-
Notifications
You must be signed in to change notification settings - Fork 0
/
jnrpe.js
executable file
·51 lines (45 loc) · 1.59 KB
/
jnrpe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
'use strict'
var JNRPE = require('yargs');
var JNRPEServer = require('jnrpe-lib').JNRPEServer;
const config = require('./config.json');
const pkg = require('./package.json');
var server = new JNRPEServer(config);
function listPlugins(yargs) {
server.pluginManager.on('loaded', () => {
console.log(server.pluginManager.getPlugins());
});
}
function startServer(yargs) {
server.start();
console.log(`JNRPE ${pkg.version} listening on port ${config.server.port}`);
}
function help(args) {
var pluginName = args.plugin;
server.pluginManager.on('loaded', () => {
var plugin = server.pluginManager.getPlugin(pluginName);
if (plugin) {
var details = plugin.details;
console.log(`\nName: ${details.name}\n`);
console.log(details.description);
console.log('======================================');
console.log(`Parameters: ${details.commandLine}`)
console.log(`\nExample command: ${details.exampleCommand}`);
console.log(`Example invocation: ${details.exampleInvocation}`);
} else {
console.log(`Unknown plugin ${pluginName}`);
}
});
}
var argv = JNRPE.usage('Usage: $0 <command> [options]')
.command('start', 'Start the JNRPE server', startServer)
.command('list', 'List all the plugins', listPlugins)
.command('help <plugin>', 'Show the help of the requested plugin', {
plugin: {
describe: 'Name of the plugin',
demand: true,
type: 'string'
}
},help)
.demandCommand()
.argv;