Debian Codegraph @

contrib/munin_plugins/dhcpstats_percent.js

raw symbols SCIP
1 #!/usr/bin/env node
2
3 var command = "dhcpd-pools"
4 var timeout = 5000; // (ms) if the command take longer, then kill it
5
6 var execFile = require('child_process').execFile;
7 var echo = require('util').print;
8
9 var arg = process.argv[2];
10
11 if ("autoconf" === arg) {
12 echo("yes\n");
13 return 0;
14 }
15
16 execFile(command, [ "--format=j", "--sort=n" ], { timeout: timeout }, function(error, stdout, stderr) {
17 if (error !== null) {
18 console.log('exec error: ' + error);
19 return 1;
20 }
21
22 stdout = JSON.parse(stdout);
23
24 if ("config" === arg) {
25 echo("graph_title dhcp usage (in percent)\n");
26 echo("graph_args --upper-limit 100 -l 0 --rigid\n");
27 echo("graph_vlabel %\n");
28 echo("graph_scale no\n");
29 echo("graph_category network\n");
30
31 stdout["subnets"].forEach(function(subnet) {
32 var location = subnet["location"];
33 var range = subnet["range"];
34 echo(location + '.label ' + location + ' (' + range + ')\n');
35 echo(location + '.warning 75\n');
36 echo(location + '.critical 90\n');
37 });
38 } else {
39 stdout["shared-networks"].forEach(function(network) {
40 var location = network["location"];
41 var used = network["used"];
42 var defined = network["defined"];
43 // keep 1 digit after decimal point
44 var percent = Math.ceil(used * 100 / defined) / 10;
45 echo(location + '.value ' + percent + '\n');
46 });
47 }
48
49 });