diff --git a/alerts.php b/alerts.php index 748089c339..48224278e1 100755 --- a/alerts.php +++ b/alerts.php @@ -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']; diff --git a/check-services.php b/check-services.php index 410ccf8e0c..b2d0bf31ec 100755 --- a/check-services.php +++ b/check-services.php @@ -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"); } ?> diff --git a/cron-hourly.sh b/cron-hourly.sh index 7acf99dc2c..97e5bf6986 100755 --- a/cron-hourly.sh +++ b/cron-hourly.sh @@ -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 & diff --git a/cron.sh b/cron.sh index bf60eace90..13048c287a 100755 --- a/cron.sh +++ b/cron.sh @@ -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 diff --git a/discover-ifs.php b/discover-ifs.php index 5670411059..337568449c 100755 --- a/discover-ifs.php +++ b/discover-ifs.php @@ -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"; diff --git a/discover-storage.php b/discover-storage.php index 41c88d891f..135463ab47 100755 --- a/discover-storage.php +++ b/discover-storage.php @@ -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'] . "'"); } diff --git a/discover-temperatures.php b/discover-temperatures.php index e2ef3fe8b9..54a1132d96 100755 --- a/discover-temperatures.php +++ b/discover-temperatures.php @@ -6,111 +6,117 @@ 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"); - $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); } - foreach(explode("\n",$oids) as $oid) { - $oid = trim($oid); - if($oid != "") { - $descr = trim(str_replace("\"", "", `snmpget -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //`)); - $fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1"; - 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("\nPolling $hostname\n"); -// 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"); - $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); } - foreach(explode("\n",$oids) as $oid) { - $oid = substr(trim($oid), 36); - echo("$oid \n"); - list($oid) = explode(" ", $oid); - if($oid != "") { - $descr = trim(str_replace("\"", "", `snmpget -v2c -Onvq -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid`)); - $fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid"; - 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`, `temp_tenths`) VALUES ('$id', '$fulloid', '$descr', '1');"); - echo("Created $fulloid on $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); } + foreach(explode("\n",$oids) as $oid) { + $oid = trim($oid); + if($oid != "") { + $descr = trim(str_replace("\"", "", `snmpget -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //`)); + $fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1"; + 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 $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"; + } } - $temp_exists[] = "$id $fulloid"; - } + } ## End Observer-Style + + ## 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); } + foreach(explode("\n",$oids) as $oid) { + $oid = substr(trim($oid), 36); + echo("$oid \n"); + list($oid) = explode(" ", $oid); + if($oid != "") { + $descr = trim(str_replace("\"", "", `snmpget -v2c -Onvq -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid`)); + $fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid"; + 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`, `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 + + + ## 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); + list($oid) = explode(" ", $data); + $temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid"; + $descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid"; + $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; + $temp = `snmpget -O qv -v2c -c $community $hostname $temp_oid`; + if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" ) { + $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; + $descr = str_replace("\"", "", $descr); + $descr = str_replace("temperature", "", $descr); + $descr = str_replace("temp", "", $descr); + $descr = trim($descr); + if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '.1.3.6.1.4.1.9.9.13.1.3.1.3.$oid' AND temp_host = '$id'"),0) == '0') { + $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"; + } + } } } -$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"); - $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`; - $oids = trim($oids); - foreach(explode("\n", $oids) as $data) { - $data = trim($data); - list($oid) = explode(" ", $data); - $temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid"; - $descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid"; - $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; - $temp = `snmpget -O qv -v2c -c $community $hostname $temp_oid`; - if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" ) { - $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; - $descr = str_replace("\"", "", $descr); - $descr = str_replace("temperature", "", $descr); - $descr = str_replace("temp", "", $descr); - $descr = trim($descr); - if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '.1.3.6.1.4.1.9.9.13.1.3.1.3.$oid' AND temp_host = '$id'"),0) == '0') { - $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 $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'] . "'"); } - - } diff --git a/discover-vlans.php b/discover-vlans.php index 1691b446e4..3e045b25eb 100644 --- a/discover-vlans.php +++ b/discover-vlans.php @@ -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"); } + } } - } diff --git a/generate-map.sh b/generate-map.sh index 3bec69ec4f..3a07e6a0ba 100755 --- a/generate-map.sh +++ b/generate-map.sh @@ -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 diff --git a/host-add.php b/host-add.php index 3bcb68984f..465ad96b1d 100755 --- a/host-add.php +++ b/host-add.php @@ -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 "); } +} else { echo("Add Host Tool\nUsage: ./host-add.php \n"); } ?> diff --git a/html/index.php b/html/index.php index 428e702111..c84f7ba7da 100755 --- a/html/index.php +++ b/html/index.php @@ -1,5 +1,7 @@ " . $device['service_id'] . "." . $device['hostname'] . " - " . $device['service_type'] . ""; } diff --git a/html/pages/device.php b/html/pages/device.php index c5d986b5fe..b986c5bc03 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -57,7 +57,7 @@ echo("
  • "); -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("
  • diff --git a/html/percentage.php b/html/percentage.php index b3d7425d9a..e14b84bbd7 100644 --- a/html/percentage.php +++ b/html/percentage.php @@ -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); diff --git a/includes/functions.php b/includes/functions.php index 00c067832f..95f6b8ce32 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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 = "');\" onmouseout=\"return nd();\">$text"; + $link .= "onmouseover=\"return overlib('
    " . $interface['hostname'] . " - " . $interface['ifDescr'] . "
    "; + $link .= $interface['ifAlias'] . "
    '".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">$text"; 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 = "');\" onmouseout=\"return nd();\">$text"; + $graph_url = "graph.php?host=" . $device[device_id] . "&from=$start&to=$end&width=400&height=120&type=cpu"; + $link = "".$device['hostname']." - CPU Load"; + $link .= "'".$config['overlib_defaults'].", LEFT);\" onmouseout=\"return nd();\">$text"; 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; } diff --git a/includes/generic.php b/includes/generic.php index d03d2a226d..7bbeed3725 100755 --- a/includes/generic.php +++ b/includes/generic.php @@ -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`; } ?> diff --git a/includes/graphing.php b/includes/graphing.php index 7fe7e7ff5b..dd1f3f6ac9 100644 --- a/includes/graphing.php +++ b/includes/graphing.php @@ -1,665 +1,529 @@ "); -# print_r ($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; - } + $options .= " CDEF:inoctets=$in_thing$pluses "; + $options .= " CDEF:outoctets=$out_thing$pluses "; + $options .= " CDEF:doutoctets=outoctets,-1,* "; + $options .= " CDEF:inbits=inoctets,8,* "; + $options .= " CDEF:outbits=outoctets,8,* "; + $options .= " CDEF:doutbits=doutoctets,8,* "; + $options .= " AREA:inbits#CDEB8B: "; + $options .= " COMMENT:BPS\ \ \ \ Current\ \ \ Average\ \ \ \ \ \ Max\\\\n "; + $options .= " LINE1.25:inbits#006600:In\ "; + $options .= " GPRINT:inbits:LAST:%6.2lf%s "; + $options .= " GPRINT:inbits:AVERAGE:%6.2lf%s "; + $options .= " GPRINT:inbits:MAX:%6.2lf%s\\\l "; + $options .= " AREA:doutbits#C3D9FF: "; + $options .= " LINE1.25:doutbits#000099:Out "; + $options .= " GPRINT:outbits:LAST:%6.2lf%s "; + $options .= " GPRINT:outbits:AVERAGE:%6.2lf%s "; + $options .= " GPRINT:outbits:MAX:%6.2lf%s "; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function trafgraph ($rrd, $graph, $from, $to, $width, $height) -{ - global $rrdtool, $installdir, $mono_font; +function trafgraph ($rrd, $graph, $from, $to, $width, $height) { + global $config, $rrdtool, $installdir, $mono_font; $database = "rrd/" . $rrd; $imgfile = "graphs/" . "$graph"; - $optsa = array( "--alt-autoscale-max", - "-E", - "--start", $from, "--end", $to, - "--width", $width, "--height", $height, - "DEF:inoctets=$database:INOCTETS:AVERAGE", - "DEF:outoctets=$database:OUTOCTETS:AVERAGE", - "CDEF:doutoctets=outoctets,-1,*", - "CDEF:inbits=inoctets,8,*", - "CDEF:outbits=outoctets,8,*", - "CDEF:doutbits=doutoctets,8,*", - "VDEF:95thin=inbits,95,PERCENT", - "VDEF:95thout=outbits,95,PERCENT", - "VDEF:d95thout=doutbits,5,PERCENT", - "AREA:inbits#CDEB8B:", - "COMMENT:BPS Current Average Max 95th %\\n", - "LINE1.25:inbits#006600:In ", - "GPRINT:inbits:LAST:%6.2lf%s", - "GPRINT:inbits:AVERAGE:%6.2lf%s", - "GPRINT:inbits:MAX:%6.2lf%s", - "GPRINT:95thin:%6.2lf%s\\n", - "AREA:doutbits#C3D9FF:", - "LINE1.25:doutbits#000099:Out", - "GPRINT:outbits:LAST:%6.2lf%s", - "GPRINT:outbits:AVERAGE:%6.2lf%s", - "GPRINT:outbits:MAX:%6.2lf%s", - "GPRINT:95thout:%6.2lf%s", - "LINE1:95thin#aa0000", - "LINE1:d95thout#aa0000:" ); - - - 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 { - return $imgfile; - } + $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:inoctets=$database:INOCTETS:AVERAGE"; + $options .= " DEF:outoctets=$database:OUTOCTETS:AVERAGE"; + $options .= " CDEF:octets=inoctets,outoctets,+"; + $options .= " CDEF:doutoctets=outoctets,-1,*"; + $options .= " CDEF:inbits=inoctets,8,*"; + $options .= " CDEF:outbits=outoctets,8,*"; + $options .= " CDEF:doutbits=doutoctets,8,*"; + $options .= " VDEF:totin=inoctets,TOTAL"; + $options .= " VDEF:totout=outoctets,TOTAL"; + $options .= " VDEF:tot=octets,TOTAL"; + $options .= " VDEF:95thin=inbits,95,PERCENT"; + $options .= " VDEF:95thout=outbits,95,PERCENT"; + $options .= " VDEF:d95thout=doutbits,5,PERCENT"; + $options .= " AREA:inbits#CDEB8B:"; + $options .= " COMMENT:BPS\ \ \ \ Current\ \ \ Average\ \ \ \ \ \ Max\ \ \ 95th\ %\\\\n"; + $options .= " LINE1.25:inbits#006600:In\ "; + $options .= " GPRINT:inbits:LAST:%6.2lf%s"; + $options .= " GPRINT:inbits:AVERAGE:%6.2lf%s"; + $options .= " GPRINT:inbits:MAX:%6.2lf%s"; + $options .= " GPRINT:95thin:%6.2lf%s\\\\n"; + $options .= " AREA:doutbits#C3D9FF:"; + $options .= " LINE1.25:doutbits#000099:Out"; + $options .= " GPRINT:outbits:LAST:%6.2lf%s"; + $options .= " GPRINT:outbits:AVERAGE:%6.2lf%s"; + $options .= " GPRINT:outbits:MAX:%6.2lf%s"; + $options .= " GPRINT:95thout:%6.2lf%s\\\\n"; + $options .= " GPRINT:tot:Total\ %6.2lf%s"; + $options .= " GPRINT:totin:\(In\ %6.2lf%s"; + $options .= " GPRINT:totout:Out\ %6.2lf%s\)\\\\l"; + $options .= " LINE1:95thin#aa0000"; + $options .= " LINE1:d95thout#aa0000"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } function pktsgraph ($rrd, $graph, $from, $to, $width, $height) { - global $rrdtool, $installdir, $mono_font; + global $config, $rrdtool, $installdir, $mono_font; $database = "rrd/" . $rrd; $imgfile = "graphs/" . "$graph"; - $optsa = array( "--alt-autoscale-max", - "-l 0", - "-E", - "--start", $from, "--end", $to, - "--width", $width, "--height", $height, - "DEF:in=$database:INUCASTPKTS:AVERAGE", - "DEF:out=$database:OUTUCASTPKTS:AVERAGE", - "CDEF:dout=out,-1,*", - "AREA:in#aa66aa:", - "COMMENT:Packets Current Average Maximum\\n", - "LINE1.25:in#330033:In ", - "GPRINT:in:LAST:%6.2lf%spps", - "GPRINT:in:AVERAGE:%6.2lf%spps", - "GPRINT:in:MAX:%6.2lf%spps\\n", - "AREA:dout#FFDD88:", - "LINE1.25:dout#FF6600:Out ", - "GPRINT:out:LAST:%6.2lf%spps", - "GPRINT:out:AVERAGE:%6.2lf%spps", - "GPRINT:out:MAX:%6.2lf%spps\\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 { - return $imgfile; - } + $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:in=$database:INUCASTPKTS:AVERAGE"; + $options .= " DEF:out=$database:OUTUCASTPKTS:AVERAGE"; + $options .= " CDEF:dout=out,-1,*"; + $options .= " AREA:in#aa66aa:"; + $options .= " COMMENT:Packets\ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ \ Maximum\\\\n"; + $options .= " LINE1.25:in#330033:In\ \ "; + $options .= " GPRINT:in:LAST:%6.2lf%spps"; + $options .= " GPRINT:in:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:in:MAX:%6.2lf%spps\\\\n"; + $options .= " AREA:dout#FFDD88:"; + $options .= " LINE1.25:dout#FF6600:Out\ "; + $options .= " GPRINT:out:LAST:%6.2lf%spps"; + $options .= " GPRINT:out:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:out:MAX:%6.2lf%spps\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function errorgraph ($rrd, $graph, $from, $to, $width, $height) -{ - global $rrdtool, $installdir, $mono_font; - $database = "rrd/" . $rrd; - $imgfile = "graphs/" . "$graph"; - - $optsa = array( - "--alt-autoscale-max", - "-E", - "-l 0", - "--start", $from, "--end", $to, - "--width", $width, "--height", $height, - "DEF:in=$database:INERRORS:AVERAGE", - "DEF:out=$database:OUTERRORS:AVERAGE", - "CDEF:dout=out,-1,*", - "AREA:in#ff3300:", - "COMMENT:Errors Current Average Maximum\\n", - "LINE1.25:in#ff0000:In ", - "GPRINT:in:LAST:%6.2lf%spps", - "GPRINT:in:AVERAGE:%6.2lf%spps", - "GPRINT:in:MAX:%6.2lf%spps\\n", - "AREA:dout#ff6633:", - "LINE1.25:out#cc3300:Out", - "GPRINT:out:LAST:%6.2lf%spps", - "GPRINT:out:AVERAGE:%6.2lf%spps", - "GPRINT:out:MAX:%6.2lf%spps\\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 { - return $imgfile; - } - +function errorgraph ($rrd, $graph, $from, $to, $width, $height) { + 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 "; + if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; } + $options .= " DEF:in=$database:INERRORS:AVERAGE"; + $options .= " DEF:out=$database:OUTERRORS:AVERAGE"; + $options .= " CDEF:dout=out,-1,*"; + $options .= " AREA:in#ff3300:"; + $options .= " COMMENT:Errors\ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ \ Maximum\\\\n"; + $options .= " LINE1.25:in#ff0000:In\ \ "; + $options .= " GPRINT:in:LAST:%6.2lf%spps"; + $options .= " GPRINT:in:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:in:MAX:%6.2lf%spps\\\\n"; + $options .= " AREA:dout#FF6633:"; + $options .= " LINE1.25:dout#cc3300:Out\ "; + $options .= " GPRINT:out:LAST:%6.2lf%spps"; + $options .= " GPRINT:out:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:out:MAX:%6.2lf%spps\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function nucastgraph ($rrd, $graph, $from, $to, $width, $height) -{ - global $rrdtool, $installdir, $mono_font; - $database = "rrd/" . $rrd; - $imgfile = "graphs/" . "$graph"; - $optsa = array( "--start", $from, "--end", $to, - "--width", $width, "--height", $height, - "--alt-autoscale-max", - "-E", - "-l 0", - "DEF:in=$database:INNUCASTPKTS:AVERAGE", - "DEF:out=$database:OUTNUCASTPKTS:AVERAGE", - "CDEF:dout=out,-1,*", - "AREA:in#aa66aa:", - "COMMENT:Packets Current Average Maximum\\n", - "LINE1.25:in#330033:In ", - "GPRINT:in:LAST:%6.2lf%spps", - "GPRINT:in:AVERAGE:%6.2lf%spps", - "GPRINT:in:MAX:%6.2lf%spps\\n", - "AREA:dout#FFDD88:", - "LINE1.25:dout#FF6600:Out ", - "GPRINT:out:LAST:%6.2lf%spps", - "GPRINT:out:AVERAGE:%6.2lf%spps", - "GPRINT:out:MAX:%6.2lf%spps\\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 { - return $imgfile; - } +function nucastgraph ($rrd, $graph, $from, $to, $width, $height) { + 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 "; + if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; } + $options .= " DEF:in=$database:INNUCASTPKTS:AVERAGE"; + $options .= " DEF:out=$database:OUTNUCASTPKTS:AVERAGE"; + $options .= " CDEF:dout=out,-1,*"; + $options .= " AREA:in#aa66aa:"; + $options .= " COMMENT:Packets\ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ \ Maximum\\\\n"; + $options .= " LINE1.25:in#330033:In\ \ "; + $options .= " GPRINT:in:LAST:%6.2lf%spps"; + $options .= " GPRINT:in:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:in:MAX:%6.2lf%spps\\\\n"; + $options .= " AREA:dout#FFDD88:"; + $options .= " LINE1.25:dout#FF6600:Out\ "; + $options .= " GPRINT:out:LAST:%6.2lf%spps"; + $options .= " GPRINT:out:AVERAGE:%6.2lf%spps"; + $options .= " GPRINT:out:MAX:%6.2lf%spps\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function cpugraph ($rrd, $graph , $from, $to, $width, $height) -{ - global $rrdtool, $installdir, $mono_font; - $database = "rrd/" . $rrd; - $imgfile = "graphs/" . "$graph"; - $optsa = array( "--start", $from, "--width", $width, "--height", $height, "--vertical-label", $vertical, "--alt-autoscale-max", - "-l 0", - "-E", - "--title", $title, - "DEF:5s=$database:LOAD5S:AVERAGE", - "DEF:5m=$database:LOAD5M:AVERAGE", - "COMMENT: Days Current Minimum Maximum Average\\n", - "AREA:5m#c5aa00:", - "AREA:5s#ffeeaa:5 sec", - "LINE1:5s#ea8f00:", - "GPRINT:5s:LAST:%6.2lf ", - "GPRINT:5s:AVERAGE:%6.2lf ", - "GPRINT:5s:MAX:%6.2lf ", - "GPRINT:5s:AVERAGE:%6.2lf\\n", - "LINE1.25:5m#aa2200:5min", - "GPRINT:5m:LAST:%6.2lf ", - "GPRINT:5m:AVERAGE:%6.2lf ", - "GPRINT:5m:MAX:%6.2lf ", - "GPRINT:5m:AVERAGE:%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 { - return $imgfile; - } +function cpugraph ($rrd, $graph , $from, $to, $width, $height) { + 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 "; + if($width <= "300") {$options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; } + $options .= " DEF:5s=$database:LOAD5S:AVERAGE"; + $options .= " DEF:5m=$database:LOAD5M:AVERAGE"; + $options .= " COMMENT:\ \ \ \ \ \ \ \ \ \ Current\ \ Minimum\ \ Maximum\ \ Average\\\\n"; + $options .= " AREA:5m#ffee99: LINE1.25:5m#aa2200:Load\ %"; + $options .= " GPRINT:5m:LAST:%6.2lf\ GPRINT:5m:AVERAGE:%6.2lf\ "; + $options .= " GPRINT:5m:MAX:%6.2lf\ GPRINT:5m:AVERAGE:%6.2lf\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function uptimegraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) -{ - global $rrdtool, $installdir, $mono_font; - $rrd = "rrd/" . $rrd; - $imgfile = "graphs/" . "$graph"; - $optsa = array( "--start", $from, "--width", $width, "--height", $height, "--alt-autoscale-max", - "-E", "-l 0", - "DEF:uptime=$rrd:uptime:AVERAGE", - "CDEF:cuptime=uptime,86400,/", - "COMMENT: Days Current Minimum Maximum Average\\n", - "AREA:cuptime#EEEEEE:Uptime", - "LINE1.25:cuptime#36393D:", - "GPRINT:cuptime:LAST:%6.2lf ", - "GPRINT:cuptime:AVERAGE:%6.2lf ", - "GPRINT:cuptime:MAX:%6.2lf ", - "GPRINT:cuptime:AVERAGE:%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 { - return $imgfile; - } +function uptimegraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) { + 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 "; + if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; } + $options .= " DEF:uptime=$database:uptime:AVERAGE"; + $options .= " CDEF:cuptime=uptime,86400,/"; + $options .= " COMMENT:Days\ \ \ \ \ \ Current\ \ Minimum\ \ Maximum\ \ Average\\\\n"; + $options .= " AREA:cuptime#EEEEEE:Uptime"; + $options .= " LINE1.25:cuptime#36393D:"; + $options .= " GPRINT:cuptime:LAST:%6.2lf\ GPRINT:cuptime:AVERAGE:%6.2lf\ "; + $options .= " GPRINT:cuptime:MAX:%6.2lf\ GPRINT:cuptime:AVERAGE:%6.2lf\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } -function memgraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) -{ - global $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:MEMTOTAL=$memrrd:MEMTOTAL:AVERAGE \ - DEF:IOFREE=$memrrd:IOFREE:AVERAGE \ - DEF:IOUSED=$memrrd:IOUSED:AVERAGE \ - DEF:PROCFREE=$memrrd:PROCFREE:AVERAGE \ - DEF:PROCUSED=$memrrd:PROCUSED:AVERAGE \ - CDEF:FREE=IOFREE,PROCFREE,+ \ - CDEF:USED=IOUSED,PROCUSED,+ \ - COMMENT:'Bytes Current Minimum Maximum Average\\n' \ - AREA:USED#f0e0a0:Used\ - GPRINT:USED:LAST:\%6.2lf%s\ - GPRINT:USED:MIN:%6.2lf%s\ - GPRINT:USED:MAX:%6.2lf%s\ - GPRINT:USED:AVERAGE:'%6.2lf%s \\n'\ - AREA:FREE#cccccc:Free:STACK\ - GPRINT:FREE:LAST:\%6.2lf%s\ - GPRINT:FREE:MIN:%6.2lf%s\ - GPRINT:FREE:MAX:%6.2lf%s\ - GPRINT:FREE:AVERAGE:%6.2lf%s\ - LINE1:USED#d0b080:\ - LINE1:MEMTOTAL#000000:"; - - if($width <= "300") {$opts .= "\ - --font LEGEND:7:$mono_font \ - --font AXIS:6:$mono_font \ - --font-render-mode normal";} - - - `$rrdtool graph $imgfile $opts`; - return $imgfile; +function memgraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) { + 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 "; } + $options .= " DEF:MEMTOTAL=$database:MEMTOTAL:AVERAGE"; + $options .= " DEF:IOFREE=$database:IOFREE:AVERAGE"; + $options .= " DEF:IOUSED=$database:IOUSED:AVERAGE"; + $options .= " DEF:PROCFREE=$database:PROCFREE:AVERAGE"; + $options .= " DEF:PROCUSED=$database:PROCUSED:AVERAGE"; + $options .= " CDEF:FREE=IOFREE,PROCFREE,+"; + $options .= " CDEF:USED=IOUSED,PROCUSED,+"; + $options .= " COMMENT:Bytes\ \ \ \ Current\ \ Minimum\ \ Maximum\ \ Average\\\\n"; + $options .= " AREA:USED#ff6060:"; + $options .= " LINE2:USED#cc0000:Used"; + $options .= " GPRINT:USED:LAST:%6.2lf%s"; + $options .= " GPRINT:USED:MIN:%6.2lf%s"; + $options .= " GPRINT:USED:MAX:%6.2lf%s"; + $options .= " GPRINT:USED:AVERAGE:%6.2lf%s\\\\l"; + $options .= " AREA:FREE#e5e5e5:Free:STACK"; + $options .= " GPRINT:FREE:LAST:%6.2lf%s"; + $options .= " GPRINT:FREE:MIN:%6.2lf%s"; + $options .= " GPRINT:FREE:MAX:%6.2lf%s"; + $options .= " GPRINT:FREE:AVERAGE:%6.2lf%s\\\\l"; + $options .= " LINE1:MEMTOTAL#000000:"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } function ip_graph ($rrd, $graph, $from, $to, $width, $height) { - 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, "--alt-autoscale-max", "-E", "-l 0", - "DEF:ipForwDatagrams=$database:ipForwDatagrams:AVERAGE", - "DEF:ipInDelivers=$database:ipInDelivers:AVERAGE", - "DEF:ipInReceives=$database:ipInReceives:AVERAGE", - "DEF:ipOutRequests=$database:ipOutRequests:AVERAGE", - "DEF:ipInDiscards=$database:ipInDiscards:AVERAGE", - "DEF:ipOutDiscards=$database:ipOutDiscards:AVERAGE", - "DEF:ipOutNoRoutes=$database:ipInDiscards:AVERAGE", - "COMMENT:Packets/sec Current Average Maximum\\n", - "LINE1.25:ipForwDatagrams#cc0000:ForwDgrams ", - "GPRINT:ipForwDatagrams:LAST:%6.2lf%s", - "GPRINT:ipForwDatagrams:AVERAGE: %6.2lf%s", - "GPRINT:ipForwDatagrams:MAX: %6.2lf%s\\n", - "LINE1.25:ipInDelivers#00cc00:InDelivers ", - "GPRINT:ipInDelivers:LAST:%6.2lf%s", - "GPRINT:ipInDelivers:AVERAGE: %6.2lf%s", - "GPRINT:ipInDelivers:MAX: %6.2lf%s\\n", - "LINE1.25:ipInReceives#006600:InReceives ", - "GPRINT:ipInReceives:LAST:%6.2lf%s", - "GPRINT:ipInReceives:AVERAGE: %6.2lf%s", - "GPRINT:ipInReceives:MAX: %6.2lf%s\\n", - "LINE1.25:ipOutRequests#0000cc:OutRequests", - "GPRINT:ipOutRequests:LAST:%6.2lf%s", - "GPRINT:ipOutRequests:AVERAGE: %6.2lf%s", - "GPRINT:ipOutRequests:MAX: %6.2lf%s\\n", - "LINE1.25:ipInDiscards#cccc00:InDiscards ", - "GPRINT:ipInDiscards:LAST:%6.2lf%s", - "GPRINT:ipInDiscards:AVERAGE: %6.2lf%s", - "GPRINT:ipInDiscards:MAX: %6.2lf%s\\n", - "LINE1.25:ipOutDiscards#330033:OutDiscards", - "GPRINT:ipOutDiscards:LAST:%6.2lf%s", - "GPRINT:ipOutDiscards:AVERAGE: %6.2lf%s", - "GPRINT:ipOutDiscards:MAX: %6.2lf%s\\n", - "LINE1.25:ipOutNoRoutes#660000:OutNoRoutes", - "GPRINT:ipOutNoRoutes:LAST:%6.2lf%s", - "GPRINT:ipOutNoRoutes:AVERAGE: %6.2lf%s", - "GPRINT:ipOutNoRoutes:MAX: %6.2lf%s\\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 { - return $imgfile; - } + $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:ipForwDatagrams=$database:ipForwDatagrams:AVERAGE"; + $options .= " DEF:ipInDelivers=$database:ipInDelivers:AVERAGE"; + $options .= " DEF:ipInReceives=$database:ipInReceives:AVERAGE"; + $options .= " DEF:ipOutRequests=$database:ipOutRequests:AVERAGE"; + $options .= " DEF:ipInDiscards=$database:ipInDiscards:AVERAGE"; + $options .= " DEF:ipOutDiscards=$database:ipOutDiscards:AVERAGE"; + $options .= " DEF:ipOutNoRoutes=$database:ipInDiscards:AVERAGE"; + $options .= " COMMENT:Packets/sec\ \ \ \ Current\ \ \ Average\ \ \ Maximum\\\n"; + $options .= " LINE1.25:ipForwDatagrams#cc0000:ForwDgrams\ "; + $options .= " GPRINT:ipForwDatagrams:LAST:%6.2lf%s"; + $options .= " GPRINT:ipForwDatagrams:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipForwDatagrams:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipInDelivers#00cc00:InDelivers\ "; + $options .= " GPRINT:ipInDelivers:LAST:%6.2lf%s"; + $options .= " GPRINT:ipInDelivers:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipInDelivers:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipInReceives#006600:InReceives\ "; + $options .= " GPRINT:ipInReceives:LAST:%6.2lf%s"; + $options .= " GPRINT:ipInReceives:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipInReceives:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipOutRequests#0000cc:OutRequests"; + $options .= " GPRINT:ipOutRequests:LAST:%6.2lf%s"; + $options .= " GPRINT:ipOutRequests:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipOutRequests:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipInDiscards#cccc00:InDiscards\ "; + $options .= " GPRINT:ipInDiscards:LAST:%6.2lf%s"; + $options .= " GPRINT:ipInDiscards:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipInDiscards:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipOutDiscards#330033:OutDiscards"; + $options .= " GPRINT:ipOutDiscards:LAST:%6.2lf%s"; + $options .= " GPRINT:ipOutDiscards:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipOutDiscards:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:ipOutNoRoutes#660000:OutNoRoutes"; + $options .= " GPRINT:ipOutNoRoutes:LAST:%6.2lf%s"; + $options .= " GPRINT:ipOutNoRoutes:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:ipOutNoRoutes:MAX:\ %6.2lf%s\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } function icmp_graph ($rrd, $graph, $from, $to, $width, $height) { - 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, "--alt-autoscale-max", "-E", "-l 0", - "DEF:icmpInMsgs=$database:icmpInMsgs:AVERAGE", - "DEF:icmpOutMsgs=$database:icmpOutMsgs:AVERAGE", - "DEF:icmpInErrors=$database:icmpInErrors:AVERAGE", - "DEF:icmpOutErrors=$database:icmpOutErrors:AVERAGE", - "DEF:icmpInEchos=$database:icmpInEchos:AVERAGE", - "DEF:icmpOutEchos=$database:icmpOutEchos:AVERAGE", - "DEF:icmpInEchoReps=$database:icmpInEchoReps:AVERAGE", - "DEF:icmpOutEchoReps=$database:icmpOutEchoReps:AVERAGE", - "COMMENT:Packets/sec Current Average Maximum\\n", - "LINE1.25:icmpInMsgs#00cc00:InMsgs ", - "GPRINT:icmpInMsgs:LAST:%6.2lf%s", - "GPRINT:icmpInMsgs:AVERAGE: %6.2lf%s", - "GPRINT:icmpInMsgs:MAX: %6.2lf%s\\n", - "LINE1.25:icmpOutMsgs#006600:OutMsgs ", - "GPRINT:icmpOutMsgs:LAST:%6.2lf%s", - "GPRINT:icmpOutMsgs:AVERAGE: %6.2lf%s", - "GPRINT:icmpOutMsgs:MAX: %6.2lf%s\\n", - "LINE1.25:icmpInErrors#cc0000:InErrors ", - "GPRINT:icmpInErrors:LAST:%6.2lf%s", - "GPRINT:icmpInErrors:AVERAGE: %6.2lf%s", - "GPRINT:icmpInErrors:MAX: %6.2lf%s\\n", - "LINE1.25:icmpOutErrors#660000:OutErrors ", - "GPRINT:icmpOutErrors:LAST:%6.2lf%s", - "GPRINT:icmpOutErrors:AVERAGE: %6.2lf%s", - "GPRINT:icmpOutErrors:MAX: %6.2lf%s\\n", - "LINE1.25:icmpInEchos#0066cc:InEchos ", - "GPRINT:icmpInEchos:LAST:%6.2lf%s", - "GPRINT:icmpInEchos:AVERAGE: %6.2lf%s", - "GPRINT:icmpInEchos:MAX: %6.2lf%s\\n", - "LINE1.25:icmpOutEchos#003399:OutEchos ", - "GPRINT:icmpOutEchos:LAST:%6.2lf%s", - "GPRINT:icmpOutEchos:AVERAGE: %6.2lf%s", - "GPRINT:icmpOutEchos:MAX: %6.2lf%s\\n", - "LINE1.25:icmpInEchoReps#cc00cc:InEchoReps ", - "GPRINT:icmpInEchoReps:LAST:%6.2lf%s", - "GPRINT:icmpInEchoReps:AVERAGE: %6.2lf%s", - "GPRINT:icmpInEchoReps:MAX: %6.2lf%s\\n", - "LINE1.25:icmpOutEchoReps#990099:OutEchoReps", - "GPRINT:icmpOutEchoReps:LAST:%6.2lf%s", - "GPRINT:icmpOutEchoReps:AVERAGE: %6.2lf%s", - "GPRINT:icmpOutEchoReps:MAX: %6.2lf%s\\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 { - return $imgfile; - } + $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:icmpInMsgs=$database:icmpInMsgs:AVERAGE"; + $options .= " DEF:icmpOutMsgs=$database:icmpOutMsgs:AVERAGE"; + $options .= " DEF:icmpInErrors=$database:icmpInErrors:AVERAGE"; + $options .= " DEF:icmpOutErrors=$database:icmpOutErrors:AVERAGE"; + $options .= " DEF:icmpInEchos=$database:icmpInEchos:AVERAGE"; + $options .= " DEF:icmpOutEchos=$database:icmpOutEchos:AVERAGE"; + $options .= " DEF:icmpInEchoReps=$database:icmpInEchoReps:AVERAGE"; + $options .= " DEF:icmpOutEchoReps=$database:icmpOutEchoReps:AVERAGE"; + $options .= " COMMENT:Packets/sec\ \ \ \ Current\ \ \ \ Average\ \ \ Maximum\\\n"; + $options .= " LINE1.25:icmpInMsgs#00cc00:InMsgs "; + $options .= " GPRINT:icmpInMsgs:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpInMsgs:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpInMsgs:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpOutMsgs#006600:OutMsgs "; + $options .= " GPRINT:icmpOutMsgs:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpOutMsgs:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpOutMsgs:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpInErrors#cc0000:InErrors "; + $options .= " GPRINT:icmpInErrors:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpInErrors:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpInErrors:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpOutErrors#660000:OutErrors "; + $options .= " GPRINT:icmpOutErrors:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpOutErrors:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpOutErrors:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpInEchos#0066cc:InEchos "; + $options .= " GPRINT:icmpInEchos:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpInEchos:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpInEchos:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpOutEchos#003399:OutEchos "; + $options .= " GPRINT:icmpOutEchos:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpOutEchos:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpOutEchos:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpInEchoReps#cc00cc:InEchoReps "; + $options .= " GPRINT:icmpInEchoReps:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpInEchoReps:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpInEchoReps:MAX:\ %6.2lf%s\\\n"; + $options .= " LINE1.25:icmpOutEchoReps#990099:OutEchoReps"; + $options .= " GPRINT:icmpOutEchoReps:LAST:%6.2lf%s"; + $options .= " GPRINT:icmpOutEchoReps:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:icmpOutEchoReps:MAX:\ %6.2lf%s\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } function tcp_graph ($rrd, $graph, $from, $to, $width, $height) { - 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, "--alt-autoscale-max", "-E", "-l 0", - "DEF:tcpActiveOpens=$database:tcpActiveOpens:AVERAGE", - "DEF:tcpPassiveOpens=$database:tcpPassiveOpens:AVERAGE", - "DEF:tcpAttemptFails=$database:tcpAttemptFails:AVERAGE", - "DEF:tcpEstabResets=$database:tcpEstabResets:AVERAGE", - "DEF:tcpInSegs=$database:tcpInSegs:AVERAGE", - "DEF:tcpOutSegs=$database:tcpOutSegs:AVERAGE", - "DEF:tcpRetransSegs=$database:tcpRetransSegs:AVERAGE", - "COMMENT:Packets/sec Current Average Maximum\\n", - "LINE1.25:tcpActiveOpens#00cc00:ActiveOpens ", - "GPRINT:tcpActiveOpens:LAST:%6.2lf%s", - "GPRINT:tcpActiveOpens:AVERAGE: %6.2lf%s", - "GPRINT:tcpActiveOpens:MAX: %6.2lf%s\\n", - "LINE1.25:tcpPassiveOpens#006600:PassiveOpens", - "GPRINT:tcpPassiveOpens:LAST:%6.2lf%s", - "GPRINT:tcpPassiveOpens:AVERAGE: %6.2lf%s", - "GPRINT:tcpPassiveOpens:MAX: %6.2lf%s\\n", - "LINE1.25:tcpAttemptFails#cc0000:AttemptFails", - "GPRINT:tcpAttemptFails:LAST:%6.2lf%s", - "GPRINT:tcpAttemptFails:AVERAGE: %6.2lf%s", - "GPRINT:tcpAttemptFails:MAX: %6.2lf%s\\n", - "LINE1.25:tcpEstabResets#660000:EstabResets ", - "GPRINT:tcpEstabResets:LAST:%6.2lf%s", - "GPRINT:tcpEstabResets:AVERAGE: %6.2lf%s", - "GPRINT:tcpEstabResets:MAX: %6.2lf%s\\n", - "LINE1.25:tcpInSegs#0066cc:InSegs ", - "GPRINT:tcpInSegs:LAST:%6.2lf%s", - "GPRINT:tcpInSegs:AVERAGE: %6.2lf%s", - "GPRINT:tcpInSegs:MAX: %6.2lf%s\\n", - "LINE1.25:tcpOutSegs#003399:OutSegs ", - "GPRINT:tcpOutSegs:LAST:%6.2lf%s", - "GPRINT:tcpOutSegs:AVERAGE: %6.2lf%s", - "GPRINT:tcpOutSegs:MAX: %6.2lf%s\\n", - "LINE1.25:tcpRetransSegs#cc00cc:RetransSegs ", - "GPRINT:tcpRetransSegs:LAST:%6.2lf%s", - "GPRINT:tcpRetransSegs:AVERAGE: %6.2lf%s", - "GPRINT:tcpRetransSegs:MAX: %6.2lf%s\\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 { - return $imgfile; - } + $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:icmpInMsgs=$database:icmpInMsgs:AVERAGE"; + $options .= " DEF:tcpActiveOpens=$database:tcpActiveOpens:AVERAGE"; + $options .= " DEF:tcpPassiveOpens=$database:tcpPassiveOpens:AVERAGE"; + $options .= " DEF:tcpAttemptFails=$database:tcpAttemptFails:AVERAGE"; + $options .= " DEF:tcpEstabResets=$database:tcpEstabResets:AVERAGE"; + $options .= " DEF:tcpInSegs=$database:tcpInSegs:AVERAGE"; + $options .= " DEF:tcpOutSegs=$database:tcpOutSegs:AVERAGE"; + $options .= " DEF:tcpRetransSegs=$database:tcpRetransSegs:AVERAGE"; + $options .= " COMMENT:Packets/sec\ \ \ \ Current\ \ \ \ Average\ \ \ Maximum\\\n"; + $options .= " LINE1.25:tcpActiveOpens#00cc00:ActiveOpens\ "; + $options .= " GPRINT:tcpActiveOpens:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpActiveOpens:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpActiveOpens:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpPassiveOpens#006600:PassiveOpens"; + $options .= " GPRINT:tcpPassiveOpens:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpPassiveOpens:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpPassiveOpens:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpAttemptFails#cc0000:AttemptFails"; + $options .= " GPRINT:tcpAttemptFails:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpAttemptFails:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpAttemptFails:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpEstabResets#660000:EstabResets\ "; + $options .= " GPRINT:tcpEstabResets:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpEstabResets:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpEstabResets:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpInSegs#0066cc:InSegs\ \ \ \ \ \ "; + $options .= " GPRINT:tcpInSegs:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpInSegs:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpInSegs:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpOutSegs#003399:OutSegs\ \ \ \ \ "; + $options .= " GPRINT:tcpOutSegs:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpOutSegs:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpOutSegs:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:tcpRetransSegs#cc00cc:RetransSegs\ "; + $options .= " GPRINT:tcpRetransSegs:LAST:%6.2lf%s"; + $options .= " GPRINT:tcpRetransSegs:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:tcpRetransSegs:MAX:\ %6.2lf%s\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } function udp_graph ($rrd, $graph, $from, $to, $width, $height) { - 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, "--alt-autoscale-max", "-E", "-l 0", - "DEF:udpInDatagrams=$database:udpInDatagrams:AVERAGE", - "DEF:udpOutDatagrams=$database:udpOutDatagrams:AVERAGE", - "DEF:udpInErrors=$database:udpInErrors:AVERAGE", - "DEF:udpNoPorts=$database:udpNoPorts:AVERAGE", - "COMMENT:Packets/sec Current Average Maximum\\n", - "LINE1.25:udpInDatagrams#00cc00:InDatagrams ", - "GPRINT:udpInDatagrams:LAST:%6.2lf%s", - "GPRINT:udpInDatagrams:AVERAGE: %6.2lf%s", - "GPRINT:udpInDatagrams:MAX: %6.2lf%s\\n", - "LINE1.25:udpOutDatagrams#006600:OutDatagrams", - "GPRINT:udpOutDatagrams:LAST:%6.2lf%s", - "GPRINT:udpOutDatagrams:AVERAGE: %6.2lf%s", - "GPRINT:udpOutDatagrams:MAX: %6.2lf%s\\n", - "LINE1.25:udpInErrors#cc0000:InErrors ", - "GPRINT:udpInErrors:LAST:%6.2lf%s", - "GPRINT:udpInErrors:AVERAGE: %6.2lf%s", - "GPRINT:udpInErrors:MAX: %6.2lf%s\\n", - "LINE1.25:udpNoPorts#660000:NoPorts ", - "GPRINT:udpNoPorts:LAST:%6.2lf%s", - "GPRINT:udpNoPorts:AVERAGE: %6.2lf%s", - "GPRINT:udpNoPorts:MAX: %6.2lf%s\\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 { - return $imgfile; - } + $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:icmpInMsgs=$database:icmpInMsgs:AVERAGE"; + $options .= " DEF:udpInDatagrams=$database:udpInDatagrams:AVERAGE"; + $options .= " DEF:udpOutDatagrams=$database:udpOutDatagrams:AVERAGE"; + $options .= " DEF:udpInErrors=$database:udpInErrors:AVERAGE"; + $options .= " DEF:udpNoPorts=$database:udpNoPorts:AVERAGE"; + $options .= " COMMENT:Packets/sec\ \ \ \ Current\ \ \ \ Average\ \ \ Maximum\\\\n"; + $options .= " LINE1.25:udpInDatagrams#00cc00:InDatagrams\ "; + $options .= " GPRINT:udpInDatagrams:LAST:%6.2lf%s"; + $options .= " GPRINT:udpInDatagrams:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:udpInDatagrams:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:udpOutDatagrams#006600:OutDatagrams"; + $options .= " GPRINT:udpOutDatagrams:LAST:%6.2lf%s"; + $options .= " GPRINT:udpOutDatagrams:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:udpOutDatagrams:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:udpInErrors#cc0000:InErrors\ \ \ \ "; + $options .= " GPRINT:udpInErrors:LAST:%6.2lf%s"; + $options .= " GPRINT:udpInErrors:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:udpInErrors:MAX:\ %6.2lf%s\\\\n"; + $options .= " LINE1.25:udpNoPorts#660000:NoPorts\ \ \ \ \ "; + $options .= " GPRINT:udpNoPorts:LAST:%6.2lf%s"; + $options .= " GPRINT:udpNoPorts:AVERAGE:\ %6.2lf%s"; + $options .= " GPRINT:udpNoPorts:MAX:\ %6.2lf%s\\\\n"; + $thing = `$rrdtool graph $imgfile $options`; + return $imgfile; } diff --git a/includes/ios.php b/includes/ios.php index 5576c66ca6..f3196399c6 100755 --- a/includes/ios.php +++ b/includes/ios.php @@ -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`; } ?> diff --git a/includes/polling/device-unix.inc.php b/includes/polling/device-unix.inc.php index 85e8cab635..6bdf21673b 100755 --- a/includes/polling/device-unix.inc.php +++ b/includes/polling/device-unix.inc.php @@ -1,19 +1,12 @@ = '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['courier']) { + include("includes/polling/courierstats.inc.php"); + } + + if($device['postfix']) { + include("includes/polling/mailstats.inc.php"); + } + 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`; - } - - list($ahits,$abits) = explode("\n", `./get-apache.sh $hostname`); - $abits = $abits * 8; - - rrd_update($apacherrd,"N:$abits:$ahits"); - } // end apache + include("includes/polling/apachestats.inc.php"); + } } // end Non-m0n0wall diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index 27eb3ee714..9661a05365 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -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]'"); + + } ?> diff --git a/includes/procurve-graphing.php b/includes/procurve-graphing.php index e034f72aad..7c8453322d 100755 --- a/includes/procurve-graphing.php +++ b/includes/procurve-graphing.php @@ -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; + } + } diff --git a/includes/snom-graphing.php b/includes/snom-graphing.php index 116c27cb11..27e72f2951 100644 --- a/includes/snom-graphing.php +++ b/includes/snom-graphing.php @@ -1,7 +1,7 @@ = "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"); + $linkdone[] = "$src $link_data[sif] $dst $link_data[dif]"; + $x++; + } + } + + +echo("\n}\n"); } -$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"; +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.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 +130,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 +152,6 @@ 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"); diff --git a/poll-device.php b/poll-device.php index 461dfd56e9..715bcbec18 100755 --- a/poll-device.php +++ b/poll-device.php @@ -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 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)) { - unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features); - unset($location); unset($hardware); - unset($sysDescr); + 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); $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") { @@ -25,14 +53,22 @@ while ($device = mysql_fetch_array($device_query)) { } else { $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 .= " | grep -v 'Cisco Internetwork Operating System Software'"; + $snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $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"); + } ?> diff --git a/poll-os.php b/poll-os.php index e93d4aa5e6..361de1ee07 100755 --- a/poll-os.php +++ b/poll-os.php @@ -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"); } diff --git a/poll-reachability.php b/poll-reachability.php index 5b64b5593b..56753ef7f9 100755 --- a/poll-reachability.php +++ b/poll-reachability.php @@ -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"); diff --git a/process-syslog.php b/process-syslog.php index 9ddaab11fa..38dd89f924 100755 --- a/process-syslog.php +++ b/process-syslog.php @@ -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']); }