git-svn-id: http://www.observium.org/svn/observer/trunk@2337 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-16 20:33:51 +00:00
parent fc40257da9
commit 59521d8778
11 changed files with 88 additions and 211 deletions

View File

@@ -11,7 +11,20 @@ function poll_sensor($device, $class, $unit)
{ {
echo("Checking $class " . $sensor['sensor_descr'] . "... "); echo("Checking $class " . $sensor['sensor_descr'] . "... ");
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB"); if($class == "temperature")
{
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
{
if ($debug) echo("Attempt $i ");
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
$sensor_value = trim(str_replace("\"", "", $sensor_value));
if ($sensor_value != 9999) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
sleep(1); # Give the TME some time to reset
}
} else {
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
}
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; } if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; } if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }

View File

@@ -88,21 +88,18 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding']))
$this_port[$oid] = $this_port[$oid] / 10; $this_port[$oid] = $this_port[$oid] / 10;
} }
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = '".$port['interface_id']."'"),0) == "0") if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = ?", array($port['interface_id'])) == "0")
{ {
mysql_query("INSERT INTO `ports_adsl` (`interface_id`) VALUES ('".$port['interface_id']."')"); dbInsert(array('interface_id' => $port['interface_id']), 'ports_adsl');
} }
$mysql_update = "UPDATE `ports_adsl` SET `port_adsl_updated` = NOW()"; $port['adsl_update'] = array('port_adsl_updated' => array('NOW()'));
foreach ($adsl_db_oids as $oid) foreach ($adsl_db_oids as $oid)
{ {
$data = str_replace("\"", "", $this_port[$oid]); $data = str_replace("\"", "", $this_port[$oid]); ## FIXME - do we need this?
$mysql_update .= ",`".$oid."` = '".$data."'"; $port['adsl_update'][$oid] = $data;
} }
$mysql_update .= "WHERE `interface_id` = '".$port['interface_id']."'"; dbUpdate($port['adsl_update'], 'ports_adsl', '`interface_id` = ?', array($port['interface_id']));
mysql_query($mysql_update);
if ($debug) { echo($mysql_update); echo(mysql_affected_rows()); echo(mysql_error()); }
$rrdupdate = "N"; $rrdupdate = "N";
foreach ($adsl_oids as $oid) foreach ($adsl_oids as $oid)
@@ -117,7 +114,7 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding']))
if (!is_file($rrdfile)) { rrdtool_create ($rrdfile, $rrd_create); } if (!is_file($rrdfile)) { rrdtool_create ($rrdfile, $rrd_create); }
rrdtool_update ($rrdfile, $rrdupdate); rrdtool_update ($rrdfile, $rrdupdate);
echo("ADSL "); echo("ADSL (".$this_port['adslLineCoding']."/".formatRates($this_port['adslAtucChanCurrTxRate'])."/".formatRates($this_port['adslAturChanCurrTxRate']).")");
} }
?> ?>

View File

