mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-15 15:27:00 +00:00
contrib: add munin plugins
Signed-off-by: Gilles Bouthenot <gilles.bouthenot@univ-fcomte.fr>
This commit is contained in:
parent
bc654bcc68
commit
443b197901
6 changed files with 173 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
44
contrib/munin_plugins/dhcpstats_abs.js
Executable file
44
contrib/munin_plugins/dhcpstats_abs.js
Executable file
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
37
contrib/munin_plugins/dhcpstats_abs.php
Executable file
37
contrib/munin_plugins/dhcpstats_abs.php
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", true);
|
||||
|
||||
$ret="";
|
||||
$xml = exec("dhcpd-pools --format x --sort n", $ret);
|
||||
$xml = join($ret);
|
||||
|
||||
$xml = new SimpleXMLElement($xml);
|
||||
|
||||
|
||||
if ($argc>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";
|
||||
}
|
||||
}
|
||||
|
||||
49
contrib/munin_plugins/dhcpstats_percent.js
Executable file
49
contrib/munin_plugins/dhcpstats_percent.js
Executable file
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
42
contrib/munin_plugins/dhcpstats_percent.php
Executable file
42
contrib/munin_plugins/dhcpstats_percent.php
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", true);
|
||||
|
||||
//$xml = file_get_contents("test.xml");
|
||||
$ret="";
|
||||
$xml = exec("dhcpd-pools --format x --sort n", $ret);
|
||||
$xml = join($ret);
|
||||
|
||||
$xml = new SimpleXMLElement($xml);
|
||||
|
||||
|
||||
if ($argc>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";
|
||||
}
|
||||
}
|
||||
|
||||
BIN
contrib/munin_plugins/preview.png
Normal file
BIN
contrib/munin_plugins/preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
Loading…
Add table
Add a link
Reference in a new issue