current support (STILL NEEDS AN ICON, YES), discovery only on APC devices at the moment

git-svn-id: http://www.observium.org/svn/observer/trunk@1125 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-06-09 20:03:16 +00:00
parent 25e6384404
commit b20d382a8c
10 changed files with 179 additions and 6 deletions

View File

@@ -8,3 +8,4 @@ ALTER TABLE `mempools` CHANGE `mempool_used` `mempool_used` BIGINT( 16 ) NOT NUL
ALTER TABLE `ports` ADD `port_descr_type` VARCHAR( 32 ) NULL DEFAULT NULL AFTER `device_id` ,ADD `port_descr_descr` VARCHAR( 64 ) NULL DEFAULT NULL AFTER `port_descr_type` ,ADD `port_descr_circuit` VARCHAR( 64 ) NULL DEFAULT NULL AFTER `port_descr_descr` ,ADD `port_descr_speed` VARCHAR( 32 ) NULL DEFAULT NULL AFTER `port_descr_circuit` ,ADD `port_descr_notes` VARCHAR( 128 ) NULL DEFAULT NULL AFTER `port_descr_speed`;
CREATE TABLE `frequency` ( `freq_id` int(11) NOT NULL auto_increment, `device_id` int(11) NOT NULL default '0', `freq_oid` varchar(64) NOT NULL, `freq_index` varchar(8) NOT NULL, `freq_type` varchar(32) NOT NULL, `freq_descr` varchar(32) NOT NULL default '', `freq_precision` int(11) NOT NULL default '1', `freq_current` float default NULL, `freq_limit` float default NULL, `freq_limit_low` float default NULL, PRIMARY KEY (`freq_id`), KEY `freq_host` (`device_id`)) ENGINE=MyISAM AUTO_INCREMENT=189 DEFAULT CHARSET=latin1;
ALTER TABLE `temperature` CHANGE `temp_index` `temp_index` int(11) NOT NULL;
CREATE TABLE `current` ( `current_id` int(11) NOT NULL auto_increment, `device_id` int(11) NOT NULL default '0', `current_oid` varchar(64) NOT NULL, `current_index` varchar(8) NOT NULL, `current_type` varchar(32) NOT NULL, `current_descr` varchar(32) NOT NULL default '', `current_precision` int(11) NOT NULL default '1', `current_current` float default NULL, `current_limit` float default NULL, `current_limit_warn` float default NULL, `current_limit_low` float default NULL, PRIMARY KEY (`current_id`), KEY `current_host` (`device_id`)) ENGINE=MyISAM AUTO_INCREMENT=189 DEFAULT CHARSET=latin1;

View File

@@ -100,6 +100,7 @@ while ($device = mysql_fetch_array($device_query))
include("includes/discovery/temperatures.inc.php");
include("includes/discovery/voltages.inc.php");
include("includes/discovery/frequencies.inc.php");
include("includes/discovery/current.inc.php");
include("includes/discovery/fanspeeds.inc.php");
include("includes/discovery/storage.inc.php");
include("includes/discovery/hr-device.inc.php");

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

View File

