git-svn-id: http://www.observium.org/svn/observer/trunk@118 61d68cd4-352d-0410-923a-c4978735b2b8

This commit is contained in:
Adam Amstrong
2007-11-23 11:37:28 +00:00
parent 9a6d196f32
commit 89b6a9bf1a
28 changed files with 1275 additions and 1379 deletions

View File

@@ -4,7 +4,7 @@
include("config.php");
include("includes/functions.php");
$alert_query = mysql_query("SELECT *, A.id as id FROM `alerts` as A, `devices` as D where A.device_id = D.id AND alerted = '0'");
$alert_query = mysql_query("SELECT *, A.id as id FROM `alerts` as A, `devices` as D where A.device_id = D.device_id AND alerted = '0'");
while ($alert = mysql_fetch_array($alert_query)) {
$id = $alert['id'];
$host = $alert['hostname'];

View File

@@ -8,23 +8,32 @@ $query = mysql_query($sql);
while ($service = mysql_fetch_array($query)) {
unset($check, $service_status, $time, $status);
$service_status = $service['service_status'];
$service_type = strtolower($service[service_type]);
$service_param = $service['service_param'];
$checker_script = "includes/services/" . $service_type . "/check.inc";
if(is_file($checker_script)) {
include($checker_script);
} else {
$status = "2";
$check = "Error : Script not found ($checker_script)";
}
if($service_status != $status) { $updated = ", `service_changed` = '" . time() . "' "; } else { unset($updated); }
mysql_query("UPDATE `services` SET `service_status` = '$status', `service_message` = '$check', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '$service[service_id]'");
if($service_status != $status) {
$updated = ", `service_changed` = '" . time() . "' ";
if($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; }
if($status == "1") {
$msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname'];
$msg .= " at " . date('l dS F Y h:i:s A');
mail($email, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']);
} elseif ($status == "0") {
$msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname'];
$msg .= " at " . date('l dS F Y h:i:s A');
mail($email, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']);
}
} else { unset($updated); }
$update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'";
mysql_query($update_sql);
echo("$update_sql " . mysql_affected_rows() . " rows updated\n");
}
?>

View File

@@ -3,8 +3,8 @@
./discover-ifs.php
./discover-nets.php
./ips.php
./discover-storage.php &
./cleanup.php
./discover-storage.php &
./discover-temperatures.php &
./generate-map.sh &
./discover-cisco-temp.php &

10
cron.sh
View File

@@ -1,11 +1,11 @@
#!/bin/bash
./poll-reachability.php
./poll-device.php &
./poll-interface.php &
./ips.php &
#./poll-reachability.php
./poll-device.php --odd >> /var/log/observer.log &
./poll-device.php --even >> /var/log/observer.log &
#./ips.php &
./check-services.php
./alerts.php
#./alerts.php
wget -O /var/sites/network.vostron.net/rrd/dill.vostron.net-mail_virus.rrd http://dill.vostron.net/rrd/mailgraph_virus.rrd
wget -O /var/sites/network.vostron.net/rrd/dill.vostron.net-mail.rrd http://dill.vostron.net/rrd/mailgraph.rrd

View File

@@ -23,12 +23,16 @@ while ($device = mysql_fetch_row($device_query)) {
$if = trim(strtolower($ifName));
$nullintf = 0;
foreach($bif as $bi) {
# echo("'$bi' -> '$if'\n");
if (strstr($if, $bi)) {
echo("'$bi' -> '$if' MATCH!\n");
$nullintf = 1;
}
}
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; }
if (preg_match('/ng[0-9]+$/', $if)) { }
if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = '1'; }
if ($nullintf == 0) {
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '$id' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
echo "Adding port $ifName \n";

View File

@@ -3,7 +3,7 @@
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' AND status = '1'");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' ORDER BY `device_id` DESC");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
@@ -19,18 +19,26 @@ while ($device = mysql_fetch_array($device_query)) {
list($descr, $units, $size, $type) = explode("\n", $temp);
list($units) = explode(" ", $units);
if(strstr($type, "FixedDisk") && $size > '0') {
echo("$oid,$descr,$units,$size\n");
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"),0) == '0') {
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')";
echo("$query \n");
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) ";
$query .= "values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')";
mysql_query($query);
echo("Adding $descr\n");
} else {
$data = mysql_fetch_array(mysql_query("SELECT * FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"));
if($data['hrStorageDescr'] != $descr || $data['hrStorageSize'] != $size || $data['hrStorageAllocationUnits'] != $units ) {
$query = "UPDATE storage SET `hrStorageDescr` = '$descr', `hrStorageSize` = '$size', `hrStorageAllocationUnits` = '$units' ";
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'";
echo("Updating $descr\n");
mysql_query($query);
}
}
$storage_exists[] = "$id $hrStorageIndex";
}
}
}
$sql = "SELECT * FROM storage";
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.status = '1'";
$query = mysql_query($sql);
while ($store = mysql_fetch_array($query)) {
@@ -40,14 +48,13 @@ while ($store = mysql_fetch_array($query)) {
$i = 0;
while ($i < count($storage_exists) && !$exists) {
$thisstore = $store['host_id'] . " " . $store['hrStorageIndex'];
if ($storage_exists[$i] == $thisstore) { $exists = 1; echo("Match!"); }
if ($storage_exists[$i] == $thisstore) { $exists = 1; }
$i++;
echo("$storage_exists[$i] == $thisstore \n");
}
if(!$exists) {
echo("Deleting...\n");
# mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
echo("Deleting " . $store['hrStorageDescr'] . " from " . $store['hostname'] . "\n");
mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
}

View File

@@ -6,13 +6,17 @@ include("includes/functions.php");
### Discovery Observer-style NetSNMP temperatures
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os != 'IOS' AND os != 'ProCurve'");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' ORDER BY device_id desc");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
$snmpver = $device['snmpver'];
echo("\n***$hostname***\n");
echo("\nPolling $hostname\n");
## Begin Observer-Style
if($device['os'] == "Linux") {
echo("Detecting Observer-Style sensors");
$oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep ".1.1 " | grep -v ".101." | cut -d"." -f 1`;
$oids = trim($oids);
if(strstr($oids, "no")) { unset ($oids); }
@@ -24,21 +28,21 @@ while ($device = mysql_fetch_array($device_query)) {
echo("Detected : $fulloid ($descr)\n");
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) {
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`) VALUES ('$id', '$fulloid', '$descr');");
echo("Created $fulloid on $hostname\n");
} else { $temp_exists[] = "$id $fulloid"; }
echo("Created $descr ($fulloid) on $hostname\n");
} else {
if (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
echo("Updating $descr on $hostname\n");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
}
}
$temp_exists[] = "$id $fulloid";
}
}
} ## End Observer-Style
// Discover Dell temperatures
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND hardware like 'Dell %'");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
$snmpver = $device['snmpver'];
echo("\n***$hostname***\n");
## Dell Temperatures
if(strstr($device['hardware'], "Dell")) {
echo("Detecting Dell OMSA sensors\n");
$oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8`;
$oids = trim($oids);
if(strstr($oids, "no")) { unset ($oids); }
@@ -53,19 +57,23 @@ while ($device = mysql_fetch_array($device_query)) {
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) {
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_tenths`) VALUES ('$id', '$fulloid', '$descr', '1');");
echo("Created $fulloid on $hostname\n");
} else {
if (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
echo("Updating $descr on $hostname\n");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
}
}
$temp_exists[] = "$id $fulloid";
}
}
}
}## End Dell Sensors
$device_query = mysql_query("SELECT * FROM `devices` WHERE `os` = 'IOS' AND `status` = '1'");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
echo("Detecting IOS temperature sensors for $hostname\n");
## Cisco Temperatures
if($device['os'] == "IOS") {
echo("Detecting Cisco IOS temperature sensors\n");
$oids = `snmpwalk -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g`;
echo($oids);
$oids = trim($oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
@@ -84,33 +92,31 @@ while ($device = mysql_fetch_array($device_query)) {
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`) values ('$id', '$temp_oid', '$descr')";
echo("$query -> $descr : $temp\n");
mysql_query($query);
$temp_exists[] = "$id $fulloid";
}
$temp_exists[] = "$id $temp_oid";
}
}
}
}
## Delete removed sensors
$sql = "SELECT * FROM temperature";
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.status = '1'";
$query = mysql_query($sql);
while ($sensor = mysql_fetch_array($query)) {
unset($exists);
$i = 0;
while ($i < count($temp_exists) && !$exists) {
$thistemp = $sensor['temp_host'] . " " . $sensor['temp_oid'];
if ($temp_exists[$i] == $thistemp) { $exists = 1; }
$i++;
}
if(!$exists) {
echo("Deleting...\n");
mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'");
}
}

View File

@@ -39,8 +39,17 @@ while ($device = mysql_fetch_array($device_query)) {
echo("VLAN $vlan ($vlan_descr)\n");
}
$this_vlans[] = $vlan;
}
$device_vlans = mysql_query("SELECT * FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "' AND `vlan_domain` = '" . $vtp_domain . "'");
while($dev_vlan = mysql_fetch_array($device_vlans)) {
unset($vlan_exists);
foreach($this_vlans as $test_vlan) {
if($test_vlan == $dev_vlan['vlan_vlan']) { $vlan_exists = 1; }
}
if(!$vlan_exists) { mysql_query("DELETE FROM `vlans` WHERE `vlan_id` = '" . $dev_vlan['vlan_id'] . "'"); echo("Deleted VLAN ". $dev_vlan['vlan_vlan'] ."\n"); }
}
}
}

View File

@@ -1,3 +1,4 @@
#!/bin/bash
./map.php > map.dot && unflatten -l4 -f map.dot | dot -Tpng -o html/network-big.png && convert -resize 400x300 html/network-big.png html/network.png
./map.php > map.dot && unflatten -l5 -f map.dot | fdp -Tpng -o html/network-big.png && convert -resize 400x500 html/network-big.png html/network.png
#./map.php > map.dot && unflatten -l5 -f map.dot | circo -Tpng -o html/network-big.png && convert -resize 400x500 html/network-big.png html/network.png

View File

@@ -17,6 +17,6 @@ if($argv[1] && $argv[2] && $argv[3]) {
} else { echo("Already got host $host\n"); }
} else { echo("Could not ping $host\n"); }
} else { echo("Could not resolve $host\n"); }
} else { echo("Usage: ./host-add.php <hostname> <community> <snmpversion>"); }
} else { echo("Add Host Tool\nUsage: ./host-add.php <hostname> <community> <snmpversion>\n"); }
?>

View File

@@ -1,5 +1,7 @@
<?php
ini_set('allow_url_fopen', 0);
ini_set('display_errors', 0);
if($_GET[debug]) {
ini_set('display_errors', 1);

View File

@@ -10,7 +10,7 @@ if($_POST['delsrv']) {
}
}
$query = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.id ORDER BY hostname");
$query = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id ORDER BY hostname");
while($device = mysql_fetch_array($query)) {
$servicesform .= "<option value='" . $device[service_id] . "'>" . $device['service_id'] . "." . $device['hostname'] . " - " . $device['service_type'] . "</option>";
}

View File

@@ -57,7 +57,7 @@ echo("<li class=" . $select['dev-graphs'] . ">
</li>
");
if(mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$_GET['id']."'"), 0) > '0') {
if(@mysql_result(mysql_query("SELECT * FROM `entPhysical` WHERE device_id = '".$_GET['id']."'"), 0) > '0') {
echo("
<li class=" . $select['dev-enyphysical'] . ">

View File

@@ -56,7 +56,7 @@ if ($dir == "v") {
};
//send picture to browser
$border = imagecolorallocate($per, 0x99, 0x99, 0x99);
$border = @imagecolorallocate($percent, 250, 250, 250);
imagerectangle($image, 0, 0, $length, 6, $border);
ImagePNG($image);

View File

@@ -9,9 +9,34 @@ include("snom.php");
include("graphing.php");
include("print-functions.php");
function strgen ($length = 8)
{
$entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e',
'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n',
'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w',
'W','x','X','y','Y','z','Z');
$string = "";
for ($i=0; $i<$length; $i++)
{
$key = mt_rand(0,61);
$string .= $entropy[$key];
}
return $string;
}
function interfacepermitted($interface_id) {
return devicepermitted(mysql_result(mysql_query("SELECT device_id FROM interface WHERE interface_id = '$interface_id'"),0));
}
function devicepermitted($device_id) {
global $_SESSION;
if($_SESSION['level'] > "5") { $allowed = true;
if($_SESSION['userlevel'] >= "5") { $allowed = true;
} elseif ( @mysql_result(mysql_query("SELECT * FROM devices_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `device_id` = $device_id"), 0) > '0' ) {
$allowed = true;
} else { $allowed = false; }
@@ -34,13 +59,25 @@ function formatStorage($size) {
return round($size, 2).$ext;
}
function arguments($argv) {
$_ARG = array();
foreach ($argv as $arg) {
if (ereg('--([^=]+)=(.*)',$arg,$reg)) {
$_ARG[$reg[1]] = $reg[2];
} elseif(ereg('-([a-zA-Z0-9])',$arg,$reg)) {
$_ARG[$reg[1]] = 'true';
}
}
return $_ARG;
}
function percent_colour($perc)
{
$r = min(255, 5 * ($perc - 50));
$b = max(0, 255 - (5 * $perc));
$r = min(255, 5 * ($perc - 25));
$b = max(0, 255 - (5 * ($perc + 25)));
return sprintf('#%02x%02x%02x', $r, 0, $b);
return sprintf('#%02x%02x%02x', $r, $b, $b);
}
function percent_colour_old($perc) {
@@ -72,10 +109,10 @@ function truncate($substring, $max = 50, $rep = '...') {
function interface_rates ($interface) {
global $rrdtool;
global $config;
$rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd";
$data = trim(`$rrdtool fetch -s -600s -e now $rrdfile AVERAGE | grep : | cut -d" " -f 2,3 | grep e`);
# $data = trim(`$rrdtool fetch -s -301s -e -300s $rrdfile AVERAGE | grep : | cut -d" " -f 2,3`);
$cmd = $config['rrdtool']." fetch -s -600s -e now ".$rrdfile." AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e";
$data = trim(`$cmd`);
foreach( explode("\n", $data) as $entry) {
list($in, $out) = split(" ", $entry);
$rate['in'] = $in * 8;
@@ -86,9 +123,10 @@ function interface_rates ($interface) {
function interface_errors ($interface) {
global $rrdtool;
global $config;
$rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd";
$data = trim(`$rrdtool fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d" " -f 4,5`);
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d\" \" -f 4,5";
$data = trim(`$cmd`);
foreach( explode("\n", $data) as $entry) {
list($in, $out) = explode(" ", $entry);
$in_errors += ($in * 300);
@@ -111,24 +149,27 @@ function geteventicon ($message) {
}
function generateiflink($interface, $text=0,$type=bits) {
global $twoday;
global $now;
global $twoday; global $now; global $config; global $day;
if(!$text) { $text = fixIfName($interface['ifDescr']); }
if(!$type) { $type = 'bits'; }
$class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
$graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$twoday&to=$now&width=400&height=120&type=" . $type;
$graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$day&to=$now&width=400&height=120&type=" . $type;
$link = "<a class=$class href='?page=interface&id=" . $interface['interface_id'] . "' ";
$link .= "onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
$link .= "onmouseover=\"return overlib('<div class=list-large>" . $interface['hostname'] . " - " . $interface['ifDescr'] . "</div><div>";
$link .= $interface['ifAlias'] . "</div><img src=\'$graph_url\'>'".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">$text</a>";
return $link;
}
function generatedevicelink($device, $text=0) {
global $twoday;
global $now;
function generatedevicelink($device, $text=0, $start=0, $end=0) {
global $twoday; global $day; global $now; global $config;
if(!$start) { $start = $day; }
if(!$end) { $end = $now; }
$class = devclass($device);
if(!$text) { $text = $device['hostname']; }
$graph_url = "graph.php?host=" . $device[device_id] . "&from=$twoday&to=$now&width=400&height=120&type=cpu";
$link = "<a class=$class href='?page=device&id=" . $device['device_id'] . "' onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
$graph_url = "graph.php?host=" . $device[device_id] . "&from=$start&to=$end&width=400&height=120&type=cpu";
$link = "<a class=$class href='?page=device&id=" . $device['device_id'] . "' ";
$link .= "onmouseover=\"return overlib('<div class=list-large>".$device['hostname']." - CPU Load</div>";
$link .= "<img src=\'$graph_url\'>'".$config['overlib_defaults'].", LEFT);\" onmouseout=\"return nd();\">$text</a>";
return $link;
}
@@ -376,6 +417,8 @@ function fixiftype ($type) {
$type = str_replace("propVirtual", "Ethernet VLAN", $type);
$type = str_replace("ethernetCsmacd", "Ethernet", $type);
$type = str_replace("l2vlan", "Ethernet VLAN", $type);
$type = str_replace("frameRelay", "Frame Relay", $type);
$type = str_replace("propPointToPointSerial", "PointToPoint Serial", $type);
return ($type);
}
@@ -406,7 +449,6 @@ function fixIOSFeatures($features){
$features = str_replace("ADVSECURITYK9", "Advanced Security Crypto", $features);
$features = str_replace("K91P", "Provider Crypto", $features);
$features = str_replace("K4P", "Provider Crypto", $features);
$features = str_replace("ADVIPSERVICESK9_WAN", "Adv IP Services Crypto + WAN", $features);
$features = str_replace("ADVIPSERVICESK9", "Adv IP Services Crypto", $features);
$features = str_replace("ADVIPSERVICES", "Adv IP Services", $features);
$features = str_replace("IK9P", "IP Plus Crypto", $features);
@@ -418,17 +460,20 @@ function fixIOSFeatures($features){
$features = str_replace("IPBASE", "IP Base", $features);
$features = str_replace("IPSERVICE", "IP Services", $features);
$features = preg_replace("/^P$/", "Service Provider", $features);
$features = str_replace("JK9S", "Enterprise Plus Crypto", $features);
$features = str_replace("IK9S", "IP Plus Crypto", $features);
$features = str_replace("I6Q4L2", "Layer 2", $features);
$features = str_replace("I6K2L2Q4", "Layer 2 Crypto", $features);
$features = str_replace("C3H2S", "Layer 2 SI/EI", $features);
$features = str_replace("_WAN", " + WAN", $features);
return $features;
}
function fixIOSHardware($hardware){
$hardware = preg_replace("/C([0-9]+)/", "Cisco \\1", $hardware);
$hardware = str_replace("cat4000","Catalyst 4000", $hardware);
$hardware = preg_replace("/CISCO([0-9]+)/", "Cisco \\1", $hardware);
$hardware = str_replace("cat4000","Cisco Catalyst 4000", $hardware);
$hardware = str_replace("s3223_rp","Cisco Catalyst 6500 SUP32", $hardware);
$hardware = str_replace("s222_rp","Cisco Catalyst 6500 SUP2", $hardware);
$hardware = str_replace("c6sup2_rp","Cisco Catalyst 6500 SUP2", $hardware);
@@ -437,6 +482,7 @@ function fixIOSHardware($hardware){
$hardware = str_replace("C3200XL", "Cisco Catalyst 3200XL", $hardware);
$hardware = str_replace("C3550", "Cisco Catalyst 3550", $hardware);
$hardware = str_replace("C2950", "Cisco Catalyst 2950", $hardware);
$hardware = str_replace("C7301", "Cisco 7301", $hardware);
return $hardware;
}

View File

@@ -4,6 +4,8 @@ function pollDevice() {
global $device;
global $community;
global $config;
$rrdtool = $config['rrdtool'];
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
@@ -13,36 +15,46 @@ function pollDevice() {
$os = $device['location'];
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$tempgraph = "public_html/graphs/" . $hostname . "-temp.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`);
$tempgraph = "public_html/graphs/" . $device['hostname'] . "-temp.png";
$cpurrd = "rrd/" . $device['hostname'] . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $device['hostname'] . "-cpu.png";
$memrrd = "rrd/" . $device['hostname'] . "-mem.rrd";
$memgraph = "public_html/graphs/" . $device['hostname'] . "-mem.png";
$cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname']." 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0";
list ($cpu5m, $cpu5s) = explode("\n", `$cmd`);
$cpu5m = $cpu5m + 0;
$cpu5s = $cpu5s + 0;
list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`);
$cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname']." .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2";
list ($tempin1, $tempout1) = explode("\n", `$cmd`);
$tempin1 = $tempin1 +0;
$tempout1 = $tempout1 + 0;
list ($memfreeio, $memfreeproc, $memusedio, $memusedproc) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1`);
echo("$hostname\n");
$cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname'];
$cmd .= " .1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1";
list ($memfreeio, $memfreeproc, $memusedio, $memusedproc) = explode("\n", `$cmd`);
echo($device['hostname'] . "\n");
$memfreeio = $memfreeio + 0;
$memfreeproc = $memfreeproc + 0;
$memusedio = $memusedio + 0;
$memusedproc = $memusedproc + 0;
$memtotal = $memfreeio + $memfreeproc + $memusedio + $memusedproc;
if (!is_file($cpurrd)) {
$rrdcreate = `rrdtool create $cpurrd --step 300 DS:LOAD5S:GAUGE:600:-1:100 DS:LOAD5M:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
$rrdcreate = `$rrdtool create $cpurrd --step 300 DS:LOAD5S:GAUGE:600:-1:100 DS:LOAD5M:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
}
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 DS:TEMPIN1:GAUGE:600:-1:100 DS:TEMPOUT1:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
$rrdcreate = `$rrdtool create $temprrd --step 300 DS:TEMPIN1:GAUGE:600:-1:100 DS:TEMPOUT1:GAUGE:600:-1:100 RRA:AVERAGE:0.5:1:1200`;
}
if (!is_file($memrrd)) {
$rrdcreate = `rrdtool create $memrrd --step 300 DS:IOFREE:GAUGE:600:0:500000000 DS:IOUSED:GAUGE:600:-1:500000000 DS:PROCFREE:GAUGE:600:0:500000000 DS:PROCUSED:GAUGE:600:-1:500000000 DS:MEMTOTAL:GAUGE:600:-1:500000000 RRA:AVERAGE:0.5:1:1200`;
$rrdcreate = `$rrdtool create $memrrd --step 300 DS:IOFREE:GAUGE:600:0:500000000 DS:IOUSED:GAUGE:600:-1:500000000 DS:PROCFREE:GAUGE:600:0:500000000 DS:PROCUSED:GAUGE:600:-1:500000000 DS:MEMTOTAL:GAUGE:600:-1:500000000 RRA:AVERAGE:0.5:1:1200`;
}
`rrdtool update $temprrd N:$tempin1:$tempout1`;
`rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`rrdtool update $memrrd N:$$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
`$rrdtool update $temprrd N:$tempin1:$tempout1`;
`$rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`$rrdtool update $memrrd N:$$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,10 @@ function pollDeviceIOS() {
global $device;
global $community;
global $config;
$rrdtool = &$config['rrdtool'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
@@ -13,12 +16,11 @@ function pollDeviceIOS() {
$os = $device['location'];
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$tempgraph = "public_html/graphs/" . $hostname . "-temp.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`);
$cpu5m = $cpu5m + 0;
$cpu5s = $cpu5s + 0;
list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`);
@@ -38,7 +40,7 @@ function pollDeviceIOS() {
$memusedproc = $memusedproc + 0;
$memtotal = $memfreeio + $memfreeproc + $memusedio + $memusedproc;
if (!is_file($cpurrd)) {
$rrdcreate = `rrdtool create $cpurrd --step 300 \
$rrdcreate = `$rrdtool create $cpurrd --step 300 \
DS:LOAD5S:GAUGE:600:-1:100 \
DS:LOAD5M:GAUGE:600:-1:100 \
RRA:AVERAGE:0.5:1:2000 \
@@ -51,7 +53,7 @@ function pollDeviceIOS() {
RRA:MAX:0.5:288:2000`;
}
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 \
$rrdcreate = `$rrdtool create $temprrd --step 300 \
DS:TEMPIN1:GAUGE:600:-25:100 \
DS:TEMPOUT1:GAUGE:600:-25:100 \
RRA:AVERAGE:0.5:1:2000 \
@@ -64,7 +66,7 @@ function pollDeviceIOS() {
RRA:MAX:0.5:288:2000`;
}
if (!is_file($memrrd)) {
$rrdcreate = `rrdtool create $memrrd --step 300 \
$rrdcreate = `$rrdtool create $memrrd --step 300 \
DS:IOFREE:GAUGE:600:0:U \
DS:IOUSED:GAUGE:600:-1:U \
DS:PROCFREE:GAUGE:600:0:U \
@@ -80,9 +82,9 @@ function pollDeviceIOS() {
RRA:MAX:0.5:288:2000`;
}
`rrdtool update $temprrd N:$tempin1:$tempout1`;
`rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`rrdtool update $memrrd N:$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
`$rrdtool update $temprrd N:$tempin1:$tempout1`;
`$rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
`$rrdtool update $memrrd N:$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal`;
}
?>

View File

@@ -1,19 +1,12 @@
<?php
$id = $device['device_id'];
$hostname = $device['hostname'];
$loadrrd = "rrd/" . $hostname . "-load.rrd";
$loadgraph = "public_html/graphs/" . $hostname . "-load.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
$sysrrd = "rrd/" . $hostname . "-sys.rrd";
$sysgraph = "public_html/graphs/" . $hostname . "-sys.png";
$loadrrd = "rrd/" . $device['hostname'] . "-load.rrd";
$cpurrd = "rrd/" . $device['hostname'] . "-cpu.rrd";
$memrrd = "rrd/" . $device['hostname'] . "-mem.rrd";
$sysrrd = "rrd/" . $device['hostname'] . "-sys.rrd";
## Check Disks
$dq = mysql_query("SELECT * FROM storage WHERE host_id = '$id'");
$dq = mysql_query("SELECT * FROM storage WHERE host_id = '" . $device['device_id'] . "'");
while ($dr = mysql_fetch_array($dq)) {
$hrStorageIndex = $dr['hrStorageIndex'];
$hrStorageAllocationUnits = $dr['hrStorageAllocationUnits'];
@@ -25,7 +18,7 @@ while ($dr = mysql_fetch_array($dq)) {
$perc = round($used / $hrStorageSize * 100, 2);
$filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr));
$storerrd = "rrd/" . $hostname . "-storage-" . $filedesc . ".rrd";
$storerrd = "rrd/" . $device['hostname'] . "-storage-" . $filedesc . ".rrd";
if (!is_file($storerrd)) {
`rrdtool create $storerrd \
--step 300 \
@@ -44,6 +37,20 @@ while ($dr = mysql_fetch_array($dq)) {
rrd_update($storerrd, "N:$hrStorageSize:$used:$perc");
mysql_query("UPDATE `storage` SET `hrStorageUsed` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'");
if($dr['storage_perc'] < '40' && $perc >= '40') {
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
$msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'] . " is " . $perc;
$msg .= " at " . date('l dS F Y h:i:s A');
mail($email, "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $dr['hrStorageDescr'] . "/n");
}
}
## Set OIDs
@@ -148,26 +155,16 @@ if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSe
rrd_update($loadrrd, "N:$load1:$load5:$load10");
rrd_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
if($device['apache']) {
$apacherrd = "rrd/" . $hostname . "-apache.rrd";
if(!is_file($apacherrd)) {
$woo= `rrdtool create $apacherrd \
DS:bits:COUNTER:600:U:10000000 \
DS:hits:COUNTER:600:U:10000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797`;
if($device['courier']) {
include("includes/polling/courierstats.inc.php");
}
list($ahits,$abits) = explode("\n", `./get-apache.sh $hostname`);
$abits = $abits * 8;
if($device['postfix']) {
include("includes/polling/mailstats.inc.php");
}
rrd_update($apacherrd,"N:$abits:$ahits");
} // end apache
if($device['apache']) {
include("includes/polling/apachestats.inc.php");
}
} // end Non-m0n0wall

View File

@@ -4,10 +4,11 @@ $query = "SELECT * FROM temperature WHERE temp_host = '" . $device['device_id']
$temp_data = mysql_query($query);
while($temperature = mysql_fetch_array($temp_data)) {
$temp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $temperature['temp_oid'];
echo($temp_cmd);
$temp_cmd = "snmpget -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $temperature['temp_oid'];
$temp = `$temp_cmd`;
echo("Checking temp " . $temperature['temp_descr'] . "... ");
$temprrd = addslashes("rrd/" . $device['hostname'] . "-temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
$temprrd = str_replace(")", "_", $temprrd);
$temprrd = str_replace("(", "_", $temprrd);
@@ -23,18 +24,28 @@ while($temperature = mysql_fetch_array($temp_data)) {
RRA:AVERAGE:0.5:12:2400`;
}
$temp = str_replace("\"", "", $temp);
$temp = trim(str_replace("\"", "", $temp));
if($temperature['temp_tenths']) { $temp = $temp / 10; }
echo("$temprrd N:$temp");
echo($temp . "C\n");
$updatecmd = "rrdtool update $temprrd N:$temp";
echo($updatecmd . "\n");
`$updatecmd`;
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {
$updated = ", `service_changed` = '" . time() . "' ";
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
$msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'] . " is " . $temp . " (Limit " . $temperature['temp_limit'];
$msg .= ") at " . date('l dS F Y h:i:s A');
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "/n");
}
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '$temperature[temp_id]'");
}
?>

