contrib: add munin plugins

Signed-off-by: Gilles Bouthenot <gilles.bouthenot@univ-fcomte.fr>
This commit is contained in:
Gilles Bouthenot 2012-12-05 14:33:01 +01:00 committed by Sami Kerola
parent bc654bcc68
commit 443b197901
6 changed files with 173 additions and 1 deletions

View file

@ -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

View 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');
});
}
});

View 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";
}
}

View 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');
});
}
});

View 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";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB