some sensor unification, rename sensor rrds and rename the DS, add testing IPMI support (no web-part yet) - tested against Intel RMM3 and working. some further cleanups as well.

git-svn-id: http://www.observium.org/svn/observer/trunk@1758 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-12-15 17:54:42 +00:00
parent 500ed09299
commit 06d2a707d5
25 changed files with 293 additions and 182 deletions

View File

@@ -14,3 +14,4 @@ ALTER TABLE `vrfs` CHANGE `mplsVpnVrfRouteDistinguisher` `mplsVpnVrfRouteDisting
ALTER TABLE `devices` ADD `timeout` INT NULL DEFAULT NULL AFTER `port`; ALTER TABLE `devices` ADD `timeout` INT NULL DEFAULT NULL AFTER `port`;
ALTER TABLE `devices` ADD `retries` INT NULL DEFAULT NULL AFTER `timeout`; ALTER TABLE `devices` ADD `retries` INT NULL DEFAULT NULL AFTER `timeout`;
ALTER TABLE `perf_times` CHANGE `duration` `duration` DOUBLE( 8, 2 ) NOT NULL ALTER TABLE `perf_times` CHANGE `duration` `duration` DOUBLE( 8, 2 ) NOT NULL
ALTER TABLE `sensors` ADD `poller_type` VARCHAR(16) NOT NULL DEFAULT 'snmp' AFTER `device_id`;

View File

@@ -45,10 +45,10 @@ if (isset($options['d'])) {
ini_set('error_reporting', 1); ini_set('error_reporting', 1);
} else { } else {
$debug = FALSE; $debug = FALSE;
ini_set('display_errors', 0); # ini_set('display_errors', 0);
ini_set('display_startup_errors', 0); ini_set('display_startup_errors', 0);
ini_set('log_errors', 0); ini_set('log_errors', 0);
ini_set('error_reporting', 0); # ini_set('error_reporting', 0);
} }
@@ -79,22 +79,26 @@ if (file_exists('.svn'))
$db_rev = 0; $db_rev = 0;
} }
if ($db_rev+0 < "1223") { if ($db_rev+0 < 1223) {
include("fix-events.php"); ## Fix events table (needs to copy some data around, so needs script) include("fix-events.php"); ## Fix events table (needs to copy some data around, so needs script)
} }
if($db_rev+0 < 1656) { if ($db_rev+0 < 1656) {
include('fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656 include('fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656
} }
if ($db_rev+0 < 1757) {
include('fix-sensor-rrd.php'); ## Rewrites all sensor RRDs. Nothing will work without this after 1757
}
if ($dbu_rev+0 > $db_rev) if ($dbu_rev+0 > $db_rev)
{ {
echo("SVN revision changed.\n"); echo("SVN revision changed.\n");
if($db_rev+0 < "1000") { if ($db_rev+0 < "1000") {
echo("Running pre-revision 1000 SQL update script...\n"); echo("Running pre-revision 1000 SQL update script...\n");
shell_exec("scripts/update-sql.php database-update-pre1000.sql"); shell_exec("scripts/update-sql.php database-update-pre1000.sql");
} }
if($db_rev+0 < "1435") { if ($db_rev+0 < "1435") {
echo("Running pre-revision 1435 SQL update script...\n"); echo("Running pre-revision 1435 SQL update script...\n");
shell_exec("scripts/update-sql.php database-update-pre1435.sql"); shell_exec("scripts/update-sql.php database-update-pre1435.sql");
} }

View File

@@ -2,34 +2,16 @@
if ($config['overview_show_sysDescr']) if ($config['overview_show_sysDescr'])
{ {
echo('<div style="font-family: courier, serif; margin: 10px";><strong>' . $device['sysDescr'] . "</strong></div>"); echo('<div style="font-family: courier, serif; margin: 10px"><strong>' . $device['sysDescr'] . "</strong></div>");
} }
$uptime = $device['uptime']; $uptime = $device['uptime'];
# if(is_file("images/devices/" . $device['hardware'] . ".gif"))
# {
# $dev_img = "<div style='float: left;'><img src='images/devices/" . $device['hardware'] . ".gif' align=absmiddle></img></div>";
# }
# elseif (is_file("images/devices/" . $device['hardware'] . ".jpg"))
# {
# $dev_img = "<div style='float: left;'><img src='images/devices/" . $device['hardware'] . ".jpg' align=absmiddle></img></div>";
# }
# elseif (is_file("images/devices/" . $device['hardware'] . ".png"))
# {
# $dev_img = "<div style='float: left;'><img src='images/devices/" . $device['hardware'] . ".png' align=absmiddle></img></div>";
# }
# else
# {
# $dev_img = '';
# }
if ($device['os'] == "ios") { formatCiscoHardware($device); } if ($device['os'] == "ios") { formatCiscoHardware($device); }
if ($device['features']) { $device['features'] = "(".$device['features'].")"; } if ($device['features']) { $device['features'] = "(".$device['features'].")"; }
$device['os_text'] = $config['os'][$device['os']]['text']; $device['os_text'] = $config['os'][$device['os']]['text'];
echo($dev_img . ' echo('<table width="100%">');
<table width="100%">');
if($device['hardware']) if($device['hardware'])
{ {

View File

@@ -10,11 +10,11 @@ include("includes/graphs/common.inc.php");
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 18),0,18); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 18),0,18);
$rrd_options .= " DEF:current=$rrd_filename:current:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " LINE1.5:current#cc0000:'" . $sensor['sensor_descr_fixed']."'"; $rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'";
$rrd_options .= " GPRINT:current$current_id:MIN:%5.2lfA"; $rrd_options .= " GPRINT:sensor$current_id:MIN:%5.2lfA";
$rrd_options .= " GPRINT:current:LAST:%5.2lfA"; $rrd_options .= " GPRINT:sensor:LAST:%5.2lfA";
$rrd_options .= " GPRINT:current:MAX:%5.2lfA\\\\l"; $rrd_options .= " GPRINT:sensor:MAX:%5.2lfA\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -6,14 +6,14 @@ include("includes/graphs/common.inc.php");
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $sensor['sensor_descr'] . ".rrd"); $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fanspeed-" . $sensor['sensor_descr'] . ".rrd");
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 20),0,20); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 20),0,20);
$rrd_options .= " DEF:fan=$rrd_filename:fan:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " LINE1.5:fan#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( $rrd_options .= " LINE1.5:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " GPRINT:fan:LAST:%3.0lfrpm"; $rrd_options .= " GPRINT:sensor:LAST:%3.0lfrpm";
$rrd_options .= " GPRINT:fan:MAX:%3.0lfrpm\\\\l"; $rrd_options .= " GPRINT:sensor:MAX:%3.0lfrpm\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -4,16 +4,16 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("freq-" . $sensor['sensor_descr'] . ".rrd"); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("frequency-" . $sensor['sensor_descr'] . ".rrd");
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28);
$rrd_options .= " DEF:freq=$rrd_filename:freq:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " LINE1.5:freq#cc0000:'" . $sensor['sensor_descr_fixed']."'"; $rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'";
$rrd_options .= " GPRINT:freq:LAST:%3.0lfHz"; $rrd_options .= " GPRINT:sensor:LAST:%3.0lfHz";
$rrd_options .= " GPRINT:freq:MAX:%3.0lfHz\\\\l"; $rrd_options .= " GPRINT:sensor:MAX:%3.0lfHz\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -12,21 +12,21 @@ include("includes/graphs/common.inc.php");
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28);
$rrd_options .= " DEF:humidity=$rrd_filename:humidity:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " DEF:humidity_max=$rrd_filename:humidity:MAX"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX";
$rrd_options .= " DEF:humidity_min=$rrd_filename:humidity:MIN"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN";
$rrd_options .= " CDEF:humiditywarm=humidity_max,".$sensor['sensor_limit'].",GT,humidity,UNKN,IF"; $rrd_options .= " CDEF:sensorwarm=humidity_max,".$sensor['sensor_limit'].",GT,humidity,UNKN,IF";
$rrd_options .= " CDEF:humiditycold=humidity_min,20,LT,humidity,UNKN,IF"; $rrd_options .= " CDEF:sensorcold=humidity_min,20,LT,humidity,UNKN,IF";
$rrd_options .= " AREA:humidity_max#c5c5c5"; $rrd_options .= " AREA:sensor_max#c5c5c5";
$rrd_options .= " AREA:humidity_min#ffffffff"; $rrd_options .= " AREA:sensor_min#ffffffff";
# $rrd_options .= " AREA:humidity#bbd392"; # $rrd_options .= " AREA:sensor#bbd392";
# $rrd_options .= " AREA:humiditywarm#FFCCCC"; # $rrd_options .= " AREA:sensorwarm#FFCCCC";
# $rrd_options .= " AREA:humiditycold#CCCCFF"; # $rrd_options .= " AREA:sensorcold#CCCCFF";
$rrd_options .= " LINE1:humidity#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( $rrd_options .= " LINE1:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1:humiditywarm#660000"; $rrd_options .= " LINE1:sensorwarm#660000";
$rrd_options .= " GPRINT:humidity:LAST:%3.0lf%%"; $rrd_options .= " GPRINT:sensor:LAST:%3.0lf%%";
$rrd_options .= " GPRINT:humidity:MAX:%3.0lf%%\\\\l"; $rrd_options .= " GPRINT:sensor:MAX:%3.0lf%%\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -8,30 +8,30 @@ include("includes/graphs/common.inc.php");
$rrd_options .= " COMMENT:' Cur Min Max\\n'"; $rrd_options .= " COMMENT:' Cur Min Max\\n'";
### FIXME: Overwrite default because it won't work here yet ### FIXME: Overwrite default because it won't work here yet
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd"; $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/temperature-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21);
$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); $sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed']));
$rrd_options .= " DEF:temp=$rrd_filename:temp:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " DEF:temp_max=$rrd_filename:temp:MAX"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX";
$rrd_options .= " DEF:temp_min=$rrd_filename:temp:MIN"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN";
$rrd_options .= " CDEF:tempwarm=temp_max,".$sensor['sensor_limit'].",GT,temp,UNKN,IF"; $rrd_options .= " CDEF:sensorwarm=sensor_max,".$sensor['sensor_limit'].",GT,sensor,UNKN,IF";
$rrd_options .= " CDEF:tempcold=temp_min,20,LT,temp,UNKN,IF"; $rrd_options .= " CDEF:sensorcold=sensor_min,20,LT,sensor,UNKN,IF";
$rrd_options .= " AREA:temp_max#c5c5c5"; $rrd_options .= " AREA:sensor_max#c5c5c5";
$rrd_options .= " AREA:temp_min#ffffffff"; $rrd_options .= " AREA:sensor_min#ffffffff";
# $rrd_options .= " AREA:temp#bbd392"; # $rrd_options .= " AREA:sensor#bbd392";
# $rrd_options .= " AREA:tempwarm#FFCCCC"; # $rrd_options .= " AREA:sensorwarm#FFCCCC";
# $rrd_options .= " AREA:tempcold#CCCCFF"; # $rrd_options .= " AREA:sensorcold#CCCCFF";
# $rrd_options .= " LINE1:temp#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( # $rrd_options .= " LINE1:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1.5:temp#cc0000:'" . $sensor['sensor_descr_fixed']."'"; $rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'";
# $rrd_options .= " LINE1.5:tempwarm#660000"; # $rrd_options .= " LINE1.5:sensorwarm#660000";
$rrd_options .= " GPRINT:temp:LAST:%4.1lfC"; $rrd_options .= " GPRINT:sensor:LAST:%4.1lfC";
$rrd_options .= " GPRINT:temp_min:MIN:%4.1lfC"; $rrd_options .= " GPRINT:sensor_min:MIN:%4.1lfC";
$rrd_options .= " GPRINT:temp_max:MAX:%4.1lfC\\\\l"; $rrd_options .= " GPRINT:sensor_max:MAX:%4.1lfC\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -4,7 +4,7 @@ $scale_min = "0";
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/volt-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd"; $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/voltage-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_options .= " -A "; $rrd_options .= " -A ";
$rrd_options .= " COMMENT:' Last Max\\n'"; $rrd_options .= " COMMENT:' Last Max\\n'";
@@ -12,17 +12,17 @@ $rrd_options .= " COMMENT:' Last Max\\n'";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 22),0,22); $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 22),0,22);
$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); $sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed']));
$rrd_options .= " DEF:volt=$rrd_filename:volt:AVERAGE"; $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$rrd_options .= " DEF:volt_max=$rrd_filename:volt:MAX"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX";
$rrd_options .= " DEF:volt_min=$rrd_filename:volt:MIN"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN";
$rrd_options .= " AREA:volt_max#c5c5c5"; $rrd_options .= " AREA:sensor_max#c5c5c5";
$rrd_options .= " AREA:volt_min#ffffffff"; $rrd_options .= " AREA:sensor_min#ffffffff";
#$rrd_options .= " AREA:volt#FFFF99"; #$rrd_options .= " AREA:sensor#FFFF99";
$rrd_options .= " LINE1.5:volt#cc0000:'" . $sensor['sensor_descr_fixed']."'"; $rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'";
$rrd_options .= " GPRINT:volt:LAST:%6.2lfV"; $rrd_options .= " GPRINT:sensor:LAST:%6.2lfV";
$rrd_options .= " GPRINT:volt:MAX:%6.2lfV\\\\l"; $rrd_options .= " GPRINT:sensor:MAX:%6.2lfV\\\\l";
if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes"; if(is_numeric($sensor['sensor_limit'])) $rrd_options .= " HRULE:".$sensor['sensor_limit']."#999999::dashes";
if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes"; if(is_numeric($sensor['sensor_limit_low'])) $rrd_options .= " HRULE:".$sensor['sensor_limit_low']."#999999::dashes";

View File

@@ -229,6 +229,7 @@ echo("</ul>");
echo(' echo('
<div class="contentstyle">'); <div class="contentstyle">');
## FIXME safe??
include("pages/device/".mres($section).".inc.php"); include("pages/device/".mres($section).".inc.php");

View File

@@ -60,9 +60,6 @@ if(is_array($oids))
$valid = TRUE; $valid = TRUE;
$type = $entitysensor[$entry['entPhySensorType']]; $type = $entitysensor[$entry['entPhySensorType']];
$descr = str_ireplace("temperature", "", $descr);
$descr = str_ireplace("sensor", "", $descr);
### FIXME this stuff is foul ### FIXME this stuff is foul

View File

@@ -1,28 +1,27 @@
<?php <?php
### Discover sensors ### Discover sensors
function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL) function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL, $poller_type = 'snmp')
{ {
global $config, $debug; global $config, $debug;
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); } if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0') if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE poller_type='" . mres($poller_type) . "' AND sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
{ {
if(!$high_limit) { $high_limit = sensor_limit($class, $current); } if(!$high_limit) { $high_limit = sensor_limit($class, $current); }
if(!$low_limit) { $low_limit = sensor_low_limit($class, $current); } if(!$low_limit) { $low_limit = sensor_low_limit($class, $current); }
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_divisor`, `sensor_multiplier`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) "; $query = "INSERT INTO sensors (`poller_type`,`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_divisor`, `sensor_multiplier`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) ";
$query .= " VALUES ('" . mres($class) . "', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$divisor', '$multiplier', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')"; $query .= " VALUES ('" . mres($poller_type) . "','" . mres($class) . "', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$divisor', '$multiplier', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')";
mysql_query($query); mysql_query($query);
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); } if($debug) { echo("$query\n". mysql_affected_rows() . " inserted\n"); }
echo("+"); echo("+");
$sensor_id = mysql_result(mysql_query("SELECT `sensor_id` FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0); log_event("Sensor Added: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device['device_id'], 'sensor', mysql_insert_id());
log_event("Sensor Added: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device['device_id'], 'sensor', $sensor_id);
} }
else else
{ {
$sensor_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); $sensor_entry = mysql_fetch_assoc(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
if(!$high_limit) if(!$high_limit)
{ {
@@ -36,7 +35,9 @@ function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr,
if ($high_limit != $sensor_entry['sensor_limit']) if ($high_limit != $sensor_entry['sensor_limit'])
{ {
mysql_query("UPDATE sensors SET `sensor_limit` = '".$high_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'"); $query = "UPDATE sensors SET `sensor_limit` = '".$high_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'";
mysql_query($query);
if($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); }
echo("H"); echo("H");
log_event("Sensor High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$high_limit.")", $device['device_id'], 'sensor', $sensor_id); log_event("Sensor High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$high_limit.")", $device['device_id'], 'sensor', $sensor_id);
} }
@@ -53,7 +54,9 @@ function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr,
if ($sensor_entry['sensor_limit_low'] != $low_limit) if ($sensor_entry['sensor_limit_low'] != $low_limit)
{ {
mysql_query("UPDATE sensors SET `sensor_limit_low` = '".$low_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'"); $query = "UPDATE sensors SET `sensor_limit_low` = '".$low_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'";
mysql_query($query);
if($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); }
echo("L"); echo("L");
log_event("Sensor Low Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$low_limit.")", $device['device_id'], 'sensor', $sensor_id); log_event("Sensor Low Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$low_limit.")", $device['device_id'], 'sensor', $sensor_id);
} }
@@ -64,21 +67,23 @@ function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr,
} }
else else
{ {
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_multiplier` = '$multiplier', `sensor_divisor` = '$divisor' WHERE `sensor_class` = '" . mres($class) . "' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index' "); $query = "UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_multiplier` = '$multiplier', `sensor_divisor` = '$divisor' WHERE `sensor_class` = '" . mres($class) . "' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index'";
mysql_query($query);
echo("U"); echo("U");
log_event("Sensor Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device['device_id'], 'sensor', $sensor_id); log_event("Sensor Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr), $device['device_id'], 'sensor', $sensor_id);
if($debug) { echo("$query ". mysql_affected_rows() . " updated"); } if($debug) { echo("$query\n". mysql_affected_rows() . " updated\n"); }
} }
} }
$valid[$class][$type][$index] = 1; $valid[$class][$type][$index] = 1;
return $return; return $return;
} }
function sensor_low_limit ($class, $current) { function sensor_low_limit ($class, $current)
{
$limit = NULL; $limit = NULL;
switch($class) { switch($class)
{
case 'temperature': case 'temperature':
$limit = $current * 0.7; $limit = $current * 0.7;
break; break;
@@ -102,11 +107,12 @@ function sensor_low_limit ($class, $current) {
} }
function sensor_limit ($class, $current) { function sensor_limit ($class, $current)
{
$limit = NULL; $limit = NULL;
switch($class) { switch($class)
{
case 'temperature': case 'temperature':
$limit = $current * 1.60; $limit = $current * 1.60;
break; break;
@@ -129,11 +135,12 @@ function sensor_limit ($class, $current) {
return $limit; return $limit;
} }
function check_valid_sensors($device, $class, $valid) { function check_valid_sensors($device, $class, $valid)
{
$sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; $sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql)) if ($query = mysql_query($sql))
{ {
while ($test = mysql_fetch_array($query)) while ($test = mysql_fetch_assoc($query))
{ {
$index = $test['sensor_index']; $index = $test['sensor_index'];
$type = $test['sensor_type']; $type = $test['sensor_type'];
@@ -181,7 +188,7 @@ function discover_link($local_interface_id, $protocol, $remote_interface_id, $re
} }
else else
{ {
$data = mysql_fetch_array(mysql_query("SELECT * FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id' $data = mysql_fetch_assoc(mysql_query("SELECT * FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id'
AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'")); AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'"));
if($data['remote_interface_id'] == $remote_interface_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version) if($data['remote_interface_id'] == $remote_interface_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version)
{ {
@@ -275,7 +282,6 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision =
else else
{ {
echo("."); echo(".");
# entry = mysql_fetch_assoc(mysql_query());
$query = "UPDATE `mempools` SET `mempool_descr` = '".$descr."', `entPhysicalIndex` = '".$entPhysicalIndex."'"; $query = "UPDATE `mempools` SET `mempool_descr` = '".$descr."', `entPhysicalIndex` = '".$entPhysicalIndex."'";
$query .= ", `hrDeviceIndex` = '$hrDeviceIndex' "; $query .= ", `hrDeviceIndex` = '$hrDeviceIndex' ";
$query .= "WHERE `device_id` = '".$device['device_id']."' AND `mempool_index` = '".$index."' AND `mempool_type` = '".$type."'"; $query .= "WHERE `device_id` = '".$device['device_id']."' AND `mempool_index` = '".$index."' AND `mempool_type` = '".$type."'";
@@ -302,7 +308,7 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
} }
else else
{ {
$toner_entry = mysql_fetch_array(mysql_query("SELECT * FROM `toner` WHERE device_id = '".$device['device_id']."' AND toner_type = '$type' AND `toner_index` = '$index'")); $toner_entry = mysql_fetch_assoc(mysql_query("SELECT * FROM `toner` WHERE device_id = '".$device['device_id']."' AND toner_type = '$type' AND `toner_index` = '$index'"));
if($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity']) if($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity'])
{ {
echo("."); echo(".");

View File

@@ -0,0 +1,31 @@
<?php
global $valid_sensor;
## IPMI
if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
{
echo("IPMI : ");
$ipmi['user'] = get_dev_attrib($device,'ipmi_username');
$ipmi['password'] = get_dev_attrib($device,'ipmi_password');
$results = shell_exec("ipmitool -H " . $ipmi['host'] . " -U " . $ipmi['user'] . " -P " . $ipmi['password'] . " sensor");
foreach (explode("\n",$results) as $sensor)
{
# BB +1.1V IOH | 1.089 | Volts | ok | na | 1.027 | 1.054 | 1.146 | 1.177 | na
list($desc,$current,$unit,$state,$low_nonrecoverable,$low_limit,$low_warn,$high_warn,$high_limit,$high_nonrecoverable) = explode('|',$sensor);
if (trim($current) != "na" && $ipmi_unit[trim($unit)])
{
discover_sensor($valid_sensor, $ipmi_unit[trim($unit)], $device, trim($desc), $index++, 'ipmi', trim($desc), '1', '1',
(trim($low_limit) == 'na' ? NULL : trim($low_limit)), (trim($low_warn) == 'na' ? NULL : trim($low_warn)),
(trim($high_warn) == 'na' ? NULL : trim($high_warn)), (trim($high_limit) == 'na' ? NULL : trim($high_limit)),
$current, 'ipmi');
}
}
echo("\n");
}
?>

View File

@@ -6,6 +6,7 @@ echo("Sensors: ");
include("includes/discovery/cisco-entity-sensor.inc.php"); include("includes/discovery/cisco-entity-sensor.inc.php");
include("includes/discovery/entity-sensor.inc.php"); include("includes/discovery/entity-sensor.inc.php");
include("includes/discovery/ipmi.inc.php");
include("includes/discovery/temperatures.inc.php"); include("includes/discovery/temperatures.inc.php");
include("includes/discovery/humidity.inc.php"); include("includes/discovery/humidity.inc.php");

View File

@@ -76,6 +76,19 @@ function write_dev_attrib($device_id, $attrib_type, $attrib_value)
return mysql_affected_rows(); return mysql_affected_rows();
} }
function get_dev_attrib($device, $attrib_type)
{
$sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = '$attrib_type'";
if ($row = mysql_fetch_assoc(mysql_query($sql)))
{
return $row['attrib_value'];
}
else
{
return NULL;
}
}
function shorthost($hostname, $len=16) function shorthost($hostname, $len=16)
{ {
$parts = explode(".", $hostname); $parts = explode(".", $hostname);
@@ -679,7 +692,7 @@ function isHexString($str)
} }
# Include all .inc.php files in $dir # Include all .inc.php files in $dir
function include_dir($dir, $regex) function include_dir($dir, $regex = "")
{ {
global $device, $config; global $device, $config;
if ( $regex == "") if ( $regex == "")

View File

@@ -1,6 +1,6 @@
<?php <?php
$query = "SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "'"; $query = "SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$current_data = mysql_query($query); $current_data = mysql_query($query);
while($dbcurrent = mysql_fetch_array($current_data)) { while($dbcurrent = mysql_fetch_array($current_data)) {
@@ -16,7 +16,7 @@ while($dbcurrent = mysql_fetch_array($current_data)) {
if (!is_file($currentrrd)) { if (!is_file($currentrrd)) {
`rrdtool create $currentrrd \ `rrdtool create $currentrrd \
--step 300 \ --step 300 \
DS:current:GAUGE:600:-273:1000 \ DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \

View File

@@ -1,9 +1,10 @@
<?php <?php
$query = "SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'"; $query = "SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$fan_data = mysql_query($query); $fan_data = mysql_query($query);
while ($fanspeed = mysql_fetch_array($fan_data)) {
while ($fanspeed = mysql_fetch_array($fan_data))
{
echo("Checking fan " . $fanspeed['sensor_descr'] . "... "); echo("Checking fan " . $fanspeed['sensor_descr'] . "... ");
$fan = snmp_get($device, $fanspeed['sensor_oid'], "-OUqnv", "SNMPv2-MIB"); $fan = snmp_get($device, $fanspeed['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
@@ -11,12 +12,13 @@ while ($fanspeed = mysql_fetch_array($fan_data)) {
if ($fanspeed['sensor_divisor']) { $fan = $fan / $fanspeed['sensor_divisor']; } if ($fanspeed['sensor_divisor']) { $fan = $fan / $fanspeed['sensor_divisor']; }
if ($fanspeed['sensor_multiplier']) { $fan = $fan * $fanspeed['sensor_multiplier']; } if ($fanspeed['sensor_multiplier']) { $fan = $fan * $fanspeed['sensor_multiplier']; }
$fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd"); $fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fanspeed-" . $fanspeed['sensor_descr'] . ".rrd");
if (!is_file($fanrrd)) { if (!is_file($fanrrd))
{
`rrdtool create $fanrrd \ `rrdtool create $fanrrd \
--step 300 \ --step 300 \
DS:fan:GAUGE:600:0:20000 \ DS:sensor:GAUGE:600:0:20000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \

View File

@@ -1,6 +1,6 @@
<?php <?php
$query = "SELECT * FROM `sensors` WHERE device_id = '" . $device['device_id'] . "' AND `sensor_class` = 'freq'"; $query = "SELECT * FROM `sensors` WHERE device_id = '" . $device['device_id'] . "' AND `sensor_class` = 'freq' AND poller_type='snmp'";
$sensor_data = mysql_query($query); $sensor_data = mysql_query($query);
while($sensor = mysql_fetch_array($sensor_data)) { while($sensor = mysql_fetch_array($sensor_data)) {
@@ -11,12 +11,12 @@ while($sensor = mysql_fetch_array($sensor_data)) {
if ($sensor['sensor_divisor']) { $freq = $freq / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $freq = $freq / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $freq = $freq * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $freq = $freq * $sensor['sensor_multiplier']; }
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("freq-" . $sensor['sensor_descr'] . ".rrd"); $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("frequency-" . $sensor['sensor_descr'] . ".rrd");
if (!is_file($rrd_file)) { if (!is_file($rrd_file)) {
`rrdtool create $rrd_file \ `rrdtool create $rrd_file \
--step 300 \ --step 300 \
DS:freq:GAUGE:600:-273:1000 \ DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \

View File

@@ -1,15 +1,12 @@
<?php <?php
$query = "SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "'"; $query = "SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$hum_data = mysql_query($query); $hum_data = mysql_query($query);
while($humidity = mysql_fetch_array($hum_data)) { while($humidity = mysql_fetch_array($hum_data)) {
echo("Checking humidity " . $humidity['sensor_descr'] . "... "); echo("Checking humidity " . $humidity['sensor_descr'] . "... ");
$hum_cmd = $config['snmpget'] . " -M ".$config['mibdir']. " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $humidity['sensor_oid'] . "|grep -v \"No Such Instance\""; $hum = snmp_get($device, $humidity['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
$hum = trim(str_replace("\"", "", shell_exec($hum_cmd)));
## fixme snmp_get()
if ($humidity['sensor_divisor']) { $hum = $hum / $humidity['sensor_divisor']; } if ($humidity['sensor_divisor']) { $hum = $hum / $humidity['sensor_divisor']; }
if ($humidity['sensor_multiplier']) { $hum = $hum / $humidity['sensor_multiplier']; } if ($humidity['sensor_multiplier']) { $hum = $hum / $humidity['sensor_multiplier']; }
@@ -19,7 +16,7 @@ while($humidity = mysql_fetch_array($hum_data)) {
if (!is_file($humrrd)) { if (!is_file($humrrd)) {
`rrdtool create $humrrd \ `rrdtool create $humrrd \
--step 300 \ --step 300 \
DS:humidity:GAUGE:600:-273:1000 \ DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \

View File

@@ -0,0 +1,52 @@
<?php
$query = "SELECT * FROM sensors WHERE device_id = '" . $device['device_id'] . "' AND poller_type='ipmi'";
$ipmi_data = mysql_query($query);
if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
{
$ipmi['user'] = get_dev_attrib($device,'ipmi_username');
$ipmi['password'] = get_dev_attrib($device,'ipmi_password');
echo("Fetching IPMI sensor data...");
$results = shell_exec("ipmitool -c -H " . $ipmi['host'] . " -U " . $ipmi['user'] . " -P " . $ipmi['password'] . " sdr");
echo(" done.\n");
foreach (explode("\n",$results) as $row)
{
list($desc,$value,$type,$status) = explode(',',$row);
$ipmi_sensor[$desc][$ipmi_unit[$type]] = $value;
}
while ($ipmisensors = mysql_fetch_array($ipmi_data))
{
echo("Updating IPMI sensor " . $ipmisensors['sensor_descr'] . "... ");
$sensor = $ipmi_sensor[$ipmisensors['sensor_descr']][$ipmisensors['sensor_class']];
$sensorrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename($ipmisensors['sensor_class'].'-'.$ipmisensors['sensor_type'].'-'.$ipmisensors['sensor_index'] . ".rrd");
if (!is_file($sensorrrd))
{
`rrdtool create $sensorrrd \
--step 300 \
DS:sensor:GAUGE:600:0:20000 \
RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \
RRA:AVERAGE:0.5:12:2400`;
}
echo($sensor . " \n"); # FIXME unit should follow?
rrdtool_update($sensorrrd,"N:$sensor");
## FIXME warnings in event & mail not done here yet!
mysql_query("UPDATE sensors SET sensor_current = '$sensor' WHERE poller_type='ipmi' AND sensor_class= AND sensor_id = '" . $ipmisensors['sensor_id'] . "'");
}
unset($ipmi_sensor);
}
?>

View File

@@ -1,6 +1,6 @@
<?php <?php
$query = "SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'"; $query = "SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$temp_data = mysql_query($query); $temp_data = mysql_query($query);
while($temperature = mysql_fetch_array($temp_data)) { while($temperature = mysql_fetch_array($temp_data)) {
@@ -9,6 +9,7 @@ while($temperature = mysql_fetch_array($temp_data)) {
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
{ {
if ($debug) echo("Attempt $i "); if ($debug) echo("Attempt $i ");
#FIXME snmp_get
$temp_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['sensor_oid'] . "|grep -v \"No Such Instance\""; $temp_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['sensor_oid'] . "|grep -v \"No Such Instance\"";
$temp = trim(str_replace("\"", "", shell_exec($temp_cmd))); $temp = trim(str_replace("\"", "", shell_exec($temp_cmd)));
@@ -19,15 +20,15 @@ while($temperature = mysql_fetch_array($temp_data)) {
if ($temperature['sensor_divisor']) { $temp = $temp / $temperature['sensor_divisor']; } if ($temperature['sensor_divisor']) { $temp = $temp / $temperature['sensor_divisor']; }
if ($temperature['sensor_multiplier']) { $temp = $temp * $temperature['sensor_multiplier']; } if ($temperature['sensor_multiplier']) { $temp = $temp * $temperature['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['sensor_descr'] . ".rrd"); $old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temperature-" . $temperature['sensor_descr'] . ".rrd");
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . safename($temperature['sensor_type']."-".$temperature['sensor_index']) . ".rrd"; $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/temperature-" . safename($temperature['sensor_type']."-".$temperature['sensor_index']) . ".rrd";
if(is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); } if(is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
if (!is_file($rrd_file)) { if (!is_file($rrd_file)) {
`rrdtool create $rrd_file \ `rrdtool create $rrd_file \
--step 300 \ --step 300 \
DS:temp:GAUGE:600:-273:1000 \ DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:24:775 \

View File

@@ -1,6 +1,6 @@
<?php <?php
$query = "SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'"; $query = "SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$volt_data = mysql_query($query); $volt_data = mysql_query($query);
while($sensor = mysql_fetch_array($volt_data)) { while($sensor = mysql_fetch_array($volt_data)) {
@@ -11,15 +11,15 @@ while($sensor = mysql_fetch_array($volt_data)) {
if ($sensor['sensor_divisor']) { $volt = $volt / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $volt = $volt / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $volt = $volt * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $volt = $volt * $sensor['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("volt-" . $sensor['sensor_descr'] . ".rrd"); $old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("voltage-" . $sensor['sensor_descr'] . ".rrd");
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/volt-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd"; $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/voltage-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
if(is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); } if(is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
if (!is_file($rrd_file)) { if (!is_file($rrd_file)) {
`rrdtool create $rrd_file \ `rrdtool create $rrd_file \
--step 300 \ --step 300 \
DS:volt:GAUGE:600:-273:1000 \ DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:1200 \ RRA:AVERAGE:0.5:1:1200 \
RRA:MIN:0.5:12:2400 \ RRA:MIN:0.5:12:2400 \
RRA:MAX:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \

View File

@@ -6,57 +6,68 @@
#$config['snmp']['timeout'] = 300; # timeout in ms #$config['snmp']['timeout'] = 300; # timeout in ms
#$config['snmp']['retries'] = 6; # how many times to retry the query #$config['snmp']['retries'] = 6; # how many times to retry the query
function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir = NULL) { function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir = NULL)
global $debug,$config,$runtime_stats,$mibs_loaded; {
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } global $debug,$config,$runtime_stats,$mibs_loaded;
if (is_numeric($device['retries'])) { $timeout = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $timeout = $config['snmp']['retries']; }
if ($config['snmp']['internal'] == true) {
if ($mib && $mibdir && !$mibs_loaded[$mib]) if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
{ if (is_numeric($device['retries'])) { $timeout = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $timeout = $config['snmp']['retries']; }
@snmp_read_mib($mibdir."/".$mib); if ($config['snmp']['internal'] == true)
$mibs_loaded[$mib] = TRUE; {
} if ($mib && $mibdir && !$mibs_loaded[$mib])
snmp_set_quick_print(1); {
$oids = explode(" ",trim($oids)); @snmp_read_mib($mibdir."/".$mib);
// s->ms - php snmp extension requires the timeout in microseconds. $mibs_loaded[$mib] = TRUE;
if(isset($timeout)) { $timeout = $timeout*1000*1000; } }
foreach($oids as $oid) {
if ($device['snmpver'] == "v2c") {
$data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
} elseif ( $device['snmpver'] == "v1") {
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
list($oid, $index) = explode(".", $oid); snmp_set_quick_print(1);
if ($data) { $array[$index][$oid] = $data; } $oids = explode(" ",trim($oids));
else { $array[$index][$oid] = null; } // s->ms - php snmp extension requires the timeout in microseconds.
} if(isset($timeout)) { $timeout = $timeout*1000*1000; }
} else { foreach($oids as $oid)
$cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; {
if ($options) { $cmd .= " " . $options; } if ($device['snmpver'] == "v2c")
if ($mib) { $cmd .= " -m " . $mib; } {
if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
elseif ( $device['snmpver'] == "v1")
{
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
}
if (isset($timeout)) { $cmd .= " -t " . $timeout; } list($oid, $index) = explode(".", $oid);
if (isset($retries)) { $cmd .= " -r " . $retries; } if ($data) { $array[$index][$oid] = $data; }
else { $array[$index][$oid] = null; }
}
}
else
{
$cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " ";
if ($options) { $cmd .= " " . $options; }
if ($mib) { $cmd .= " -m " . $mib; }
if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; }
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oids; if (isset($timeout)) { $cmd .= " -t " . $timeout; }
if (!$debug) { $cmd .= " 2>/dev/null"; } if (isset($retries)) { $cmd .= " -r " . $retries; }
if ($debug) { echo("$cmd\n"); }
$data = trim(shell_exec($cmd)); $cmd .= " ".$device['hostname'].":".$device['port']." ".$oids;
$runtime_stats['snmpget']++; if (!$debug) { $cmd .= " 2>/dev/null"; }
if ($debug) { echo("$data\n"); } if ($debug) { echo("$cmd\n"); }
foreach(explode("\n", $data) as $entry) { $data = trim(shell_exec($cmd));
list($oid,$value) = explode("=", $entry); $runtime_stats['snmpget']++;
$oid = trim($oid); $value = trim($value); if ($debug) { echo("$data\n"); }
list($oid, $index) = explode(".", $oid); foreach(explode("\n", $data) as $entry)
if (!strstr($value, "at this OID") && isset($oid) && isset($index)) { {
$array[$index][$oid] = $value; list($oid,$value) = explode("=", $entry);
} $oid = trim($oid); $value = trim($value);
} list($oid, $index) = explode(".", $oid);
} if (!strstr($value, "at this OID") && isset($oid) && isset($index))
return $array; {
$array[$index][$oid] = $value;
}
}
}
return $array;
} }
function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) { function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) {

View File

@@ -393,6 +393,11 @@ $config['os'][$os]['text'] = "Delta UPS";
$config['os'][$os]['type'] = "power"; $config['os'][$os]['type'] = "power";
$config['os'][$os]['icon'] = "delta"; $config['os'][$os]['icon'] = "delta";
$os = "engenius";
$config['os'][$os]['type'] = "network";
$config['os'][$os]['text'] = "EnGenius Access Point";
$config['os'][$os]['icon'] = "engenius";
$os = "airport"; $os = "airport";
$config['os'][$os]['type'] = "network"; $config['os'][$os]['type'] = "network";
$config['os'][$os]['text'] = "Apple AirPort"; $config['os'][$os]['text'] = "Apple AirPort";
@@ -818,5 +823,11 @@ $config['twomonth'] = time() - (2 * 31 * 24 * 60 * 60);
$config['threemonth'] = time() - (3 * 31 * 24 * 60 * 60); $config['threemonth'] = time() - (3 * 31 * 24 * 60 * 60);
$config['year'] = time() - (365 * 24 * 60 * 60); $config['year'] = time() - (365 * 24 * 60 * 60);
# IPMI sensor type mappings
$ipmi_unit['Volts'] = 'voltage';
$ipmi_unit['degrees C'] = 'temperature';
$ipmi_unit['RPM'] = 'fanspeed';
$ipmi_unit['Watts'] = '';
$ipmi_unit['discrete'] = '';
?> ?>

View File

@@ -55,10 +55,10 @@ if (isset($options['d'])) {
ini_set('error_reporting', 1); ini_set('error_reporting', 1);
} else { } else {
$debug = FALSE; $debug = FALSE;
ini_set('display_errors', 0); # ini_set('display_errors', 0);
ini_set('display_startup_errors', 0); ini_set('display_startup_errors', 0);
ini_set('log_errors', 0); ini_set('log_errors', 0);
ini_set('error_reporting', 0); # ini_set('error_reporting', 0);
} }
@@ -193,6 +193,7 @@ while ($device = mysql_fetch_assoc($device_query))
$sysLocation = str_replace("\"","", $sysLocation); $sysLocation = str_replace("\"","", $sysLocation);
include("includes/polling/ipmi.inc.php");
include("includes/polling/temperatures.inc.php"); include("includes/polling/temperatures.inc.php");
include("includes/polling/humidity.inc.php"); include("includes/polling/humidity.inc.php");
include("includes/polling/fanspeeds.inc.php"); include("includes/polling/fanspeeds.inc.php");