View File

@@ -2,7 +2,7 @@
function cpugraphHP ($rrd, $graph , $from, $to, $width, $height)
{
global $rrdtool, $installdir, $mono_font;
global $config,$rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
@@ -21,7 +21,7 @@ function cpugraphHP ($rrd, $graph , $from, $to, $width, $height)
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$opts = array_merge($config['rrdgraph_defaults'], $$optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
@@ -36,29 +36,34 @@ function cpugraphHP ($rrd, $graph , $from, $to, $width, $height)
function memgraphHP ($rrd, $graph , $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool, $installdir, $mono_font;
global $config,$rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$memrrd = $database;
$opts = "--start $from \
--alt-autoscale-max \
--width $width --height $height \
-l 0 -E \
-b 1024 \
DEF:TOTAL=$memrrd:TOTAL:AVERAGE \
DEF:FREE=$memrrd:FREE:AVERAGE \
DEF:USED=$memrrd:USED:AVERAGE \
AREA:USED#ee9900:Used \
AREA:FREE#FAFDCE:Free:STACK \
LINE1.5:TOTAL#cc0000:";
$opts = array("--start", "$from", "--alt-autoscale-max", "--width", "$width", "--height", "$height",
"-l", "0", "-E", "-b", "1024",
"DEF:TOTAL=$memrrd:TOTAL:AVERAGE",
"DEF:FREE=$memrrd:FREE:AVERAGE",
"DEF:USED=$memrrd:USED:AVERAGE",
"AREA:USED#ee9900:Used",
"AREA:FREE#FAFDCE:Free:STACK",
"LINE1.5:TOTAL#cc0000:");
if($width <= "300") {$opts .= "\
--font LEGEND:7:$mono_font \
--font AXIS:6:$mono_font \
--font-render-mode normal";}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($config['rrdgraph_defaults'], $$opts, $optsb);
`$rrdtool graph $imgfile $opts`;
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}

View File

@@ -1,7 +1,7 @@
<?php
function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
@@ -18,7 +18,7 @@ function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $ver
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$opts = array_merge($config['rrdgraph_defaults'], $optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));

View File

@@ -3,631 +3,422 @@
// Start Graphing Functions
function mailerrorgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$range = $to - $from;
$points_per_sample = 3;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$rrd_virus = "rrd/" . $rrd . "-mail_virus.rrd";
$rrd = "rrd/" . $rrd . "-mail.rrd";
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start", $from, "--end", $to,
"DEF:rejected=$rrd:rejected:AVERAGE",
"DEF:mrejected=$rrd:rejected:MAX",
"CDEF:rrejected=rejected,60,*",
"CDEF:drejected=rejected,UN,0,rejected,IF,$step,*",
"CDEF:srejected=PREV,UN,drejected,PREV,IF,drejected,+",
"CDEF:rmrejected=mrejected,60,*",
"DEF:bounced=$rrd:bounced:AVERAGE",
"DEF:mbounced=$rrd:bounced:MAX",
"CDEF:rbounced=bounced,60,*",
"CDEF:dbounced=bounced,UN,0,bounced,IF,$step,*",
"CDEF:sbounced=PREV,UN,dbounced,PREV,IF,dbounced,+",
"CDEF:rmbounced=mbounced,60,*",
"DEF:virus=$rrd_virus:virus:AVERAGE",
"DEF:mvirus=$rrd_virus:virus:MAX",
"CDEF:rvirus=virus,60,*",
"CDEF:dvirus=virus,UN,0,virus,IF,$step,*",
"CDEF:svirus=PREV,UN,dvirus,PREV,IF,dvirus,+",
"CDEF:rmvirus=mvirus,60,*",
"DEF:spam=$rrd_virus:spam:AVERAGE",
"DEF:mspam=$rrd_virus:spam:MAX",
"CDEF:rspam=spam,60,*",
"CDEF:dspam=spam,UN,0,spam,IF,$step,*",
"CDEF:sspam=PREV,UN,dspam,PREV,IF,dspam,+",
"CDEF:rmspam=mspam,60,*",
"LINE2:rrejected#cc0000:reject",
'GPRINT:srejected:MAX:tot\: %6.0lf msgs',
'GPRINT:rrejected:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmrejected:MAX:max\: %3.0lf/min\l',
"AREA:rbounced#0000cc:bounce",
'GPRINT:sbounced:MAX:tot\: %6.0lf msgs',
'GPRINT:rbounced:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmbounced:MAX:max\: %3.0lf/min\l',
"STACK:rvirus#000000:virus ",
'GPRINT:svirus:MAX:tot\: %6.0lf msgs',
'GPRINT:rvirus:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmvirus:MAX:max\: %3.0lf/min\l',
"STACK:rspam#00cc00:spam ",
'GPRINT:sspam:MAX:tot\: %6.0lf msgs',
'GPRINT:rspam:AVERAGE:avg\: %5.2lf/min',
'GPRINT:rmspam:MAX:max\: %3.0lf/min\l');
$database = "rrd/" . $rrd . "-mailstats.rrd";
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$options .= " DEF:rejected=$database:reject:AVERAGE";
$options .= " DEF:mrejected=$database:reject:MAX";
$options .= " CDEF:rrejected=rejected,60,*";
$options .= " CDEF:drejected=rejected,UN,0,rejected,IF,$step,*";
$options .= " CDEF:srejected=PREV,UN,drejected,PREV,IF,drejected,+";
$options .= " CDEF:rmrejected=mrejected,60,*";
$options .= " DEF:bounced=$database:bounced:AVERAGE";
$options .= " DEF:mbounced=$database:bounced:MAX";
$options .= " CDEF:rbounced=bounced,60,*";
$options .= " CDEF:dbounced=bounced,UN,0,bounced,IF,$step,*";
$options .= " CDEF:sbounced=PREV,UN,dbounced,PREV,IF,dbounced,+";
$options .= " CDEF:rmbounced=mbounced,60,*";
$options .= " DEF:virus=$database:virus:AVERAGE";
$options .= " DEF:mvirus=$database:virus:MAX";
$options .= " CDEF:rvirus=virus,60,*";
$options .= " CDEF:dvirus=virus,UN,0,virus,IF,$step,*";
$options .= " CDEF:svirus=PREV,UN,dvirus,PREV,IF,dvirus,+";
$options .= " CDEF:rmvirus=mvirus,60,*";
$options .= " DEF:spam=$database:spam:AVERAGE";
$options .= " DEF:mspam=$database:spam:MAX";
$options .= " CDEF:rspam=spam,60,*";
$options .= " CDEF:dspam=spam,UN,0,spam,IF,$step,*";
$options .= " CDEF:sspam=PREV,UN,dspam,PREV,IF,dspam,+";
$options .= " CDEF:rmspam=mspam,60,*";
$options .= " COMMENT:Errors\ \ \ \ \ \ \ Total\ \ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " LINE1.25:rrejected#cc0000:reject";
$options .= " GPRINT:srejected:MAX:\ %6.0lf";
$options .= " GPRINT:rrejected:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmrejected:MAX:\ %5.2lf/min\\\\l";
$options .= " AREA:rbounced#0000cc:bounce";
$options .= " GPRINT:sbounced:MAX:\ %6.0lf";
$options .= " GPRINT:rbounced:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmbounced:MAX:\ %5.2lf/min\\\\l";
$options .= " STACK:rvirus#000000:virus\ ";
$options .= " GPRINT:svirus:MAX:\ %6.0lf";
$options .= " GPRINT:rvirus:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmvirus:MAX:\ %5.2lf/min\\\\l";
$options .= " STACK:rspam#00cc00:spam\ \ ";
$options .= " GPRINT:sspam:MAX:\ %6.0lf";
$options .= " GPRINT:rspam:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmspam:MAX:\ %5.2lf/min\\\\l";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function mailsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$points_per_sample = 3;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$range = $to - $from;
$points_per_sample = 3;
$xpoints = '540';
$step = $range*$points_per_sample/$xpoints;
$rrd = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start",
$from, "--end", $to,
"DEF:sent=$rrd:sent:AVERAGE",
"DEF:msent=$rrd:sent:MAX",
"CDEF:rsent=sent,60,*",
"CDEF:rmsent=msent,60,*",
"CDEF:dsent=sent,UN,0,sent,IF,$step,*",
"CDEF:ssent=PREV,UN,dsent,PREV,IF,dsent,+",
"DEF:recv=$rrd:recv:AVERAGE",
"DEF:mrecv=$rrd:recv:MAX",
"CDEF:rrecv=recv,60,*",
"CDEF:rmrecv=mrecv,60,*",
"CDEF:drecv=recv,UN,0,recv,IF,$step,*",
"CDEF:srecv=PREV,UN,drecv,PREV,IF,drecv,+",
"AREA:rsent#00c000:sent",
"LINE1:rsent#005000:",
"GPRINT:ssent:MAX:Tot\: %5.0lf msgs",
"GPRINT:rsent:AVERAGE:Avg\: %4.2lf/min",
"GPRINT:rmsent:MAX:Max\: %3.0lf/min\l",
"LINE1.5:rrecv#cc0000:rcvd",
"GPRINT:srecv:MAX:Tot\: %5.0lf msgs",
"GPRINT:rrecv:AVERAGE:Avg\: %4.2lf/min",
"GPRINT:rmrecv:MAX:Max\: %3.0lf/min\l");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$options .= " DEF:sent=$rrd:sent:AVERAGE";
$options .= " DEF:msent=$rrd:sent:MAX";
$options .= " CDEF:rsent=sent,60,*";
$options .= " CDEF:rmsent=msent,60,*";
$options .= " CDEF:dsent=sent,UN,0,sent,IF,$step,*";
$options .= " CDEF:ssent=PREV,UN,dsent,PREV,IF,dsent,+";
$options .= " DEF:recv=$rrd:rcvd:AVERAGE";
$options .= " DEF:mrecv=$rrd:rcvd:MAX";
$options .= " CDEF:rrecv=recv,60,*";
$options .= " CDEF:rmrecv=mrecv,60,*";
$options .= " CDEF:drecv=recv,UN,0,recv,IF,$step,*";
$options .= " CDEF:srecv=PREV,UN,drecv,PREV,IF,drecv,+";
$options .= " COMMENT:Mails\ \ \ \ \ \ Total\ \ \ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:rsent#00c000:sent";
$options .= " LINE1.25:rsent#005000:";
$options .= " GPRINT:ssent:MAX:\ \ %6.0lf";
$options .= " GPRINT:rsent:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmsent:MAX:\ %5.2lf/min\\\\l";
$options .= " LINE1.25:rrecv#cc0000:rcvd";
$options .= " GPRINT:srecv:MAX:\ \ %6.0lf";
$options .= " GPRINT:rrecv:AVERAGE:\ \ %5.2lf/min";
$options .= " GPRINT:rmrecv:MAX:\ %5.2lf/min\\\\l";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function memgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool, $installdir, $mono_font;
function memgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array (
"--start", $from, "--end", $to,
"-b 1024",
"-E",
"-v", $vertical,
"--title", $title,
"-l 0",
"--width", $width, "--height", $height,
"DEF:atotalswap=$database:totalswap:AVERAGE",
"DEF:aavailswap=$database:availswap:AVERAGE",
"DEF:atotalreal=$database:totalreal:AVERAGE",
"DEF:aavailreal=$database:availreal:AVERAGE",
"DEF:atotalfree=$database:totalfree:AVERAGE",
"DEF:ashared=$database:shared:AVERAGE",
"DEF:abuffered=$database:buffered:AVERAGE",
"DEF:acached=$database:cached:AVERAGE",
"CDEF:totalswap=atotalswap,1024,*",
"CDEF:availswap=aavailswap,1024,*",
"CDEF:totalreal=atotalreal,1024,*",
"CDEF:availreal=aavailreal,1024,*",
"CDEF:totalfree=atotalfree,1024,*",
"CDEF:shared=ashared,1024,*",
"CDEF:buffered=abuffered,1024,*",
"CDEF:cached=acached,1024,*",
"CDEF:usedreal=totalreal,availreal,-",
"CDEF:usedswap=totalswap,availswap,-",
"CDEF:cusedswap=usedswap,-1,*",
"CDEF:cdeftot=availreal,shared,buffered,usedreal,cached,usedswap,+,+,+,+,+",
"COMMENT:Bytes Current Average Maximum\\n",
"LINE1:usedreal#d0b080:",
"AREA:usedreal#f0e0a0:used",
"GPRINT:usedreal:LAST: %7.2lf %s",
"GPRINT:usedreal:AVERAGE:%7.2lf %s",
"GPRINT:usedreal:MAX:%7.2lf %s\\n",
"STACK:availreal#e5e5e5:free",
"GPRINT:availreal:LAST: %7.2lf %s",
"GPRINT:availreal:AVERAGE:%7.2lf %s",
"GPRINT:availreal:MAX:%7.2lf %s\\n",
"LINE1:usedreal#d0b080:",
"AREA:shared#afeced::",
"AREA:buffered#cc0000::STACK",
"AREA:cached#ffaa66::STACK",
"LINE1.25:shared#008fea:shared",
"GPRINT:shared:LAST: %7.2lf %s",
"GPRINT:shared:AVERAGE:%7.2lf %s",
"GPRINT:shared:MAX:%7.2lf %s\\n",
"LINE1.25:buffered#ff1a00:buffers:STACK",
"GPRINT:buffered:LAST:%7.2lf %s",
"GPRINT:buffered:AVERAGE:%7.2lf %s",
"GPRINT:buffered:MAX:%7.2lf %s\\n",
"LINE1.25:cached#ea8f00:cached:STACK",
"GPRINT:cached:LAST: %7.2lf %s",
"GPRINT:cached:AVERAGE:%7.2lf %s",
"GPRINT:cached:MAX:%7.2lf %s\\n",
"LINE1:totalreal#050505:",
"AREA:cusedswap#C3D9FF:swap",
"LINE1.25:cusedswap#356AA0:",
"GPRINT:usedswap:LAST: %7.2lf %s",
"GPRINT:usedswap:AVERAGE:%7.2lf %s",
"GPRINT:usedswap:MAX:%7.2lf %s\\n",
"LINE1:totalreal#050505:total",
"GPRINT:totalreal:AVERAGE: %7.2lf %s");
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -b 1024";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:atotalswap=$database:totalswap:AVERAGE";
$options .= " DEF:aavailswap=$database:availswap:AVERAGE";
$options .= " DEF:atotalreal=$database:totalreal:AVERAGE";
$options .= " DEF:aavailreal=$database:availreal:AVERAGE";
$options .= " DEF:atotalfree=$database:totalfree:AVERAGE";
$options .= " DEF:ashared=$database:shared:AVERAGE";
$options .= " DEF:abuffered=$database:buffered:AVERAGE";
$options .= " DEF:acached=$database:cached:AVERAGE";
$options .= " CDEF:totalswap=atotalswap,1024,*";
$options .= " CDEF:availswap=aavailswap,1024,*";
$options .= " CDEF:totalreal=atotalreal,1024,*";
$options .= " CDEF:availreal=aavailreal,1024,*";
$options .= " CDEF:totalfree=atotalfree,1024,*";
$options .= " CDEF:shared=ashared,1024,*";
$options .= " CDEF:buffered=abuffered,1024,*";
$options .= " CDEF:cached=acached,1024,*";
$options .= " CDEF:usedreal=totalreal,availreal,-";
$options .= " CDEF:usedswap=totalswap,availswap,-";
$options .= " CDEF:cusedswap=usedswap,-1,*";
$options .= " CDEF:cdeftot=availreal,shared,buffered,usedreal,cached,usedswap,+,+,+,+,+";
$options .= " COMMENT:Bytes\ \ \ \ \ \ \ Current\ \ \ \ Average\ \ \ \ \ Maximum\\n";
$options .= " LINE1:usedreal#d0b080:";
$options .= " AREA:usedreal#f0e0a0:used";
$options .= " GPRINT:usedreal:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:usedreal:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:usedreal:MAX:%7.2lf%sB\\\\n";
$options .= " STACK:availreal#e5e5e5:free";
$options .= " GPRINT:availreal:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:availreal:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:availreal:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:usedreal#d0b080:";
$options .= " AREA:shared#afeced::";
$options .= " AREA:buffered#cc0000::STACK";
$options .= " AREA:cached#ffaa66::STACK";
$options .= " LINE1.25:shared#008fea:shared";
$options .= " GPRINT:shared:LAST:\ %7.2lf%sB";
$options .= " GPRINT:shared:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:shared:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1.25:buffered#ff1a00:buffers:STACK";
$options .= " GPRINT:buffered:LAST:%7.2lf%sB";
$options .= " GPRINT:buffered:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:buffered:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1.25:cached#ea8f00:cached:STACK";
$options .= " GPRINT:cached:LAST:\ %7.2lf%sB";
$options .= " GPRINT:cached:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:cached:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:totalreal#050505:";
$options .= " AREA:cusedswap#C3D9FF:swap";
$options .= " LINE1.25:cusedswap#356AA0:";
$options .= " GPRINT:usedswap:LAST:\ \ \ %7.2lf%sB";
$options .= " GPRINT:usedswap:AVERAGE:%7.2lf%sB";
$options .= " GPRINT:usedswap:MAX:%7.2lf%sB\\\\n";
$options .= " LINE1:totalreal#050505:total";
$options .= " GPRINT:totalreal:AVERAGE:\ \ %7.2lf%sB";
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function loadgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:1min=$database:1min:AVERAGE",
"DEF:5min=$database:5min:AVERAGE",
"DEF:15min=$database:15min:AVERAGE",
"CDEF:a=1min,100,/",
"CDEF:b=5min,100,/",
"CDEF:c=15min,100,/",
"CDEF:cdefd=a,b,c,+,+",
"COMMENT:Load Average Current Average Maximum\\n",
"AREA:a#ffeeaa:1 Min:",
"LINE1:a#c5aa00:",
"GPRINT:a:LAST: %7.2lf",
"GPRINT:a:AVERAGE: %7.2lf",
"GPRINT:a:MAX: %7.2lf\\n",
"LINE1.25:b#ea8f00:5 Min:",
"GPRINT:b:LAST: %7.2lf",
"GPRINT:b:AVERAGE: %7.2lf",
"GPRINT:b:MAX: %7.2lf\\n",
"LINE1.25:c#cc0000:15 Min",
"GPRINT:c:LAST: %7.2lf",
"GPRINT:c:AVERAGE: %7.2lf",
"GPRINT:c:MAX: %7.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:1min=$database:1min:AVERAGE";
$options .= " DEF:5min=$database:5min:AVERAGE";
$options .= " DEF:15min=$database:15min:AVERAGE";
$options .= " CDEF:a=1min,100,/";
$options .= " CDEF:b=5min,100,/";
$options .= " CDEF:c=15min,100,/";
$options .= " CDEF:cdefd=a,b,c,+,+";
$options .= " COMMENT:Load\ Average\ \ Current\ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " AREA:a#ffeeaa:1\ Min:";
$options .= " LINE1:a#c5aa00:";
$options .= " GPRINT:a:LAST:\ \ \ \ %7.2lf";
$options .= " GPRINT:a:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:a:MAX:\ \ %7.2lf\\\\n";
$options .= " LINE1.25:b#ea8f00:5\ Min:";
$options .= " GPRINT:b:LAST:\ \ \ \ %7.2lf";
$options .= " GPRINT:b:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:b:MAX:\ \ %7.2lf\\\\n";
$options .= " LINE1.25:c#cc0000:15\ Min";
$options .= " GPRINT:c:LAST:\ \ \ %7.2lf";
$options .= " GPRINT:c:AVERAGE:\ \ %7.2lf";
$options .= " GPRINT:c:MAX:\ \ %7.2lf\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function usersgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:users=$database:users:AVERAGE",
"COMMENT:Users Cur Ave Min Max\\n",
"AREA:users#CDEB8B:",
"LINE1.25:users#008C00: ",
"GPRINT:users:LAST: %6.2lf",
"GPRINT:users:AVERAGE:%6.2lf",
"GPRINT:users:MIN:%6.2lf",
"GPRINT:users:MAX:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:users=$database:users:AVERAGE";
$options .= " COMMENT:Users\ \ \ \ \ \ \ Cur\ \ \ \ \ Ave\ \ \ \ \ \ Min\ \ \ \ \ Max\\\\n";
$options .= " AREA:users#CDEB8B:";
$options .= " LINE1.25:users#008C00:\ ";
$options .= " GPRINT:users:LAST:\ \ \ \ %6.2lf";
$options .= " GPRINT:users:AVERAGE:%6.2lf";
$options .= " GPRINT:users:MIN:%6.2lf";
$options .= " GPRINT:users:MAX:%6.2lf\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function procsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start", $from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:procs=$database:procs:AVERAGE",
"DEF:maxprocs=$database:procs:MAX",
"COMMENT:Processes Cur Ave Min Max\\n",
"AREA:procs#C3D9FF:",
"LINE1.25:procs#356AA0: ",
"GPRINT:procs:LAST: %6.2lf",
"GPRINT:procs:AVERAGE:%6.2lf",
"GPRINT:procs:MIN:%6.2lf",
"GPRINT:procs:MAX:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:procs=$database:procs:AVERAGE";
$options .= " COMMENT:Processes\ \ \ \ Cur\ \ \ \ \ Ave\ \ \ \ \ \ Min\ \ \ \ \ Max\\\\n";
$options .= " AREA:procs#CDEB8B:";
$options .= " LINE1.25:procs#008C00:\ ";
$options .= " GPRINT:procs:LAST:\ \ \ \ %6.2lf";
$options .= " GPRINT:procs:AVERAGE:%6.2lf";
$options .= " GPRINT:procs:MIN:%6.2lf";
$options .= " GPRINT:procs:MAX:%6.2lf\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function cpugraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"--title", $title,
"--start",
$from, "--end", $to,
"-E",
"-v", $vertical,
"--rigid",
"--alt-autoscale-max",
"-l 0",
"--width", $width, "--height", $height,
"DEF:user=$database:user:AVERAGE",
"DEF:nice=$database:nice:AVERAGE",
"DEF:system=$database:system:AVERAGE",
"DEF:idle=$database:idle:AVERAGE",
"CDEF:total=user,nice,system,idle,+,+,+",
"CDEF:user_perc=user,total,/,100,*",
"CDEF:nice_perc=nice,total,/,100,*",
"CDEF:system_perc=system,total,/,100,*",
"CDEF:idle_perc=idle,total,/,100,*",
"AREA:user_perc#c02020:user",
"GPRINT:user_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:user_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:user_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:nice_perc#008f00:nice:STACK",
"GPRINT:nice_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:nice_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:nice_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:system_perc#ea8f00:system:STACK",
"GPRINT:system_perc:LAST:Cur\:%3.0lf%%",
"GPRINT:system_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:system_perc:MAX: Max\:%3.0lf%%\\n",
"AREA:idle_perc#f5f5e5:idle:STACK",
"GPRINT:idle_perc:LAST: Cur\:%3.0lf%%",
"GPRINT:idle_perc:AVERAGE: Avg\:%3.0lf%%",
"GPRINT:idle_perc:MAX: Max\:%3.0lf%%\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
# $err = rrd_error();
return FALSE;
} else {
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:user=$database:user:AVERAGE";
$options .= " DEF:nice=$database:nice:AVERAGE";
$options .= " DEF:system=$database:system:AVERAGE";
$options .= " DEF:idle=$database:idle:AVERAGE";
$options .= " CDEF:total=user,nice,system,idle,+,+,+";
$options .= " CDEF:user_perc=user,total,/,100,*";
$options .= " CDEF:nice_perc=nice,total,/,100,*";
$options .= " CDEF:system_perc=system,total,/,100,*";
$options .= " CDEF:idle_perc=idle,total,/,100,*";
$options .= " COMMENT:Usage\ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " AREA:user_perc#c02020:user";
$options .= " GPRINT:user_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:user_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:user_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:nice_perc#008f00:nice:STACK";
$options .= " GPRINT:nice_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:nice_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:nice_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:system_perc#ea8f00:system:STACK";
$options .= " GPRINT:system_perc:LAST:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:idle_perc#f5f5e5:idle:STACK";
$options .= " GPRINT:idle_perc:LAST:\ \ \ \ \ %5.2lf%%";
$options .= " GPRINT:idle_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:idle_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function couriergraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$period = $to - $from;
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$points_per_sample = 3;
$range = $to - $from;
$rrd = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array(
"-E",
"--lower-limit", "0",
"--units-exponent", "0",
"--title", $title,
"--vertical-label", $vertical,
"-l 0",
"--width", $width, "--height", $height,
"--start", $from, "--end", $to,
"DEF:pop3d_login=$rrd:pop3d_login:AVERAGE",
"DEF:mpop3d_login=$rrd:pop3d_login:MAX",
"DEF:imapd_login=$rrd:imapd_login:AVERAGE",
"DEF:mimapd_login=$rrd:imapd_login:MAX",
"CDEF:rpop3d_login=pop3d_login,60,*",
"CDEF:vpop3d_login=pop3d_login,UN,0,pop3d_login,IF,$range,*",
"CDEF:rmpop3d_login=mpop3d_login,60,*",
"CDEF:rimapd_login=imapd_login,60,*",
"CDEF:vimapd_login=imapd_login,UN,0,imapd_login,IF,$range,*",
"CDEF:rmimapd_login=mimapd_login,60,*",
"DEF:pop3d_ssl_login=$rrd:pop3d_ssl_login:AVERAGE",
"DEF:mpop3d_ssl_login=$rrd:pop3d_ssl_login:MAX",
"DEF:imapd_ssl_login=$rrd:imapd_ssl_login:AVERAGE",
"DEF:mimapd_ssl_login=$rrd:imapd_ssl_login:MAX",
"CDEF:rpop3d_ssl_login=pop3d_ssl_login,60,*",
"CDEF:vpop3d_ssl_login=pop3d_ssl_login,UN,0,pop3d_ssl_login,IF,$range,*",
"CDEF:rmpop3d_ssl_login=mpop3d_ssl_login,60,*",
"CDEF:rimapd_ssl_login=imapd_ssl_login,60,*",
"CDEF:rmimapd_ssl_login=mimapd_ssl_login,60,*",
"CDEF:vimapd_ssl_login=imapd_ssl_login,UN,0,imapd_ssl_login,IF,$range,*",
'LINE1.5:rpop3d_login#BB0000:pop3',
'GPRINT:vpop3d_login:AVERAGE: tot\: %5.0lf',
'GPRINT:rpop3d_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmpop3d_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rimapd_login#009900:imap',
'GPRINT:vimapd_login:AVERAGE: tot\: %5.0lf',
'GPRINT:rimapd_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmimapd_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rpop3d_ssl_login#000000:pop3-ssl',
'GPRINT:vpop3d_ssl_login:AVERAGE:tot\: %5.0lf',
'GPRINT:rpop3d_ssl_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmpop3d_ssl_login:MAX:max\: %4.0lf/min\l',
'LINE1.5:rimapd_ssl_login#000099:imap-ssl',
'GPRINT:vimapd_ssl_login:AVERAGE:tot\: %5.0lf',
'GPRINT:rimapd_ssl_login:AVERAGE:avg\: %4.0lf/min',
'GPRINT:rmimapd_ssl_login:MAX:max\: %4.0lf/min\l');
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$options .= " DEF:pop3d_login=$database:pop3:AVERAGE";
$options .= " DEF:mpop3d_login=$database:pop3:MAX";
$options .= " DEF:imapd_login=$database:imap:AVERAGE";
$options .= " DEF:mimapd_login=$database:imap:MAX";
$options .= " CDEF:rpop3d_login=pop3d_login,60,*";
$options .= " CDEF:vpop3d_login=pop3d_login,UN,0,pop3d_login,IF,$range,*";
$options .= " CDEF:rmpop3d_login=mpop3d_login,60,*";
$options .= " CDEF:rimapd_login=imapd_login,60,*";
$options .= " CDEF:vimapd_login=imapd_login,UN,0,imapd_login,IF,$range,*";
$options .= " CDEF:rmimapd_login=mimapd_login,60,*";
$options .= " DEF:pop3d_ssl_login=$database:pop3ssl:AVERAGE";
$options .= " DEF:mpop3d_ssl_login=$database:pop3ssl:MAX";
$options .= " DEF:imapd_ssl_login=$database:imapssl:AVERAGE";
$options .= " DEF:mimapd_ssl_login=$database:imapssl:MAX";
$options .= " CDEF:rpop3d_ssl_login=pop3d_ssl_login,60,*";
$options .= " CDEF:vpop3d_ssl_login=pop3d_ssl_login,UN,0,pop3d_ssl_login,IF,$range,*";
$options .= " CDEF:rmpop3d_ssl_login=mpop3d_ssl_login,60,*";
$options .= " CDEF:rimapd_ssl_login=imapd_ssl_login,60,*";
$options .= " CDEF:rmimapd_ssl_login=mimapd_ssl_login,60,*";
$options .= " CDEF:vimapd_ssl_login=imapd_ssl_login,UN,0,imapd_ssl_login,IF,$range,*";
$options .= " COMMENT:Logins\ \ \ \ \ \ \ \ \ Total\ \ \ \ Average\ \ \ \ Maximum\\\\n";
$options .= " LINE1.25:rpop3d_login#BB0000:pop3";
$options .= " GPRINT:vpop3d_login:AVERAGE:\ \ \ \ \ %6.0lf";
$options .= " GPRINT:rpop3d_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmpop3d_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rimapd_login#009900:imap";
$options .= " GPRINT:vimapd_login:AVERAGE:\ \ \ \ \ %6.0lf";
$options .= " GPRINT:rimapd_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmimapd_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rpop3d_ssl_login#000000:pop3-ssl";
$options .= " GPRINT:vpop3d_ssl_login:AVERAGE:\ %6.0lf";
$options .= " GPRINT:rpop3d_ssl_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmpop3d_ssl_login:MAX:%5.2lf/min\\\\l";
$options .= " LINE1.25:rimapd_ssl_login#000099:imap-ssl";
$options .= " GPRINT:vimapd_ssl_login:AVERAGE:\ %6.0lf";
$options .= " GPRINT:rimapd_ssl_login:AVERAGE:%5.2lf/min";
$options .= " GPRINT:rmimapd_ssl_login:MAX:%5.2lf/min\\\\l";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function apachehitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:hits=$database:hits:AVERAGE",
"COMMENT: Current Average Maximum\\n",
"AREA:hits#ff9933:",
"LINE1.25:hits#FF6600:Hits",
"GPRINT:hits:LAST: %6.2lf/sec",
"GPRINT:hits:AVERAGE:%6.2lf/sec",
"GPRINT:hits:MAX:%6.2lf/sec\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:hits=$database:hits:AVERAGE";
$options .= " COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:hits#ff9933:";
$options .= " LINE1.25:hits#FF6600:Hits";
$options .= " GPRINT:hits:LAST:\ %6.2lf/sec";
$options .= " GPRINT:hits:AVERAGE:%6.2lf/sec";
$options .= " GPRINT:hits:MAX:%6.2lf/sec\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function unixfsgraph ($id, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -b 1024 -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$hostname = gethostbyid($device);
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where storage_id = '$id'");
$optsa[] = "COMMENT: Size Used %age\l";
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
while($fs = mysql_fetch_array($sql)) {
$hostname = gethostbyid($fs['host_id']);
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = str_pad($fs[hrStorageDescr], 16);
$descr = substr($descr,0,16);
$descr = str_pad($fs[hrStorageDescr], 14);
$descr = substr($descr,0,14);
$text = str_replace("/", "_", $fs['hrStorageDescr']);
$optsa[] = "DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$optsa[] = "LINE1.25:$fs[storage_id]p#" . $colour . ":$descr";
$optsa[] = "GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]p:LAST:%3.0lf%%\l";
$options .= " DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$options .= " DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$options .= " DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$options .= " LINE1.25:$fs[storage_id]p#" . $colour . ":'$descr'";
$options .= " GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]p:LAST:%5.2lf%%\\\\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function unixfsgraph_dev ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max",
"-l 0",
"-E",
"-b 1024",
"--title", $title);
$hostname = gethostbyid($device);
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -b 1024 -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$hostname = gethostbyid($device);
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where host_id = '$device'");
$optsa[] = "COMMENT: Size Used %age\l";
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
while($fs = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = str_pad($fs[hrStorageDescr], 16);
$descr = substr($descr,0,16);
$descr = str_pad($fs[hrStorageDescr], 14);
$descr = substr($descr,0,14);
$text = str_replace("/", "_", $fs['hrStorageDescr']);
$optsa[] = "DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$optsa[] = "DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$optsa[] = "LINE1.25:$fs[storage_id]p#" . $colour . ":$descr";
$optsa[] = "GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$optsa[] = "GPRINT:$fs[storage_id]p:LAST:%3.0lf%%\l";
$options .= " DEF:$fs[storage_id]=rrd/$hostname-storage-$text.rrd:used:AVERAGE";
$options .= " DEF:$fs[storage_id]s=rrd/$hostname-storage-$text.rrd:size:AVERAGE";
$options .= " DEF:$fs[storage_id]p=rrd/$hostname-storage-$text.rrd:perc:AVERAGE";
$options .= " LINE1.25:$fs[storage_id]p#" . $colour . ":'$descr'";
$options .= " GPRINT:$fs[storage_id]s:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]:LAST:%6.2lf%SB";
$options .= " GPRINT:$fs[storage_id]p:LAST:%5.2lf%%\\\\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
#echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}
function apachebitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) {
global $rrdtool, $installdir, $mono_font;
global $config, $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical,"--alt-autoscale-max",
"-l 0",
"-E",
"--title", $title,
"DEF:bits=$database:bits:AVERAGE",
"COMMENT: Current Average Maximum\\n",
"AREA:bits#cccc00:",
"LINE1.25:bits#999900:Bits",
"GPRINT:bits:LAST:%6.2lf%sbps",
"GPRINT:bits:AVERAGE:%6.2lf%sbps",
"GPRINT:bits:MAX:%6.2lf%sbps\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height -l 0";
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
$options .= " DEF:bits=$database:bits:AVERAGE";
$options .= " COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ Maximum\\\\n";
$options .= " AREA:bits#cccc00:";
$options .= " LINE1.25:bits#9900:Bits";
$options .= " GPRINT:bits:LAST:\ %6.2lf/sec";
$options .= " GPRINT:bits:AVERAGE:%6.2lf/sec";
$options .= " GPRINT:bits:MAX:%6.2lf/sec\\\\n";
$thing = `$rrdtool graph $imgfile $options`;
return $imgfile;
}
}

