| 1 |
#!/usr/bin/env node |
| 2 |
|
| 3 |
var command = "dhcpd-pools" |
| 4 |
var timeout = 5000; |
| 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 (number of machines)\n"); |
| 26 |
echo("graph_vlabel nb of machines\n"); |
| 27 |
echo("graph_scale no\n"); |
| 28 |
echo("graph_category network\n"); |
| 29 |
|
| 30 |
stdout["subnets"].forEach(function(subnet) { |
| 31 |
var location = subnet["location"]; |
| 32 |
var range = subnet["range"]; |
| 33 |
echo(location + '.label ' + location + ' (' + range + ')\n'); |
| 34 |
}); |
| 35 |
} else { |
| 36 |
stdout["shared-networks"].forEach(function(network) { |
| 37 |
var location = network["location"]; |
| 38 |
var used = network["used"]; |
| 39 |
var defined = network["defined"]; |
| 40 |
echo(location + '.value ' + used + '\n'); |
| 41 |
}); |
| 42 |
} |
| 43 |
|
| 44 |
}); |