@@ -184,6 +184,7 @@ echo('<li><a href="ports/?status=0"><img src="images/16/link_error.png" border="
<li><a href="health/fanspeeds/"><img src="images/icons/fans.png" border="0" align="absmiddle" /> Fans</a></li>
<li><a href="health/voltages/"><img src="images/icons/voltages.png" border="0" align="absmiddle" /> Voltages</a></li>
<li><a href="health/frequencies/"><img src="images/icons/frequencies.png" border="0" align="absmiddle" /> Frequencies</a></li>
<li><a href="health/current/"><img src="images/icons/current.png" border="0" align="absmiddle" /> Current</a></li>
</ul>
</td></tr></table>
<!--[if lte IE 6]></a><![endif]-->

View File

@@ -1,6 +1,6 @@
<?php
$datas = array('Processors','Memory','Storage','Temperatures', 'Voltages', 'Fanspeeds', 'Frequencies');
$datas = array('Processors','Memory','Storage','Temperatures', 'Voltages', 'Fanspeeds', 'Frequencies', 'Current');
if(!$_GET['opta']) { $_GET['opta'] = "processors"; }
@@ -31,6 +31,7 @@ switch ($_GET['opta'])
case 'voltages':
case 'fanspeeds':
case 'frequencies':
case 'current':
include('pages/health/'.$_GET['opta'].'.inc.php');
break;
default:

View File

@@ -0,0 +1,63 @@
<?php
if($_SESSION['userlevel'] >= '5') {
$sql = "SELECT * FROM `current` AS V, `devices` AS D WHERE V.device_id = D.device_id ORDER BY D.hostname, V.current_descr";
} else {
$sql = "SELECT * FROM `current` AS V, `devices` AS D, devices_perms as P WHERE V.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, V.current_descr";
}
$query = mysql_query($sql);
echo('<table cellspacing="0" cellpadding="2" width="100%">');
echo('<tr class=tablehead>
<th width="280">Device</th>
<th width="180">Sensor</th>
<th></th>
<th></th>
<th width="100">Current</th>
<th width="100">Warning</th>
<th width="100">Limit</th>
<th>Notes</th>
</tr>');
$row = 1;
while($current = mysql_fetch_array($query))
{
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$weekly_current = "graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$week&amp;to=$now&amp;width=500&amp;height=150";
$current_popup = "<a onmouseover=\"return overlib('<img src=\'$weekly_current\'>', LEFT);\" onmouseout=\"return nd();\">
" . $current['current_descr'] . "</a>";
if($current['current_current'] >= $current['current_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
$current_day = "graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$day&amp;to=$now&amp;width=300&amp;height=100";
$current_week = "graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$week&amp;to=$now&amp;width=300&amp;height=100";
$current_month = "graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$month&amp;to=$now&amp;width=300&amp;height=100";
$current_year = "graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$year&amp;to=$now&amp;width=300&amp;height=100";
$current_minigraph = "<img src='graph.php?id=" . $current['current_id'] . "&amp;type=current&amp;from=$day&amp;to=$now&amp;width=100&amp;height=20'";
$current_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$current['hostname']." - ".$current['current_descr'];
$current_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$current_day\'><img src=\'$current_week\'><img src=\'$current_month\'><img src=\'$current_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
echo("<tr bgcolor=$row_colour>
<td class=list-bold>" . generatedevicelink($current) . "</td>
<td>$current_popup</td>
<td>$current_minigraph</td>
<td width=100>$alert</td>
<td style='text-align: center; font-weight: bold;'>" . $current['current_current'] . "A</td>
<td style='text-align: center'>" . $current['current_limit_warn'] . "A</td>
<td style='text-align: center'>" . $current['current_limit'] . "A</td>
<td>" . (isset($current['current_notes']) ? $current['current_notes'] : '') . "</td>
</tr>\n");
$row++;
}
echo("</table>");
?>

View File

@@ -0,0 +1,68 @@
<?php
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
$snmpver = $device['snmpver'];
$port = $device['port'];
echo("Current : ");
## APC PDU
if ($device['os'] == "apc")
{
$oids = snmp_walk($device, ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2", "-OsqnU", "");
if ($debug) { echo($oids."\n"); }
$oids = trim($oids);
if ($oids) echo("APC ");
$type = "apc";
$precision = "10";
foreach(explode("\n", $oids) as $data)
{
$data = trim($data);
if ($data)
{
list($oid,$kind) = explode(" ", $data);
$split_oid = explode('.',$oid);
$index = $split_oid[count($split_oid)-1];
$current_oid = "1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.".$index;
$phase_oid = "1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.".$index;
$limit_oid = "1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.".$index;
$lowlimit_oid = "1.3.6.1.4.1.318.1.1.12.2.2.1.1.2.".$index;
$warnlimit_oid = "1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.".$index;
$phase = snmp_get($device, $phase_oid, "-Oqv", "");
$current = snmp_get($device, $current_oid, "-Oqv", "") / $precision;
$limit = snmp_get($device, $limit_oid, "-Oqv", ""); # No / $precision here! Nice, APC!
$lowlimit = snmp_get($device, $lowlimit_oid, "-Oqv", ""); # No / $precision here! Nice, APC!
$warnlimit = snmp_get($device, $warnlimit_oid, "-Oqv", ""); # No / $precision here! Nice, APC!
$descr = "Phase $phase";
echo discover_current($device, $current_oid, $index, $type, $descr, $precision, $lowlimit, $warnlimit, $limit, $current);
$current_exists[$type][$index] = 1;
}
}
}
## Delete removed sensors
if($debug) { print_r($current_exists); }
$sql = "SELECT * FROM current WHERE device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test_current = mysql_fetch_array($query))
{
$index = $test_current['current_index'];
$type = $test_current['current_type'];
if($debug) { echo("$type -> $index\n"); }
if(!$current_exists[$type][$index]) {
echo("-");
mysql_query("DELETE FROM `current` WHERE current_id = '" . $test_current['current_id'] . "'");
}
}
}
unset($current_exists); echo("\n");
?>

View File

@@ -276,6 +276,42 @@ function discover_freq($device, $oid, $index, $type, $descr, $precision = 1, $lo
return $return;
}
function discover_current($device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
{
global $config, $debug;
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
if(!$low_limit)
{
$low_limit = $config['limit']['current'];
}
if (mysql_result(mysql_query("SELECT count(current_id) FROM `current` WHERE device_id = '".$device['device_id']."' AND current_type = '$type' AND `current_index` = '$index'"),0) == '0')
{
$query = "INSERT INTO current (`device_id`, `current_oid`, `current_index`, `current_type`, `current_descr`, `current_precision`, `current_limit`, `current_limit_warn`, `current_limit_low`, `current_current`) ";
$query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$current')";
mysql_query($query);
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
echo("+");
}
else
{
$current_entry = mysql_fetch_array(mysql_query("SELECT * FROM `current` WHERE device_id = '".$device['device_id']."' AND current_type = '$type' AND `current_index` = '$index'"));
if($oid == $current_entry['current_oid'] && $descr == $current_entry['current_descr'] && $precision == $current_entry['current_precision'])
{
echo(".");
}
else
{
mysql_query("UPDATE current SET `current_descr` = '$descr', `current_oid` = '$oid', `current_precision` = '$precision' WHERE `device_id` = '" . $device['device_id'] . "' AND current_type = '$type' AND `current_index` = '$index' ");
echo("U");
if($debug) { echo("$query ". mysql_affected_rows() . " updated"); }
}
}
return $return;
}
function discover_toner($device, $oid, $index, $type, $descr, $capacity = NULL, $current = NULL)
{
global $config, $debug;

View File

@@ -165,6 +165,6 @@ if ($query = mysql_query($sql))
}
}
unset($fan_exists); echo("\n");
unset($volt_exists); echo("\n");
?>

View File

@@ -1,9 +1,11 @@
<?php
#list($hardware, $features, $version) = explode(",", str_replace(", ", ",", $sysDescr));
#list($version) = explode("(", $version);
preg_match("/MN:(AP\d+) /",$sysDescr,$matches);
$hardware = str_replace('MN:','',$matches[0]);
$serial = trim(snmp_get($device, "1.3.6.1.4.1.318.1.1.12.1.6.0", "-OQv", "", ""),'"');
$hardware = trim(snmp_get($device, "1.3.6.1.4.1.318.1.1.12.1.5.0", "-OQv", "", ""),'"');
$hardware .= ' ' . trim(snmp_get($device, "1.3.6.1.4.1.318.1.1.12.1.2.0", "-OQv", "", ""),'"');
$version = trim(snmp_get($device, "1.3.6.1.4.1.318.1.1.12.1.3.0", "-OQv", "", ""),'"');
?>