Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let fs = require('fs'),
path = require('path'),
async = require('async'),
mkdirp = require('mkdirp'),
colors = require('colors'),
pm2 = require('pm2'),
pm2cst = require('pm2/constants.js'),
pm2prepare = require('pm2/lib/Common.js').prepareAppConf,
// Client is pm2's RPC daemon, we have to use it to get
// some custom behavior that is not exposed by pm2's CLI.
Client = pm2.Client,
exec = require('child_process').exec,
Emitter = require('events').EventEmitter,
debug = require('debug')('api')
var conf = require('./conf'),
ERRORS = require('./errors'),
formatter = require('./formatter'),
hookTemplate = fs.readFileSync(__dirname + '/../hooks/post-receive', 'utf-8')
// Load config data
var globalConfigPath = conf.path,
webInterfaceId = conf.webId,
globalConfig = readJSON(globalConfigPath)
upgradeConf()
pm2.connect(function () {
api.emit('ready');
Client = pm2.Client;
})
'use strict';
const pm2 = require('pm2');
const pmx = require('pmx');
const packageJSON = require('./package');
const conf = pmx.initModule();
const elasticLibModule = require('./libs/elasticsearch');
const elasticLib = new elasticLibModule(conf.elasticsearch_host, conf.elasticsearch_index);
/**
* Change default host to elasticsearch : pm2 set pm2-elasticlogs:elasticsearch_host 'http://localhost:9200'
*
* Start module in development mode
* $ pm2 install .
*/
pm2.Client.launchBus(function(err, bus) {
if(err)
return console.error(err);
bus.on('log:*', function(type, packet) {
if ((conf.app_name != 'all' && conf.app_name && conf.app_name != packet.process.name) || packet.process.name === packageJSON.name) return false;
if (typeof(packet.data) == 'string')
packet.data = packet.data.replace(/(\r\n|\n|\r)/gm,'');
elasticLib.add({
message : packet.data,
application : packet.process.name,
process_id : packet.process.pm_id,
}).catch((e) => {console.error(e)});
});
});