<commit_before>'use strict';

/**
 * Module dependencies.
 */
var fs = require('fs');
var yargs = require('yargs')
    .describe('c', 'Load a config (file)')
    .alias('c', 'config')
    .alias('c', 'config-file')
    .alias('c', 'config_file')
    .default('c', './config.json');
var argv = yargs.argv;

// Check config file
if (!fs.existsSync(argv.c)) {
  yargs.showHelp();
  console.log('Config file must exist and be readable.');
  process.exit(1);
}
try {
  var config = require(argv.c);
} catch (e) {
  console.log('Syntax error with the config file ' + argv.c);
  process.exit(1);
}

var express = require('express'),
  http = require('http'),
  path = require('path'),
  async = require('async'),
  _ = require('underscore'),
  app = express(),
  server = http.createServer(app);

var io = require('socket.io').listen(server);
io.set('log level', 1);

var Dc = require('./lib/dc.js').Dc;
var clients = {};


/**
 * Initialize configuration
 */
if (!_.isArray(config.sensu)) {
  config.sensu = [config.sensu];
  config.sensu[0].name = config.sensu[0].host;
}
var port = config.uchiwa.port || 3000;
var host = config.uchiwa.host || '0.0.0.0';
config.uchiwa.refresh = config.uchiwa.refresh || 10000;

/**
 * App configuration
 */
app.set('port', process.env.PORT || port);
app.set('host', process.env.HOST || host);
app.engine('.html', require('ejs').__express);
app.set('views', path.join(__dirname, 'public'));
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

/**
 * Authentification
 */
if (config.uchiwa.user && config.uchiwa.pass) {
  var basicAuth = express.basicAuth(function (username, password) {
    return (username === config.uchiwa.user && password === config.uchiwa.pass);
  }, 'Restrict area, please identify');
  app.all('*', basicAuth);
}

/**
 * Error handling
 * NODE_ENV=development node app.js
 */
if ('development' === process.env.NODE_ENV) {
  console.log('Debugging enabled.');
  app.use(express.errorHandler({showStack: true, dumpExceptions: true}));
  io.set('log level', 3);
}

/* jshint ignore:start */
app.use(function (err, req, res, next) {
  console.log(err);
  res.send(500);
});
/* jshint ignore:end */

// Remove passwords from public config
var publicConfig = _.clone(config);
publicConfig.uchiwa.user = '*****';
publicConfig.uchiwa.pass = '*****';
_.each(publicConfig.sensu, function (element) {
  element.user = '*****';
  element.pass = '*****';
});

var sensu = {};
var datacenters = [];
config.sensu.forEach(function (configuration) {
  datacenters.push(new Dc(configuration));
});

var pull = function () {
  var attributes = ['checks', 'clients', 'events', 'stashes'];
  attributes.forEach(function(attribute) {
    sensu[attribute] = [];
  });
  sensu.dc = [];
  
  async.eachSeries(datacenters, function (datacenter, nextDc) {
    datacenter.pull(function () {
        var aggregate = function (callback) {
          async.each(attributes, function (attribute, nextAttribute) {
            async.each(datacenter.sensu[attribute], function (item, nextItem) {
              item.dc = datacenter.name;
              sensu[attribute].push(item);
              nextItem();
            }, function () {
              nextAttribute();
            });<commit_msg>Perform a deep clone for public config display<commit_after>'use strict';

/**
 * Module dependencies.
 */
var fs = require('fs');
var yargs = require('yargs')
    .describe('c', 'Load a config (file)')
    .alias('c', 'config')
    .alias('c', 'config-file')
    .alias('c', 'config_file')
    .default('c', './config.json');
var argv = yargs.argv;

// Check config file
if (!fs.existsSync(argv.c)) {
  yargs.showHelp();
  console.log('Config file must exist and be readable.');
  process.exit(1);
}
try {
  var config = require(argv.c);
} catch (e) {
  console.log('Syntax error with the config file ' + argv.c);
  process.exit(1);
}

var express = require('express'),
  http = require('http'),
  path = require('path'),
  async = require('async'),
  _ = require('underscore'),
  app = express(),
  server = http.createServer(app);

var io = require('socket.io').listen(server);
io.set('log level', 1);

var Dc = require('./lib/dc.js').Dc;
var clients = {};


/**
 * Initialize configuration
 */
if (!_.isArray(config.sensu)) {
  config.sensu = [config.sensu];
  config.sensu[0].name = config.sensu[0].host;
}
var port = config.uchiwa.port || 3000;
var host = config.uchiwa.host || '0.0.0.0';
config.uchiwa.refresh = config.uchiwa.refresh || 10000;

/**
 * App configuration
 */
app.set('port', process.env.PORT || port);
app.set('host', process.env.HOST || host);
app.engine('.html', require('ejs').__express);
app.set('views', path.join(__dirname, 'public'));
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

/**
 * Authentification
 */
if (config.uchiwa.user && config.uchiwa.pass) {
  var basicAuth = express.basicAuth(function (username, password) {
    return (username === config.uchiwa.user && password === config.uchiwa.pass);
  }, 'Restrict area, please identify');
  app.all('*', basicAuth);
}

/**
 * Error handling
 * NODE_ENV=development node app.js
 */
if ('development' === process.env.NODE_ENV) {
  console.log('Debugging enabled.');
  app.use(express.errorHandler({showStack: true, dumpExceptions: true}));
  io.set('log level', 3);
}

/* jshint ignore:start */
app.use(function (err, req, res, next) {
  console.log(err);
  res.send(500);
});
/* jshint ignore:end */

// Remove passwords from public config
var publicConfig = JSON.parse(JSON.stringify(config));
publicConfig.uchiwa.user = '*****';
publicConfig.uchiwa.pass = '*****';
_.each(publicConfig.sensu, function (element) {
  element.user = '*****';
  element.pass = '*****';
});

var sensu = {};
var datacenters = [];
config.sensu.forEach(function (configuration) {
  datacenters.push(new Dc(configuration));
});

var pull = function () {
  var attributes = ['checks', 'clients', 'events', 'stashes'];
  attributes.forEach(function(attribute) {
    sensu[attribute] = [];
  });
  sensu.dc = [];
  
  async.eachSeries(datacenters, function (datacenter, nextDc) {
    datacenter.pull(function () {
        var aggregate = function (callback) {
          async.each(attributes, function (attribute, nextAttribute) {
            async.each(datacenter.sensu[attribute], function (item, nextItem) {
              item.dc = datacenter.name;
              sensu[attribute].push(item);
              nextItem();
            }, function () {
              nextAttribute();
            });
{'fraction_non_alphanumeric': 0.19437229437229436, 'fraction_numerical': 0.006637806637806638, 'mean_word_length': 3.870695713281799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2568732', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2267, 'n_words': 465}