122
map.php
View File

@@ -4,23 +4,42 @@
include("config.php");
include("includes/functions.php");
echo("digraph G { sep=0.5; size=\"50,50\"; pack=15; bgcolor=transparent;
node [ fontname=\"times roman\" fontsize=18 fontstyle=bold ]; edge [ labelfontsize=12 labelfontname=\"times roman\" ];
graph [bgcolor=transparent]; ");
echo("digraph G { sep=0.5; size=\"40,30\"; pack=15; bgcolor=transparent;splines=true;
node [ fontname=\"times roman\", fontsize=24, fontstyle=bold, shape=box, style=bold];
edge [ labelfontsize=14, labelfontname=\"times roman\", overlap=false];
graph [bgcolor=transparent, remincross=true];
");
$linkdone = array();
$x = 1;
$dev_sql = "SELECT * FROM links AS L, interfaces AS I, interfaces AS X, devices as D
WHERE I.host = D.id AND L.src_if = I.id GROUP BY D.hostname ORDER BY hostname DESC";
$loc_sql = "SELECT * FROM links AS L, interfaces AS I, interfaces AS X, devices as D WHERE I.device_id = D.device_id AND L.src_if = I.interface_id AND D.hostname LIKE '%vostron.net' AND D.hostname NOT LIKE 'cust.vostron.net' GROUP BY D.location ORDER BY D.device_id ASC";
$loc_result = mysql_query($loc_sql);
while($loc_data = mysql_fetch_array($loc_result)) {
echo("subgraph \"". $loc_data['location'] ."\" {\n
label = \"". $loc_data['location'] ."\";
style=filled;
color=lightgrey;\n\n");
if($loc_data['location'] == "TFM3, Telehouse North, London") {
echo(" \"Internet\" [shape=tripleoctagon style=filled fillcolor=crimson]\n");
echo(" \"ADSL\" [shape=tripleoctagon style=filled fillcolor=orange]\n");
}
$dev_sql = "SELECT * FROM links AS L, interfaces AS I, interfaces AS X, devices as D WHERE D.location = '" . $loc_data['location'] . "' AND I.device_id = D.device_id AND L.src_if = I.interface_id AND D.hostname LIKE '%vostron.net' AND D.hostname NOT LIKE '%cust.vostron.net' GROUP BY D.hostname";
$dev_result = mysql_query($dev_sql);
while($dev_data = mysql_fetch_array($dev_result)) {
$host = $dev_data['hostname'];
unset($hostinfo);
if(strpos($host, "cust." . $mydomain)) { $hostinfo = "shape=egg style=filled fillcolor=pink"; }
elseif(strpos($host, $mydomain)) {
if(strpos($host, "-sw")) { $hostinfo = "shape=rectangle style=filled fillcolor=skyblue"; }
if(strpos($host, "-gw")) { $hostinfo = "shape=rectangle style=filled fillcolor=yellow"; }
} else { $hostinfo = "style=filled shape=rectangle fillcolor=lightgray"; }
if(strpos($host, "-sw")||strpos($host, "-cs")) { $hostinfo = "shape=rectangle style=filled fillcolor=skyblue"; }
if(strpos($host, "-gw")||strpos($host, "-pe")||strpos($host, "-er")) { $hostinfo = "shape=ellipse style=filled fillcolor=darkolivegreen3"; }
if(strpos($host, "-lns")) { $hostinfo = "shape=egg style=filled fillcolor=darkolivegreen4"; }
} else { $hostinfo = "style=filled shape=circle fillcolor=lightgray"; }
$host = $dev_data[hostname];
$host = str_replace("." . $mydomain,"", $host);
@@ -29,17 +48,15 @@ while($dev_data = mysql_fetch_array($dev_result)) {
}
$linkdone = array();
$links_sql = "SELECT *, X.if AS sif, I.if AS dif FROM links AS L, interfaces AS I, interfaces AS X, devices as D where I.host = D.id AND L.src_if = I.id AND X.id = L.dst_if ORDER BY D.hostname";
$links_sql = "SELECT *, X.ifDescr AS sif, I.ifDescr AS dif FROM links AS L, interfaces AS I, interfaces AS X, devices as D, devices as Y WHERE D.hostname LIKE '%vostron.net' AND I.device_id = D.device_id AND X.device_id = Y.device_id AND D.hostname NOT LIKE '%cust%' AND Y.hostname NOT LIKE '%cust%' AND L.src_if = I.interface_id AND X.interface_id = L.dst_if AND D.location = '" . $loc_data['location'] . "' AND D.location = Y.location ORDER BY D.location DESC";
$links_result = mysql_query($links_sql);
while($link_data = mysql_fetch_array($links_result)) {
$src_if = $link_data['src_if'];
$dst_if = $link_data['dst_if'];
$sq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.host = D.id and I.id = '$src_if'"));
$dq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.host = D.id and I.id = '$dst_if'"));
$sq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$src_if'"));
$dq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$dst_if'"));
$src = $sq[0];
$dst = $dq[0];
@@ -52,15 +69,15 @@ while($link_data = mysql_fetch_array($links_result)) {
$info = "";
# if($src_speed == "10 Gbps") {
# $info .= "color=red weight=5";
# } elseif ($src_speed == "1.0 Gbps") {
# $info .= "color=blue weight=10";
# } elseif ($src_speed == "100 Gbps") {
# $info .= "color=green weight=1";
# } elseif ($src_speed == "10 mbps") {
# $info .= "";
# }
if($src_speed >= "10000000000") {
$info .= "color=darkred weight=10 style=\"setlinewidth(16)\"";
} elseif ($src_speed >= "1000000000") {
$info .= "color=navyblue weight=5 style=\"setlinewidth(8)\"";
} elseif ($src_speed >= "100000000") {
$info .= "color=darkgreen weight=1 style=\"setlinewidth(4)\"";
} elseif ($src_speed >= "10000000") {
$info .= "style=\"setlinewidth(2)\" weight=1";
}
unset($die);
@@ -74,10 +91,67 @@ while($link_data = mysql_fetch_array($links_result)) {
$sif = makeshortif($link_data[sif]);
$dif = makeshortif($link_data[dif]);
# $sif = $link_data[sif];
# $dif = $link_data[dif];
if(!$die){
# echo("\"$src\" -> \"$dst\" [taillabel=\"$dif\" headlabel=\"$sif\" arrowhead=none arrowtail=none $info];\n");
echo("\"$src\" -> \"$dst\" [ arrowhead=none arrowtail=none $info];\n");
$linkdone[] = "$src $link_data[sif] $dst $link_data[dif]";
$x++;
}
}
echo("\n}\n");
}
echo("\"Internet\" -> \"thlon-pe01\" [ arrowhead=none arrowtail=none color=navyblue weight=5 style=\"setlinewidth(8)\"];\n");
echo("\"Internet\" -> \"thlon-lns01\" [ arrowhead=none arrowtail=none color=navyblue weight=5 style=\"setlinewidth(8)\"];\n");
echo("\"ADSL\" -> \"thlon-lns01\" [ arrowhead=none arrowtail=none color=navyblue weight=5 style=\"setlinewidth(8)\"];\n");
$links_sql = "SELECT *, X.ifDescr AS sif, I.ifDescr AS dif FROM links AS L, interfaces AS I, interfaces AS X, devices as D, devices as Y WHERE D.hostname LIKE '%vostron.net' AND I.device_id = D.device_id AND X.device_id = Y.device_id AND D.hostname NOT LIKE '%cust%' AND L.src_if = I.interface_id AND X.interface_id = L.dst_if AND D.location != Y.location AND D.hostname NOT LIKE '%cust.vostron.net' AND Y.hostname NOT LIKE '%cust.vostron.net' ORDER BY D.location DESC";
$links_result = mysql_query($links_sql);
while($link_data = mysql_fetch_array($links_result)) {
$src_if = $link_data['src_if'];
$dst_if = $link_data['dst_if'];
$sq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$src_if'"));
$dq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$dst_if'"));
$src = $sq[0];
$dst = $dq[0];
$src_speed = $sq[1];
$dst_speed = $dq[1];
$src = str_replace("." . $mydomain, "", $src);
$dst = str_replace("." . $mydomain, "", $dst);
$info = "";
if($src_speed >= "10000000000") {
$info .= "color=darkred weight=10 style=\"setlinewidth(16)\"";
} elseif ($src_speed >= "1000000000") {
$info .= "color=navyblue weight=5 style=\"setlinewidth(8)\"";
} elseif ($src_speed >= "100000000") {
$info .= "color=darkgreen weight=1 style=\"setlinewidth(4)\"";
} elseif ($src_speed >= "10000000") {
$info .= "style=\"setlinewidth(2)\" weight=1";
}
unset($die);
$i = 0;
while ($i < count($linkdone)) {
$thislink = "$dst $link_data[dif] $src $link_data[sif]";
if ($linkdone[$i] == $thislink) { $die = "yes"; }
$i++;
}
$sif = makeshortif($link_data[sif]);
$dif = makeshortif($link_data[dif]);
if(!$die){
# echo("\"$src\" -> \"$dst\" [taillabel=\"$dif\" headlabel=\"$sif\" arrowhead=none arrowtail=none $info];\n");
echo("\"$src\" -> \"$dst\" [ arrowhead=none arrowtail=none $info];\n");

View File

@@ -4,20 +4,48 @@
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` like '%$argv[1]' AND `ignore` = '0' ORDER BY `device_id` ASC");
echo("Project Observer Poller v$observer_version\n\n");
if($argv[1] == "--device" && $argv[2]) {
$where = "AND `device_id` = '".$argv[2]."'";
} elseif ($argv[1] == "--odd") {
$where = "AND MOD(device_id,2) = 1";
} elseif ($argv[1] == "--even") {
$where = "AND MOD(device_id,2) = 0";
} elseif ($argv[1] == "--all") {
$where = "";
} else {
echo("--device <device id> Poll single device\n");
echo("--all Poll all devices\n\n");
echo("No polling type specified!\n");
exit;
}
echo("Starting polling run:\n\n");
$device_query = mysql_query("SELECT * FROM `devices` WHERE `ignore` = '0' $where ORDER BY `device_id` ASC");
while ($device = mysql_fetch_array($device_query)) {
echo("Polling " . $device['hostname'] . " ( ".$device['device_id']." )\n\n");
unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features);
unset($location); unset($hardware);
unset($sysDescr);
unset($location); unset($hardware); unset($sysDescr);
$pingable = isPingable($device['hostname']);
if($pingable) { echo("Pings : yes :)\n"); } else { echo("Pings : no :(\n"); }
$snmpable = FALSE;
if($pingable) {
$snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver']);
if($snmpable) { echo("SNMP : yes :)"); } else { echo("SNMP : no :("); }
}
echo("\n");
if ($snmpable) {
$status = '1';
if($device['os'] == "FreeBSD" || $device['os'] == "OpenBSD" || $device['os'] == "Linux" || $device['os'] == "Windows") {
@@ -26,13 +54,21 @@ while ($device = mysql_fetch_array($device_query)) {
$uptimeoid = "1.3.6.1.2.1.1.3.0";
}
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_cmd .= " $uptimeoid sysLocation.0 .1.3.6.1.2.1.47.1.1.1.1.13.1 sysDescr.0";
$snmp_cmd .= " $uptimeoid sysLocation.0 sysContact.0 sysDescr.0";
$snmp_cmd .= " | grep -v 'Cisco Internetwork Operating System Software'";
if($device['os'] == "IOS") {
$snmp_cmdb = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_cmdb .= " .1.3.6.1.2.1.47.1.1.1.1.13.1";
$snmp_cmdb .= " | grep -v 'Cisco Internetwork Operating System Software'";
$ciscomodel = str_replace("\"", "", trim(`$snmp_cmdb`));
} else { unset($ciscomodel); }
$snmpdata = `$snmp_cmd`;
$snmpdata = preg_replace("/^.*IOS/","", $snmpdata);
$snmpdata = trim($snmpdata);
$snmpdata = str_replace("\"", "", $snmpdata);
list($sysUptime, $sysLocation, $ciscomodel, $sysDescr) = explode("\n", $snmpdata);
list($sysUptime, $sysLocation, $sysContact, $sysDescr) = explode("\n", $snmpdata);
$sysUptime = str_replace("(", "", $sysUptime);
$sysUptime = str_replace(")", "", $sysUptime);
list($days, $hours, $mins, $secs) = explode(":", $sysUptime);
@@ -98,6 +134,7 @@ while ($device = mysql_fetch_array($device_query)) {
break;
case "IOS":
echo("Device is Cisco! \n$sysDescr\n");
$version = str_replace("Cisco IOS Software,", "", $sysDescr);
$version = str_replace("IOS (tm) ", "", $version);
$version = str_replace(",RELEASE SOFTWARE", "", $version);
@@ -112,12 +149,11 @@ while ($device = mysql_fetch_array($device_query)) {
list($hardware, $features, $version) = explode("|", $version);
$features = fixIOSFeatures($features);
#$hardware = fixIOSHardware($hardware);
$ciscomodel = str_replace("\"", "", $ciscomodel);
if(strstr($ciscomodel, "OID")){ unset($ciscomodel); }
if(!strstr($ciscomodel, " ") && strlen($ciscomodel) >= '3') {
$hardware = $ciscomodel;
}
echo($device['version'] . " $version");
include("includes/polling/device-ios.inc.php");
break;
@@ -126,7 +162,6 @@ while ($device = mysql_fetch_array($device_query)) {
list($hardware, $features, $version) = explode(",", $sysDescr);
list($version) = explode("(", $version);
if(!strstr($ciscomodel, " ")) {
echo("$ciscomodel");
$hardware = str_replace("\"", "", $ciscomodel);
}
include("includes/polling/device-procurve.inc.php");
@@ -139,14 +174,27 @@ while ($device = mysql_fetch_array($device_query)) {
}
$location = str_replace("\"","", $sysLocation);
echo("Polling temperatures\n");
include("includes/polling/temperatures.inc.php");
include("includes/polling/device-netstats.inc.php");
echo("Polling interfaces\n");
$where = "WHERE device_id = '" . $device['device_id'] . "'";
include("includes/polling/interfaces.inc.php");
} else {
$status = '0';
}
unset( $update ) ;
unset( $seperator) ;
if ( $sysContact && $sysContact != $device['sysContact'] ) {
$update .= $seperator . "`sysContact` = '$sysContact'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Contact -> $sysContact')");
}
echo("$update\n");
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
$update .= $seperator . "`sysDescr` = '$sysDescr'";
@@ -197,10 +245,10 @@ while ($device = mysql_fetch_array($device_query)) {
$old_uptime = mysql_result(mysql_query("SELECT `attrib_value` FROM `devices_attribs` WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'"), 0);
if( $uptime < $old_uptime ) {
mail($notify_email, "Rebooted: " . $device['hostname'], "Device " . $device['hostname'] . " rebooted at " . date('l dS F Y h:i:s A'));
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
mail($notify_email, "Device Rebooted: " . $device['hostname'], "Device Rebooted :" . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']);
}
$uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
if(!is_file($uptimerrd)) {
$woo = `rrdtool create $uptimerrd \
@@ -224,11 +272,14 @@ while ($device = mysql_fetch_array($device_query)) {
$update_query = "UPDATE `devices` SET ";
$update_query .= $update;
$update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'";
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n\n");
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n");
$update_result = mysql_query($update_query);
} else {
echo("No Changes to " . $device['hostname'] . "\n\n");
echo("No Changes to " . $device['hostname'] . "\n");
}
echo("\n");
}
?>

View File

@@ -14,7 +14,7 @@ while ($device = mysql_fetch_array($device_query)) {
$host = trim(strtolower($hostname));
$host_os = getHostOS($host, $community, $device[snmpver]);
if($old_os != $host_os) {
$sql = mysql_query("UPDATE `devices` SET `os` = '$host_os' WHERE `id` = '$id'");
$sql = mysql_query("UPDATE `devices` SET `os` = '$host_os' WHERE `device_id` = '$id'");
echo("Updated host : $host ($host_os)\n");
} else echo("Not Updated host : $host ($host_os)\n");
}

View File

@@ -38,15 +38,19 @@ while ($device = mysql_fetch_array($device_query)) {
$status='0';
}
if($status != $device['status']) {
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'");
if ($status == '1') {
$stat = "Up";
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')");
mail($email, "DeviceUp: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']);
} else {
$stat = "Down";
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')");
mail($email, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']);
}
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to $stat')");
echo("Status Changed!\n");

View File

@@ -27,17 +27,18 @@ while($l = mysql_fetch_array($q)){
$host = $maybehost;
} elseif($perhapshost) {
$host = $perhapshost;
} else { `echo Failed log entry from $l[host] > /var/log/observer.log`; }
} else { `echo Failed log entry from $l[host] >> /var/log/observer.log`; }
if($host) {
if(mysql_result(mysql_query("SELECT os FROM `devices` WHERE `device_id` = '$host'"),0) == "IOS") {
list(,$l[msg]) = split(": %", $l[msg]);
$l[msg] = "%" . $l[msg];
$l[msg] = preg_replace("/^%(.+):\ /", "\\1||", $l[msg]);
$l[msg] = preg_replace("/^%(.+?):\ /", "\\1||", $l[msg]);
list($l[program], $l[msg]) = explode("||", $l[msg]);
} else {
$l[msg] = preg_replace("/^" . $l[program] . ":\ /", "", $l[msg]);
$program = addslashes($l['program']);
$l['msg'] = preg_replace("/^$program:\ /", "", $l['msg']);
}