git-svn-id: http://www.observium.org/svn/observer/trunk@2340 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-17 19:21:20 +00:00
parent 0846a7cc60
commit 1b956853ad
23 changed files with 384 additions and 227 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
$query = "SELECT * FROM entPhysical WHERE device_id = '" . $device['device_id'] . "' AND entPhysicalClass = 'sensor'";
$sensors = mysql_query($query);
while ($sensor = mysql_fetch_assoc($sensors))
{
echo("Checking Entity Sensor " . $sensor['entPhysicalName'] . " - " . $sensor['cempsensorName']);
$oid = $sensor['entPhysicalIndex'];
$sensor_cmd = $config['snmpget'] . " -M ".$config['mibdir']." -m CISCO-ENTITY-SENSOR-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
$sensor_cmd .= " entSensorValue.$oid entSensorStatus.$oid";
$sensor_data = trim(shell_exec($sensor_cmd));
# echo("$sensor_data");
list($entSensorValue, $entSensorStatus) = explode("\n", $sensor_data);
$rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("ces-" . $oid . ".rrd");
if (!is_file($rrd))
{
rrdtool_create($rrd,"--step 300 \
DS:value:GAUGE:600:-1000:U \
RRA:AVERAGE:0.5:1:2304 \
RRA:AVERAGE:0.5:6:1536 \
RRA:AVERAGE:0.5:24:2268 \
RRA:AVERAGE:0.5:288:1890 \
RRA:MAX:0.5:1:2304 \
RRA:MAX:0.5:6:1536 \
RRA:MAX:0.5:24:2268 \
RRA:MAX:0.5:288:1890 \
RRA:MIN:0.5:1:2304 \
RRA:MIN:0.5:6:1536 \
RRA:MIN:0.5:24:2268 \
RRA:MIN:0.5:288:1890");
}
$entSensorValue = entPhysical_scale($entSensorValue, $sensor['entSensorScale']);
$updatecmd = $config['rrdtool'] ." update $rrd N:$entSensorValue";
shell_exec($updatecmd);
$update_query = "UPDATE `entPhysical` SET entSensorValue='$entSensorValue', entSensorStatus='$entSensorStatus' WHERE `entPhysical_id` = '".$sensor['entPhysical_id']."'";
mysql_query($update_query);
echo($entSensorValue . " - " . $entSensorStatus . "\n");
}
?>
+66
View File
@@ -0,0 +1,66 @@
<?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'] . "'");
}
?>
+54
View File
@@ -0,0 +1,54 @@
<?php
$class = 'voltage';
$class_text = "Voltage";
$unit = 'V';
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `poller_type` = 'snmp'", array($class, $device['device_id'])) as $sensor)
{
echo("Checking ".$class." " . $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 = $class_text . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit'];
$msg .= "$unit) at " . date($config['timestamp_format']);
notify($device, $class_text" Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n");
log_event($class_text.' '.$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 = $class_text." Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is " . $sensor_value . "$unit (Limit " . $sensor['sensor_limit'];
$msg .= "$unit) at " . date($config['timestamp_format']);
notify($device, $class_text." Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
echo("Alerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "\n");
log_event($class_text." ". $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " $unit (> " . $sensor['sensor_limit'] . " $unit)", $device, $class, $sensor['sensor_id']);
}
dbUpdate(array('sensor_current' => $sensor_value), 'sensors', '`sensor_id` = ', array($sensor['sensor_id']));
}
?>