@@ -73,24 +73,6 @@ if ($device['adsl_count'] > "0")
$port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB"); $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB");
} }
## Alcatel Detailed Statistics ## FIXME make this disableable
if($device['os'] == "aos") {
$stat_oids = array('alcetherStatsCRCAlignErrors', 'alcetherStatsRxUndersizePkts','alcetherStatsTxUndersizePkts', 'alcetherStatsTxOversizePkts','alcetherStatsRxJabbers', 'alcetherStatsRxCollisions', 'alcetherStatsTxCollisions',
'alcetherStatsPkts64Octets','alcetherStatsPkts65to127Octets', 'alcetherStatsPkts128to255Octets','alcetherStatsPkts256to511Octets','alcetherStatsPkts512to1023Octets','alcetherStatsPkts1024to1518Octets',
'gigaEtherStatsPkts1519to4095Octets','gigaEtherStatsPkts4096to9215Octets','alcetherStatsPkts1519to2047Octets','alcetherStatsPkts2048to4095Octets','alcetherStatsPkts4096Octets','alcetherStatsRxGiantPkts',
'alcetherStatsRxDribbleNibblePkts','alcetherStatsRxLongEventPkts','alcetherStatsRxVlanTagPkts','alcetherStatsRxControlPkts','alcetherStatsRxLenChkErrPkts','alcetherStatsRxCodeErrPkts','alcetherStatsRxDvEventPkts',
'alcetherStatsRxPrevPktDropped','alcetherStatsTx64Octets','alcetherStatsTx65to127Octets','alcetherStatsTx128to255Octets','alcetherStatsTx256to511Octets','alcetherStatsTx512to1023Octets',
'alcetherStatsTx1024to1518Octets','alcetherStatsTx1519to2047Octets','alcetherStatsTx2048to4095Octets','alcetherStatsTx4096Octets','alcetherStatsTxRetryCount','alcetherStatsTxVlanTagPkts',
'alcetherStatsTxControlPkts','alcetherStatsTxLatePkts','alcetherStatsTxTotalBytesOnWire','alcetherStatsTxLenChkErrPkts','alcetherStatsTxExcDeferPkts');
foreach($stat_oids as $oid)
{
$port_stats = snmpwalk_cache_oid($device, "alcetherStatsEntry", $port_stats, "ALCATEL-IND1-PORT-MIB");
}
}
echo("\n");
/// FIXME This probably needs re-enabled. We need to clear these things when they get unset, too. /// FIXME This probably needs re-enabled. We need to clear these things when they get unset, too.
#foreach ($etherlike_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "EtherLike-MIB"); } #foreach ($etherlike_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "EtherLike-MIB"); }
#foreach ($cisco_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "OLD-CISCO-INTERFACES-MIB"); } #foreach ($cisco_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "OLD-CISCO-INTERFACES-MIB"); }
@@ -115,24 +97,45 @@ $polled = time();
if ($debug) { print_r($port_stats); } if ($debug) { print_r($port_stats); }
### Build array of ports in the database
## FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
$ports_db = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id']));
foreach ($ports_db as $port) { $ports[$port['ifIndex']] = $port; }
/// New interface detection /// New interface detection
///// FIXME foreach ($port_stats as $ifIndex => $port)
{
if (!is_array($ports[$port['ifIndex']]))
{
$interface_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
$ports[$port['ifIndex']] = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($interface_id));
mysql_error();
echo("Adding: ".$port['ifName']."(".$ifIndex.")(".$ports[$port['ifIndex']]['interface_id'].")");
#print_r($ports);
} elseif ($ports[$ifIndex]['deleted'] == "1") {
dbUpdate(array('deleted' => '0'), 'ports', '`interface_id` = ?', array($ports[$ifIndex]['interface_id']));
$ports[$ifIndex]['deleted'] = "0";
}
}
/// End New interface detection /// End New interface detection
echo("\n");
/// Loop ports in the DB and update where necessary /// Loop ports in the DB and update where necessary
$port_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = 0"); foreach ($ports as $port)
while ($port = mysql_fetch_assoc($port_query))
{ {
echo("Port " . $port['ifDescr'] . " "); echo ("Port " . $port['ifDescr'] . "(".$port['ifIndex'].") ");
if ($port_stats[$port['ifIndex']] && $port['disabled'] != "1") if ($port_stats[$port['ifIndex']] && $port['disabled'] != "1")
{ // Check to make sure Port data is cached. { // Check to make sure Port data is cached.
$this_port = &$port_stats[$port['ifIndex']]; $this_port = &$port_stats[$port['ifIndex']];
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; } if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; }
$polled_period = $polled - $port['poll_time']; $polled_period = $polled - $port['poll_time'];
$update .= "`poll_time` = '".$polled."'"; $port['update'] = array();
$update .= ", `poll_prev` = '".$port['poll_time']."'"; $port['update']['poll_time'] = $polled;
$update .= ", `poll_period` = '".$polled_period."'"; $port['update']['poll_prev'] = $port['poll_time'];
$port['update']['poll_period'] = $polled_period;
### Copy ifHC[In|Out]Octets values to non-HC if they exist ### Copy ifHC[In|Out]Octets values to non-HC if they exist
if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets'])) if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets']))
@@ -144,7 +147,7 @@ while ($port = mysql_fetch_assoc($port_query))
### rewrite the ifPhysAddress ### rewrite the ifPhysAddress
if(strpos($this_port['ifPhysAddress'], ":")) if (strpos($this_port['ifPhysAddress'], ":"))
{ {
list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $this_port['ifPhysAddress']); list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $this_port['ifPhysAddress']);
$ah_a = zeropad($a_a); $ah_a = zeropad($a_a);
@@ -185,12 +188,12 @@ while ($port = mysql_fetch_assoc($port_query))
{ {
if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid]))
{ {
$update .= ", `$oid` = NULL"; $port['update'][$oid] = array(NULL);
log_event($oid . ": ".$port[$oid]." -> NULL", $device, 'interface', $port['interface_id']); log_event($oid . ": ".$port[$oid]." -> NULL", $device, 'interface', $port['interface_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); } if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
} elseif ($port[$oid] != $this_port[$oid]) { } elseif ($port[$oid] != $this_port[$oid]) {
$update .= ", `$oid` = '".mres($this_port[$oid])."'"; $port['update'][$oid] = $this_port[$oid];
log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device, 'interface', $port['interface_id']); log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device, 'interface', $port['interface_id']);
if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); } if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
} }
} }
@@ -207,7 +210,7 @@ while ($port = mysql_fetch_assoc($port_query))
$attrib_key = "port_descr_".$attrib; $attrib_key = "port_descr_".$attrib;
if ($port_ifAlias[$attrib] != $port[$attrib_key]) if ($port_ifAlias[$attrib] != $port[$attrib_key])
{ {
$update .= ", `".$attrib_key."` = '".$port_ifAlias[$attrib]."'"; $port['update'][$attrib_key] = $port_ifAlias[$attrib];
log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device, 'interface', $port['interface_id']); log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device, 'interface', $port['interface_id']);
} }
} }
@@ -218,20 +221,23 @@ while ($port = mysql_fetch_assoc($port_query))
/// Update IF-MIB metrics /// Update IF-MIB metrics
foreach ($stat_oids_db as $oid) foreach ($stat_oids_db as $oid)
{ {
$update .= ", `$oid` = '".$this_port[$oid]."'"; $port['update'][$oid] = $this_port[$oid];
$update .= ", `".$oid."_prev` = '".$port[$oid]."'"; $port['update'][$oid.'_prev'] = $port[$oid];
$oid_prev = $oid . "_prev"; $oid_prev = $oid . "_prev";
if ($port[$oid]) if ($port[$oid])
{ {
$oid_diff = $this_port[$oid] - $port[$oid]; $oid_diff = $this_port[$oid] - $port[$oid];
$oid_rate = $oid_diff / $polled_period; $oid_rate = $oid_diff / $polled_period;
if ($oid_rate < 0) { $oid_rate = "0"; } if ($oid_rate < 0) { $oid_rate = "0"; }
$update .= ", `".$oid."_rate` = '".$oid_rate."'"; $port['update'][$oid.'_rate'] = $oid_rate;
$update .= ", `".$oid."_delta` = '".$oid_diff."'"; $port['update'][$oid.'_delta'] = $oid_diff;
if ($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); } if ($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); }
} }
} }
echo('bits('.formatRates($port['update']['ifInOctets_rate']).'/'.formatRates($port['update']['ifOutOctets_rate']).')');
echo('pkts('.format_si($port['update']['ifInUcastPkts_rate']).'pps/'.format_si($port['update']['ifOutUcastPkts_rate']).'pps)');
/// Update RRDs /// Update RRDs
$rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd"); $rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd");
if (!is_file($rrdfile)) if (!is_file($rrdfile))
@@ -287,7 +293,7 @@ while ($port = mysql_fetch_assoc($port_query))
{ // Loop the OIDs { // Loop the OIDs
if ($this_port[$oid] != $port[$oid]) if ($this_port[$oid] != $port[$oid])
{ // If data has changed, build a query { // If data has changed, build a query
$update .= ", `$oid` = '".mres($this_port[$oid])."'"; $port['update'][$oid] = $this_port[$oid];
echo("PAgP "); echo("PAgP ");
log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']); log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']);
} }
@@ -309,16 +315,13 @@ while ($port = mysql_fetch_assoc($port_query))
// Update MySQL // Update MySQL
if ($update) if (count($port['update']))
{ {
$update_query = "UPDATE `ports` SET ".$update." WHERE `interface_id` = '" . $port['interface_id'] . "'"; $updated = dbUpdate($port['update'], 'ports', '`interface_id` = ?', array($port['interface_id']));
@mysql_query($update_query); if($debug) { echo("$updated updated"); }
if ($debug) {echo("\nMYSQL : [ $update_query ]"); }
} }
// End Update MySQL // End Update MySQL
unset($update_query); unset($update);
// Send alerts for interface flaps. // Send alerts for interface flaps.
if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0) if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0)
{ {
@@ -342,7 +345,7 @@ while ($port = mysql_fetch_assoc($port_query))
elseif ($port['disabled'] != "1") elseif ($port['disabled'] != "1")
{ {
echo("Port Deleted"); // Port missing from SNMP cache. echo("Port Deleted"); // Port missing from SNMP cache.
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$this_port['ifIndex']."'"); dbUpdate(array('deleted' => '1'), 'ports', '`device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $port['ifIndex']));
} else { } else {
echo("Port Disabled."); echo("Port Disabled.");
} }

View File

@@ -1,8 +1,6 @@
<?php <?php
$query = "SELECT * FROM processors WHERE device_id = '" . $device['device_id'] . "'"; foreach (dbFetchRows("SELECT * FROM processors WHERE device_id = ?", array($device['device_id'])) as $processor)
$proc_data = mysql_query($query);
while ($processor = mysql_fetch_assoc($proc_data))
{ {
echo("Processor " . $processor['processor_descr'] . "... "); echo("Processor " . $processor['processor_descr'] . "... ");
@@ -35,8 +33,7 @@ while ($processor = mysql_fetch_assoc($proc_data))
echo($proc . "%\n"); echo($proc . "%\n");
rrdtool_update($procrrd,"N:$proc"); rrdtool_update($procrrd,"N:$proc");
dbUpdate(array('processor_usage' => $proc), 'processors', '`processor_id` = ?', array($processor['processor_id']));
mysql_query("UPDATE `processors` SET `processor_usage` = '$proc' WHERE `processor_id` = '".$processor['processor_id']."'");
} }
?> ?>

View File

@@ -5,12 +5,13 @@ poll_sensor($device,'frequency', 'Hz');
poll_sensor($device,'fanspeed', 'rpm'); poll_sensor($device,'fanspeed', 'rpm');
poll_sensor($device,'humidity', '%'); poll_sensor($device,'humidity', '%');
poll_sensor($device,'power', 'W'); poll_sensor($device,'power', 'W');
#poll_sensor($device,'voltage', 'V'); poll_sensor($device,'voltage', 'V');
poll_sensor($device,'temperature', 'C');
# FIXME voltages have other filenames # FIXME voltages have other filenames
include('includes/polling/voltages.inc.php'); #include('includes/polling/voltages.inc.php');
# FIXME also convert temperature, but there's some special code in there? # FIXME also convert temperature, but there's some special code in there?
include('includes/polling/temperatures.inc.php'); #include('includes/polling/temperatures.inc.php');
?> ?>

View File

@@ -2,11 +2,7 @@
$storage_cache = array(); $storage_cache = array();
#echo("Storage: "); foreach (dbFetchRows("SELECT * FROM storage WHERE device_id = ?", array($device['device_id'])) as $storage)
$query = "SELECT * FROM storage WHERE device_id = '" . $device['device_id'] . "'";
$storage_data = mysql_query($query);
while ($storage = mysql_fetch_assoc($storage_data))
{ {
echo("Storage ".$storage['storage_descr'] . ": "); echo("Storage ".$storage['storage_descr'] . ": ");
@@ -54,16 +50,12 @@ while ($storage = mysql_fetch_assoc($storage_data))
rrdtool_update($storage_rrd,"N:".$storage['used'].":".$storage['free']); rrdtool_update($storage_rrd,"N:".$storage['used'].":".$storage['free']);
$update_query = "UPDATE `storage` SET `storage_used` = '".$storage['used']."'"; $update = dbUpdate(array('storage_used' => $storage['used'], 'storage_free' => $storage['free'], 'storage_size' => $storage['size'], 'storage_units' => $storage['units'], 'storage_perc' => $percent),
$update_query .= ", `storage_free` = '".$storage['free']."', `storage_size` = '".$storage['size']."'"; 'storage', '`storage_id` = ?', array($storage['storage_id']));
$update_query .= ", `storage_units` = '".$storage['units']."', `storage_perc` = '".$percent."'";
$update_query .= " WHERE `storage_id` = '".$storage['storage_id']."'";
if ($debug) { echo("$update_query\n"); }
mysql_query($update_query);
echo("\n"); echo("\n");
} }
unset($storage); unset($storage);
?> ?>

View File

@@ -1,66 +0,0 @@
<?php
$class = 'temperature';
$unit = 'C';
$query = "SELECT * FROM sensors WHERE sensor_class='$class' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$sensor_data = mysql_query($query);
while ($sensor = mysql_fetch_assoc($sensor_data))
{
echo("Checking temp " . $sensor['sensor_descr'] . "... ");
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
{
if ($debug) echo("Attempt $i ");
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
$sensor_value = trim(str_replace("\"", "", $sensor_value));
if ($sensor_value != 9999) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
sleep(1); # Give the TME some time to reset
}
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_file = get_sensor_rrd($device, $sensor);
if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
if (!is_file($rrd_file))
{
rrdtool_create($rrd_file,"--step 300 \
DS:sensor:GAUGE:600:-273:1000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797\
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797");
}
echo("$sensor_value $unit\n");
rrdtool_update($rrd_file,"N:$sensor_value");
if ($sensor['sensor_limit_low'] != "" && $sensor['sensor_current'] < $sensor['sensor_limit'] && $sensor_value >= $sensor['sensor_limit'])
{
$msg = "Temp Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . " (Limit " . $sensor['sensor_limit'];
$msg .= ") at " . date($config['timestamp_format']);
notify($device, "Temp Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n");
log_event('Temperature ' . $sensor['sensor_descr'] . " over threshold: " . $sensor_value . " " . html_entity_decode('&deg;') . "$unit (>= " . $sensor['sensor_limit'] . " " . html_entity_decode('&deg;') . "$unit)", $device, $class, $sensor['sensor_id']);
}
mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'");
}
?>

View File

@@ -2,14 +2,13 @@
if ($config['enable_printers']) if ($config['enable_printers'])
{ {
$query = "SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'"; $toner_data = dbFetchRows("SELECT * FROM toner WHERE device_id = ?", array($device['device_id']));
$toner_data = mysql_query($query);
while ($toner = mysql_fetch_assoc($toner_data)) foreach ($toner_data as $toner)
{ {
echo("Checking toner " . $toner['toner_descr'] . "... "); echo("Checking toner " . $toner['toner_descr'] . "... ");
# FIXME poll capacity maybe also here, when toner is replaced capacity can change, leading to "154% of toner" # FIXME poll capacity maybe also here, when toner is replaced capacity can change, leading to "154% of toner"
$tonerperc = snmp_get($device, $toner['toner_oid'], "-OUqnv") / $toner['toner_capacity'] * 100; $tonerperc = snmp_get($device, $toner['toner_oid'], "-OUqnv") / $toner['toner_capacity'] * 100;
@@ -43,7 +42,7 @@ if ($config['enable_printers'])
log_event('Toner ' . $toner['toner_descr'] . ' was replaced (new level: ' . $tonerperc . '%)', $device, 'toner', $toner['toner_id']); log_event('Toner ' . $toner['toner_descr'] . ' was replaced (new level: ' . $tonerperc . '%)', $device, 'toner', $toner['toner_id']);
} }
mysql_query("UPDATE toner SET toner_current = '$tonerperc', toner_capacity = '" . $toner['toner_capacity'] . "' WHERE toner_id = '" . $toner['toner_id'] . "'"); dbUpdate(array('toner_current' => $tonerperc, 'toner_capacity' => $toner['toner_capacity']), 'toner', '`toner_id` = ?', array($toner['toner_id']));
} }
} }

View File

@@ -1,17 +1,15 @@
<?php <?php
$sql = "SELECT * FROM `ucd_diskio` WHERE `device_id` = '".$device['device_id']."'"; $diskio_data = dbFetchRows("SELECT * FROM `ucd_diskio` WHERE `device_id` = ?".array($device['device_id']));
if ($debug) { echo("$sql"); }
$diskio_data = mysql_query($sql);
if (mysql_affected_rows()) if (count($diskio_data))
{ {
$diskio_cache = array(); $diskio_cache = array();
$diskio_cache = snmpwalk_cache_oid($device, "diskIOEntry", $diskio_cache, "UCD-DISKIO-MIB"); $diskio_cache = snmpwalk_cache_oid($device, "diskIOEntry", $diskio_cache, "UCD-DISKIO-MIB");
echo("Checking UCD DiskIO MIB: "); echo("Checking UCD DiskIO MIB: ");
while ($diskio = mysql_fetch_assoc($diskio_data)) foreach ($diskio_data as $diskio)
{ {
$index = $diskio['diskio_index']; $index = $diskio['diskio_index'];
@@ -59,4 +57,4 @@ if (mysql_affected_rows())
unset($diskio_data); unset($diskio_data);
unset($diskio_cache); unset($diskio_cache);
?> ?>

View File

@@ -1,56 +0,0 @@
<?php
$class = 'voltage';
$unit = 'V';
$query = "SELECT * FROM sensors WHERE sensor_class='$class' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
$sensor_data = mysql_query($query);
while ($sensor = mysql_fetch_assoc($sensor_data))
{
echo("Checking voltage " . $sensor['sensor_descr'] . "... ");
$sensor_value = snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
if ($sensor['sensor_divisor']) { $sensor_value = $sensor_value / $sensor['sensor_divisor']; }
if ($sensor['sensor_multiplier']) { $sensor_value = $sensor_value * $sensor['sensor_multiplier']; }
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/$class-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$rrd_file = get_sensor_rrd($device, $sensor);
if (is_file($old_rrd_file)) { rename($old_rrd_file, $rrd_file); }
if (!is_file($rrd_file))
{
rrdtool_create($rrd_file,"--step 300 \
DS:sensor:GAUGE:600:-273:1000 \
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_value $unit\n");
rrdtool_update($rrd_file,"N:$sensor_value");
if ($sensor['sensor_limit_low'] != "" && $sensor['sensor_current'] > $sensor['sensor_limit_low'] && $sensor_value <= $sensor['sensor_limit_low'])
{
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit'];
$msg .= "$unit) at " . date($config['timestamp_format']);
notify($device, "Voltage Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n");
log_event('Voltage ' . $sensor['sensor_descr'] . " under threshold: " . $sensor_value . " $unit (< " . $sensor['sensor_limit_low'] . " $unit)", $device, $class, $sensor['sensor_id']);
}
else if ($sensor['sensor_limit'] != "" && $sensor['sensor_current'] < $sensor['sensor_limit'] && $sensor_value >= $sensor['sensor_limit'])
{
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit'];
$msg .= "$unit) at " . date($config['timestamp_format']);
notify($device, "Voltage Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n");
log_event('Voltage ' . $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " $unit (> " . $sensor['sensor_limit'] . " $unit)", $device, $class, $sensor['sensor_id']);
}
mysql_query("UPDATE sensors SET sensor_current = '$sensor_value' WHERE sensor_class='$class' AND sensor_id = '" . $sensor['sensor_id'] . "'");
}
?>

View File

@@ -33,8 +33,7 @@ if ($device['type'] == 'network' || $device['type'] == 'firewall')
$wirelesscards = array('Wireless', 'Atheros'); $wirelesscards = array('Wireless', 'Atheros');
foreach ($wirelesscards as $wirelesscheck) foreach ($wirelesscards as $wirelesscheck)
{ {
$query = "SELECT COUNT(*) FROM `entPhysical` WHERE `device_id` = '" . $device['device_id'] . "' AND `entPhysicalDescr` LIKE '%" . $wirelesscheck . "%'"; if (dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE `device_id` = ?AND `entPhysicalDescr` LIKE ?", array($device['device_id'], "%".$wirelesscheck."%")) >= "1")
if (mysql_result(mysql_query($query),0) >= "1")
{ {
echo("Checking RouterOS Wireless clients... "); echo("Checking RouterOS Wireless clients... ");