| 1 |
#!/usr/bin/env php |
| 2 |
<?php |
| 3 |
error_reporting(E_ALL); |
| 4 |
ini_set("display_errors", true); |
| 5 |
|
| 6 |
|
| 7 |
$ret=""; |
| 8 |
$xml = exec("dhcpd-pools --format x --sort n", $ret); |
| 9 |
$xml = join($ret); |
| 10 |
|
| 11 |
$xml = new SimpleXMLElement($xml); |
| 12 |
|
| 13 |
|
| 14 |
if ($argc>1 && $argv[1]=="autoconf") { |
| 15 |
echo "yes\n"; |
| 16 |
return; |
| 17 |
} elseif ($argc>1 && $argv[1]=="config") { |
| 18 |
$xml2 = $xml->xpath("subnet"); |
| 19 |
echo "graph_title dhcp usage (in percent)\n"; |
| 20 |
echo "graph_args --upper-limit 100 -l 0 --rigid\n"; |
| 21 |
echo "graph_vlabel %\n"; |
| 22 |
echo "graph_scale no\n"; |
| 23 |
echo "graph_category network\n"; |
| 24 |
foreach ($xml2 as $xml3) { |
| 25 |
$location = (string) $xml3->location; |
| 26 |
$range = (string) $xml3->range; |
| 27 |
echo "$location.label $location ($range)\n"; |
| 28 |
echo "$location.warning 75\n"; |
| 29 |
echo "$location.critical 90\n"; |
| 30 |
} |
| 31 |
} else { |
| 32 |
$xml2 = $xml->xpath("shared-network"); |
| 33 |
foreach ($xml2 as $xml3) { |
| 34 |
$location = (string) $xml3->location; |
| 35 |
$used = (int) $xml3->used; |
| 36 |
$defined = (int) $xml3->defined; |
| 37 |
|
| 38 |
$pourcent = ceil($used*1000/$defined)/10; |
| 39 |
echo "$location.value $pourcent\n"; |
| 40 |
} |
| 41 |
} |
| 42 |
|