<commit_before>var http = require('http');
var https = require('https');
var net = require('net');
var sys = require('sys');
var fs = require('fs');
var logger = require('util');
var _ = require('underscore')._;
var settings = require('./settings').create();
var EventEmitter = require('events').EventEmitter;
var controller = new EventEmitter();
module.exports = controller;

var plugins = [];
fs.readdir('./plugins', function(err, files){
  if(!err){
   plugins = _.map(files, function(file){
     return require('./plugins/'+file).create(controller);
   });
 }
});
  
var status = {};
status.lastupdate = new Date().toGMTString();
status.services = [];

updatingServices = function() {
  status.lastupdate = new Date().toUTCString();
  logger.log('Refreshing status board...');
  for (var i = 0; i < settings.services.length; i++) {
    status.services[i] = {};
    status.services[i].name = settings.services[i].name;
    status.services[i].label = settings.services[i].label;
    status.services[i].status = 'unknown';
    status.services[i].statusCode = 0;
    status.services[i].message = '';
    commands[settings.services[i].check].call(null, settings.services[i], status.services[i]);
  }
  setTimeout(function() {
    var statusTab = _.map(status.services, function(value, key) { return value; });
    status.summarize = {};
    status.summarize.lastupdate = status.lastupdate;
    status.summarize.up = _.reduce(_.select(status.services, function(data){ return data.status == 'up'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.critical = _.reduce(_.select(status.services, function(data){ return data.status == 'critical'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.down = _.reduce(_.select(status.services, function(data){ return data.status == 'down'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.unknown = _.reduce(_.select(status.services, function(data){ return data.status == 'unknown'; }), function(memo, num){ return memo + 1; }, 0);

    controller.emit("refresh", status);
  }, settings.serviceDelay);
};

var checkHttpStatusCode = function(response, service) {
  if (response.statusCode == 200) {
    service.status = "up";
  } else if (response.statusCode == 301 || response.statusCode == 302) {
    service.status = "unknown";
    service.message = "Redirected to " + response.headers.location;
  } else if (response.statusCode == 503 || response.statusCode == 404) {
    service.status = "down";
  } else {
    service.status = "critical";
  }
  service.statusCode = response.statusCode;
};

var checkRange = function(min, max, value) {
  if (min && max && value >= min && value < max) {
    return true;
  } else if ( (min && value >= min) || (max && value < max) ) {
    return true;
  }
  return false;
};
var checkStatusDashboardResponse = function(response, serviceDefinition, service) {
  if(response.statusCode === 200){
    response.on('data', function(chunk){
      summary = JSON.parse(chunk);
      if(summary.critical === 0 && summary.down === 0 && summary.unknown ===0){
        service.status = 'up';
      }else {
        service.status = 'down';
        service.message = "Services up: "+ summary.up + ", Services down: "+ summary.down + ", Services critical: "+summary.critical + ", Services unknown: "+summary.unknown 
      }
      controller.emit(service.status, service);
    });
  }
};

var checkHttpValueResponse = function(response, serviceDefinition, service) {
  if (response.statusCode == 200 && (serviceDefinition.checkFixedValueResponse || serviceDefinition.checkRangeValuesResponse)) {
    response.on('data', function (chunk) {
      var value = ('' + chunk).substring(0, chunk.length - 1);
      if (serviceDefinition.checkFixedValueResponse) {
        if (serviceDefinition.checkFixedValueResponse[value]) {
          service.status = serviceDefinition.checkFixedValueResponse[value];<commit_msg>Adding the semicolor for correctness<commit_after>var http = require('http');
var https = require('https');
var net = require('net');
var sys = require('sys');
var fs = require('fs');
var logger = require('util');
var _ = require('underscore')._;
var settings = require('./settings').create();
var EventEmitter = require('events').EventEmitter;
var controller = new EventEmitter();
module.exports = controller;

var plugins = [];
fs.readdir('./plugins', function(err, files){
  if(!err){
   plugins = _.map(files, function(file){
     return require('./plugins/'+file).create(controller);
   });
 }
});
  
var status = {};
status.lastupdate = new Date().toGMTString();
status.services = [];

updatingServices = function() {
  status.lastupdate = new Date().toUTCString();
  logger.log('Refreshing status board...');
  for (var i = 0; i < settings.services.length; i++) {
    status.services[i] = {};
    status.services[i].name = settings.services[i].name;
    status.services[i].label = settings.services[i].label;
    status.services[i].status = 'unknown';
    status.services[i].statusCode = 0;
    status.services[i].message = '';
    commands[settings.services[i].check].call(null, settings.services[i], status.services[i]);
  }
  setTimeout(function() {
    var statusTab = _.map(status.services, function(value, key) { return value; });
    status.summarize = {};
    status.summarize.lastupdate = status.lastupdate;
    status.summarize.up = _.reduce(_.select(status.services, function(data){ return data.status == 'up'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.critical = _.reduce(_.select(status.services, function(data){ return data.status == 'critical'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.down = _.reduce(_.select(status.services, function(data){ return data.status == 'down'; }), function(memo, num){ return memo + 1; }, 0);
    status.summarize.unknown = _.reduce(_.select(status.services, function(data){ return data.status == 'unknown'; }), function(memo, num){ return memo + 1; }, 0);

    controller.emit("refresh", status);
  }, settings.serviceDelay);
};

var checkHttpStatusCode = function(response, service) {
  if (response.statusCode == 200) {
    service.status = "up";
  } else if (response.statusCode == 301 || response.statusCode == 302) {
    service.status = "unknown";
    service.message = "Redirected to " + response.headers.location;
  } else if (response.statusCode == 503 || response.statusCode == 404) {
    service.status = "down";
  } else {
    service.status = "critical";
  }
  service.statusCode = response.statusCode;
};

var checkRange = function(min, max, value) {
  if (min && max && value >= min && value < max) {
    return true;
  } else if ( (min && value >= min) || (max && value < max) ) {
    return true;
  }
  return false;
};
var checkStatusDashboardResponse = function(response, serviceDefinition, service) {
  if(response.statusCode === 200){
    response.on('data', function(chunk){
      summary = JSON.parse(chunk);
      if(summary.critical === 0 && summary.down === 0 && summary.unknown ===0){
        service.status = 'up';
      }else {
        service.status = 'down';
        service.message = "Services up: "+ summary.up + ", Services down: "+ summary.down + ", Services critical: "+summary.critical + ", Services unknown: "+summary.unknown; 
      }
      controller.emit(service.status, service);
    });
  }
};

var checkHttpValueResponse = function(response, serviceDefinition, service) {
  if (response.statusCode == 200 && (serviceDefinition.checkFixedValueResponse || serviceDefinition.checkRangeValuesResponse)) {
    response.on('data', function (chunk) {
      var value = ('' + chunk).substring(0, chunk.length - 1);
      if (serviceDefinition.checkFixedValueResponse) {
        if (serviceDefinition.checkFixedValueResponse[value]) {
          service.status = serviceDefinition.checkFixedValueResponse[value];
{'fraction_non_alphanumeric': 0.16899087221095335, 'fraction_numerical': 0.009127789046653144, 'mean_word_length': 4.092963202065849, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5223603', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2286, 'n_words': 523}