<commit_before>var express = require('express');
var router = express.Router();
var http=require('http')
var request = require("request");
var config = require("../config.js")
var plot = require('plotter').plot;

var environment = {
  endpoint : process.argv[2] ? process.argv[2] : ONEOPS_ENDPOINT,
  org: '',
  authkey: process.argv[3] ? process.argv[3] : AUTH_TOKEN
}

router.get('/', function(req, res, next) {
  res.send('OneOps API route');
});


router.get('/health1', function(req, res, next) {
  var org = req.param('orgname')
  console.log(org)
  var options = {
    method: 'GET',
    isArray: true,
    headers: { 'Authorization': 'Basic ' + "XXXXX:" },
    host: 'https://stg.oneops.walmart.com',
    path: '/$org/operations/health?state=total&profiles%5B%5D=DEV'
  };
  callback = function(data) {
    data.on('data', function(chunk){
      str += chunk
    })

    data.on('end', function(data){
     console.log(data)
    })
  }
  http.request(options, callback).end()
  res.send('OneOps API route');
});


router.get('/health', function(req, res, next) {
  environment.org = req.param('orgname')
  var options = config.options(environment)
  options.uri += '/operations/health.json?state=total'
  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    var hasUnhealhty = false;
    var reqPath = req.param('nspath')
    for(var key in data) {//array of heath objects
      var nspath = data[key].ns

      if(reqPath) {
        if(nspath.startsWith(reqPath) > 0) {
          var h = data[key].health
          if('unhealthy' in h) {
            hasUnhealhty = true;
            console.log(nspath + "  " + JSON.stringify(h));
          }
        }

      }  else {
        console.log(nspath + " " + JSON.stringify(data[key].health));
      }
    }
    if(!hasUnhealhty) {
      console.log('nspath ' + reqPath + ' has everything in good state')
    }
  });
  res.send('OneOps API health route');
});


router.get('/metricgraph', function(req, res, next) {
  environment.org = req.param('orgname')
  var assembly = req.param('assembly')
  var enviornment = req.param('enviornment')
  var platform = req.param('platform')
  var instance = req.param('instance')
  var monitor = req.param('monitor')
  var component = req.param('component')

  var options = config.options(environment)
  options.uri += '/assemblies/' + assembly + '/operations/environments/' + enviornment + '/platforms/' + platform
  + '/components/' + component + '/instances/' + instance + '/monitors/' + monitor + '.json'

  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    var plotdata = {}
    for(var key in data) {//array os heath objects
      if(key == 'charts') {
        var obj = data[key]
        for(var o in obj) {
          var seriesdata = obj[o].data
          for(var s in seriesdata) {
            var sdata = seriesdata[s]
            var md = sdata.header.metric
            // plotdata.put(md,sdata.data)
            plotdata[md] = sdata.data
          }
        }
      }
    }
    console.log(JSON.stringify(plotdata))
    plot({
      data:	plotdata,
      filename:	'output.svg',
      format: 'svg',
      logscale:   true,
      title: 'metric graph'
    });

  });
  res.send('OneOps API metric graph route');
});


router.post('/notifications', function(req, res, next) {
  var data=req.body
  console.log(data.payload)
  res.send('respond with a resource');
});

module.exports = router;<commit_msg>added methods for get calls<commit_after>var express = require('express');
var router = express.Router();
var http=require('http')
var request = require("request");
var config = require("../config.js")
var plot = require('plotter').plot;

var environment = {
  endpoint : process.argv[2] ? process.argv[2] : ONEOPS_ENDPOINT,
  org: '',
  authkey: process.argv[3] ? process.argv[3] : AUTH_TOKEN
}

router.get('/', function(req, res, next) {
  res.send('OneOps API route');
});


router.get('/health1', function(req, res, next) {
  var org = req.param('orgname')
  console.log(org)
  var options = {
    method: 'GET',
    isArray: true,
    headers: { 'Authorization': 'Basic ' + "XXXXX:" },
    host: 'https://stg.oneops.walmart.com',
    path: '/$org/operations/health?state=total&profiles%5B%5D=DEV'
  };
  callback = function(data) {
    data.on('data', function(chunk){
      str += chunk
    })

    data.on('end', function(data){
     console.log(data)
    })
  }
  http.request(options, callback).end()
  res.send('OneOps API route');
});


router.get('/health', function(req, res, next) {
  environment.org = req.param('orgname')
  var options = config.options(environment)
  options.uri += '/operations/health.json?state=total'
  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    var hasUnhealhty = false;
    var reqPath = req.param('nspath')
    for(var key in data) {//array of heath objects
      var nspath = data[key].ns

      if(reqPath) {
        if(nspath.startsWith(reqPath) > 0) {
          var h = data[key].health
          if('unhealthy' in h) {
            hasUnhealhty = true;
            console.log(nspath + "  " + JSON.stringify(h));
          }
        }

      }  else {
        console.log(nspath + " " + JSON.stringify(data[key].health));
      }
    }
    if(!hasUnhealhty) {
      console.log('nspath ' + reqPath + ' has everything in good state')
    }
  });
  res.send('OneOps API health route');
});


router.get('/metricgraph', function(req, res, next) {
  environment.org = req.param('orgname')
  var assembly = req.param('assembly')
  var enviornment = req.param('enviornment')
  var platform = req.param('platform')
  var instance = req.param('instance')
  var monitor = req.param('monitor')
  var component = req.param('component')

  var options = config.options(environment)
  options.uri += '/assemblies/' + assembly + '/operations/environments/' + enviornment + '/platforms/' + platform
  + '/components/' + component + '/instances/' + instance + '/monitors/' + monitor + '.json'

  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    var plotdata = {}
    for(var key in data) {//array of metric objects
      if(key == 'charts') {
        var obj = data[key]
        for(var o in obj) {
          var seriesdata = obj[o].data
          for(var s in seriesdata) {
            var sdata = seriesdata[s]
            var md = sdata.header.metric
            // plotdata.put(md,sdata.data)
            plotdata[md] = sdata.data
          }
        }
      }
    }
    console.log(JSON.stringify(plotdata))
    plot({
      data:	plotdata,
      filename:	'output.svg',
      format: 'svg',
      logscale:   true,
      title: 'metric graph'
    });

  });
  res.send('OneOps API metric graph route');
});


function getInstances(orgname, assembly, platform, enviornment, component) {
  environment.org = orgname
  var options = config.options(environment)
  options.uri += '/assemblies/' + assembly + '/operations/environments/' + enviornment + '/platforms/'
  + platform + '/components/' + component + '/instances.json?instances_state=all'

  var ids = []
  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    for(var key in data) {
      ids.push(data[key].ciId)
    }
    return ids
  });
}

function getMonitors(orgname, assembly, platform, enviornment, component, monitor) {
  environment.org = orgname
  var options = config.options(environment)
  options.uri += '/assemblies/' + assembly + '/transition/environments/' + enviornment + '/platforms/' + platform
  + '/components/' + component + '/monitors.json'

  var ids = []
  request(options, function(error, response, body) {
    var data = JSON.parse(body);
    for(var key in data) {
      var name = data[key].ciName

      if(name && name.endsWith(monitor))
        ids.push(data[key].ciId)
    }
    return ids
  });
}


router.post('/notifications', function(req, res, next) {
  var data=req.body
  console.log(data.payload)
  res.send('respond with a resource');
});

module.exports = router;
{'fraction_non_alphanumeric': 0.16030628627886873, 'fraction_numerical': 0.001976040508830431, 'mean_word_length': 2.9101883148237566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2832437', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2613, 'n_words': 579}