diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 6de6b49..a3396bf 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,3 +1,3 @@ contribdir = $(datadir)/dhcpd-pools/ dist_contrib_SCRIPTS = dhcpd-pools.cgi snmptest.pl -EXTRA_DIST = nagios.conf +EXTRA_DIST = nagios.conf munin_plugins diff --git a/contrib/munin_plugins/dhcpstats_abs.js b/contrib/munin_plugins/dhcpstats_abs.js new file mode 100755 index 0000000..aa5409c --- /dev/null +++ b/contrib/munin_plugins/dhcpstats_abs.js @@ -0,0 +1,44 @@ +#!/usr/bin/env node + +var command = "dhcpd-pools" +var timeout = 5000; // (ms) if the command take longer, then kill it + +var execFile = require('child_process').execFile; +var echo = require('util').print; + +var arg = process.argv[2]; + +if ("autoconf" === arg) { + echo("yes\n"); + return 0; +} + +execFile(command, [ "--format=j", "--sort=n" ], { timeout: timeout }, function(error, stdout, stderr) { + if (error !== null) { + console.log('exec error: ' + error); + return 1; + } + + stdout = JSON.parse(stdout); + + if ("config" === arg) { + echo("graph_title dhcp usage (number of machines)\n"); + echo("graph_vlabel nb of machines\n"); + echo("graph_scale no\n"); + echo("graph_category network\n"); + + stdout["subnets"].forEach(function(subnet) { + var location = subnet["location"]; + var range = subnet["range"]; + echo(location + '.label ' + location + ' (' + range + ')\n'); + }); + } else { + stdout["shared-networks"].forEach(function(network) { + var location = network["location"]; + var used = network["used"]; + var defined = network["defined"]; + echo(location + '.value ' + used + '\n'); + }); + } + +}); diff --git a/contrib/munin_plugins/dhcpstats_abs.php b/contrib/munin_plugins/dhcpstats_abs.php new file mode 100755 index 0000000..3f8c553 --- /dev/null +++ b/contrib/munin_plugins/dhcpstats_abs.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +1 && $argv[1]=="autoconf") { + echo "yes\n"; + return; +} elseif ($argc>1 && $argv[1]=="config") { + $xml2 = $xml->xpath("subnet"); + echo "graph_title dhcp usage (number of machines)\n"; + echo "graph_vlabel nb of machines\n"; + echo "graph_scale no\n"; + echo "graph_category network\n"; + foreach ($xml2 as $xml3) { + $location = (string) $xml3->location; + $range = (string) $xml3->range; + echo "$location.label $location ($range)\n"; + } +} else { + $xml2 = $xml->xpath("shared-network"); + foreach ($xml2 as $xml3) { + $location = (string) $xml3->location; + $used = (int) $xml3->used; + $defined = (int) $xml3->defined; + $pourcent = ceil($used*10000/$defined)/100; + echo "$location.value $used\n"; + } +} + diff --git a/contrib/munin_plugins/dhcpstats_percent.js b/contrib/munin_plugins/dhcpstats_percent.js new file mode 100755 index 0000000..6cf2dbd --- /dev/null +++ b/contrib/munin_plugins/dhcpstats_percent.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +var command = "dhcpd-pools" +var timeout = 5000; // (ms) if the command take longer, then kill it + +var execFile = require('child_process').execFile; +var echo = require('util').print; + +var arg = process.argv[2]; + +if ("autoconf" === arg) { + echo("yes\n"); + return 0; +} + +execFile(command, [ "--format=j", "--sort=n" ], { timeout: timeout }, function(error, stdout, stderr) { + if (error !== null) { + console.log('exec error: ' + error); + return 1; + } + + stdout = JSON.parse(stdout); + + if ("config" === arg) { + echo("graph_title dhcp usage (in percent)\n"); + echo("graph_args --upper-limit 100 -l 0 --rigid\n"); + echo("graph_vlabel %\n"); + echo("graph_scale no\n"); + echo("graph_category network\n"); + + stdout["subnets"].forEach(function(subnet) { + var location = subnet["location"]; + var range = subnet["range"]; + echo(location + '.label ' + location + ' (' + range + ')\n'); + echo(location + '.warning 75\n'); + echo(location + '.critical 90\n'); + }); + } else { + stdout["shared-networks"].forEach(function(network) { + var location = network["location"]; + var used = network["used"]; + var defined = network["defined"]; + // keep 1 digit after decimal point + var percent = Math.ceil(used * 100 / defined) / 10; + echo(location + '.value ' + percent + '\n'); + }); + } + +}); diff --git a/contrib/munin_plugins/dhcpstats_percent.php b/contrib/munin_plugins/dhcpstats_percent.php new file mode 100755 index 0000000..8a5ae32 --- /dev/null +++ b/contrib/munin_plugins/dhcpstats_percent.php @@ -0,0 +1,42 @@ +#!/usr/bin/env php +1 && $argv[1]=="autoconf") { + echo "yes\n"; + return; +} elseif ($argc>1 && $argv[1]=="config") { + $xml2 = $xml->xpath("subnet"); + echo "graph_title dhcp usage (in percent)\n"; + echo "graph_args --upper-limit 100 -l 0 --rigid\n"; + echo "graph_vlabel %\n"; + echo "graph_scale no\n"; + echo "graph_category network\n"; + foreach ($xml2 as $xml3) { + $location = (string) $xml3->location; + $range = (string) $xml3->range; + echo "$location.label $location ($range)\n"; + echo "$location.warning 75\n"; + echo "$location.critical 90\n"; + } +} else { + $xml2 = $xml->xpath("shared-network"); + foreach ($xml2 as $xml3) { + $location = (string) $xml3->location; + $used = (int) $xml3->used; + $defined = (int) $xml3->defined; + // keep 1 digit after decimal point + $pourcent = ceil($used*1000/$defined)/10; + echo "$location.value $pourcent\n"; + } +} + diff --git a/contrib/munin_plugins/preview.png b/contrib/munin_plugins/preview.png new file mode 100644 index 0000000..b621b69 Binary files /dev/null and b/contrib/munin_plugins/preview.png differ