mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
fix uptime polling broken in r970
git-svn-id: http://www.observium.org/svn/observer/trunk@982 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+56
-54
@@ -48,7 +48,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
if ($os_groups[$device[os]]) {$device['os_group'] = $os_groups[$device[os]]; echo "(".$device['os_group'].")";}
|
if ($os_groups[$device[os]]) {$device['os_group'] = $os_groups[$device[os]]; echo "(".$device['os_group'].")";}
|
||||||
echo("\n");
|
echo("\n");
|
||||||
|
|
||||||
unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features);
|
unset($poll_update); unset($poll_update_query); unset($poll_separator); unset($version); unset($uptime); unset($features);
|
||||||
unset($sysLocation); unset($hardware); unset($sysDescr); unset($sysContact); unset($sysName);
|
unset($sysLocation); unset($hardware); unset($sysDescr); unset($sysContact); unset($sysName);
|
||||||
|
|
||||||
$pingable = isPingable($device['hostname']);
|
$pingable = isPingable($device['hostname']);
|
||||||
@@ -71,37 +71,6 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
$status = "0";
|
$status = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($uptime)
|
|
||||||
{
|
|
||||||
if ( $uptime < $device['uptime'] ) {
|
|
||||||
notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.");
|
|
||||||
eventlog('Device rebooted', $device['device_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
|
|
||||||
|
|
||||||
if (!is_file($uptimerrd)) {
|
|
||||||
$woo = shell_exec($config['rrdtool'] . " create $uptimerrd \
|
|
||||||
DS:uptime:GAUGE:600:0:U \
|
|
||||||
RRA:AVERAGE:0.5:1:600 \
|
|
||||||
RRA:AVERAGE:0.5:6:700 \
|
|
||||||
RRA:AVERAGE:0.5:24:775 \
|
|
||||||
RRA:AVERAGE:0.5:288:797");
|
|
||||||
}
|
|
||||||
rrdtool_update($uptimerrd, "N:$uptime");
|
|
||||||
|
|
||||||
$update .= $seperator . "`uptime` = '$uptime'";
|
|
||||||
$seperator = ", ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $device['status'] != $status ) {
|
|
||||||
$update .= $seperator . "`status` = '$status'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("UPDATE `devices` SET `status` = '".$status."' WHERE `device_id` = '".$device['device_id']."'");
|
|
||||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is " . ($status == '1' ? 'up' : 'down') . "')");
|
|
||||||
eventlog('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device['device_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($status) {
|
if ($status) {
|
||||||
$snmp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
$snmp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||||
$snmp_cmd .= " sysUpTime.0 sysLocation.0 sysContact.0 sysName.0";
|
$snmp_cmd .= " sysUpTime.0 sysLocation.0 sysContact.0 sysName.0";
|
||||||
@@ -121,6 +90,39 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
$secs = $secs + ($mins * 60);
|
$secs = $secs + ($mins * 60);
|
||||||
$uptime = $secs;
|
$uptime = $secs;
|
||||||
|
|
||||||
|
if ($uptime)
|
||||||
|
{
|
||||||
|
if ( $uptime < $device['uptime'] ) {
|
||||||
|
notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.");
|
||||||
|
eventlog('Device rebooted', $device['device_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
|
||||||
|
|
||||||
|
if (!is_file($uptimerrd))
|
||||||
|
{
|
||||||
|
$woo = shell_exec($config['rrdtool'] . " create $uptimerrd \
|
||||||
|
DS:uptime:GAUGE:600:0:U \
|
||||||
|
RRA:AVERAGE:0.5:1:600 \
|
||||||
|
RRA:AVERAGE:0.5:6:700 \
|
||||||
|
RRA:AVERAGE:0.5:24:775 \
|
||||||
|
RRA:AVERAGE:0.5:288:797");
|
||||||
|
}
|
||||||
|
rrdtool_update($uptimerrd, "N:$uptime");
|
||||||
|
|
||||||
|
$poll_update .= $poll_separator . "`uptime` = '$uptime'";
|
||||||
|
$poll_separator = ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $device['status'] != $status )
|
||||||
|
{
|
||||||
|
$poll_update .= $poll_separator . "`status` = '$status'";
|
||||||
|
$poll_separator = ", ";
|
||||||
|
mysql_query("UPDATE `devices` SET `status` = '".$status."' WHERE `device_id` = '".$device['device_id']."'");
|
||||||
|
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is " . ($status == '1' ? 'up' : 'down') . "')");
|
||||||
|
eventlog('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device['device_id']);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_file($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php")) {
|
if (is_file($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php")) {
|
||||||
/// OS Specific
|
/// OS Specific
|
||||||
include($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php");
|
include($config['install_dir'] . "/includes/polling/device-".$device['os'].".inc.php");
|
||||||
@@ -149,59 +151,59 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
unset( $seperator) ;
|
unset( $seperator) ;
|
||||||
|
|
||||||
if ( $sysContact && $sysContact != $device['sysContact'] ) {
|
if ( $sysContact && $sysContact != $device['sysContact'] ) {
|
||||||
$update .= $seperator . "`sysContact` = '".mres($sysContact)."'";
|
$poll_update .= $poll_separator . "`sysContact` = '".mres($sysContact)."'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("Contact -> $sysContact", $device['device_id']);
|
eventlog("Contact -> $sysContact", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $sysName && $sysName != $device['sysName'] ) {
|
if ( $sysName && $sysName != $device['sysName'] ) {
|
||||||
$update .= $seperator . "`sysName` = '$sysName'";
|
$poll_update .= $poll_separator . "`sysName` = '$sysName'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("sysName -> $sysName", $device['device_id']);
|
eventlog("sysName -> $sysName", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
|
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
|
||||||
$update .= $seperator . "`sysDescr` = '$sysDescr'";
|
$poll_update .= $poll_separator . "`sysDescr` = '$sysDescr'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("sysDescr -> $sysDescr", $device['device_id']);
|
eventlog("sysDescr -> $sysDescr", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $sysLocation && $device['location'] != $sysLocation ) {
|
if ( $sysLocation && $device['location'] != $sysLocation ) {
|
||||||
$update .= $seperator . "`location` = '$sysLocation'";
|
$poll_update .= $poll_separator . "`location` = '$sysLocation'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("Location -> $sysLocation", $device['device_id']);
|
eventlog("Location -> $sysLocation", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $version && $device['version'] != $version ) {
|
if ( $version && $device['version'] != $version ) {
|
||||||
$update .= $seperator . "`version` = '$version'";
|
$poll_update .= $poll_separator . "`version` = '$version'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("OS Version -> $version", $device['device_id']);
|
eventlog("OS Version -> $version", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $features && $features != $device['features'] ) {
|
if ( $features && $features != $device['features'] ) {
|
||||||
$update .= $seperator . "`features` = '$features'";
|
$poll_update .= $poll_separator . "`features` = '$features'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("OS Features -> $features", $device['device_id']);
|
eventlog("OS Features -> $features", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $hardware && $hardware != $device['hardware'] ) {
|
if ( $hardware && $hardware != $device['hardware'] ) {
|
||||||
$update .= $seperator . "`hardware` = '$hardware'";
|
$poll_update .= $poll_separator . "`hardware` = '$hardware'";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
eventlog("Hardware -> $hardware", $device['device_id']);
|
eventlog("Hardware -> $hardware", $device['device_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$update .= $seperator . "`last_polled` = NOW()";
|
$poll_update .= $poll_separator . "`last_polled` = NOW()";
|
||||||
$seperator = ", ";
|
$poll_separator = ", ";
|
||||||
$polled_devices++;
|
$polled_devices++;
|
||||||
echo("\n");
|
echo("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($update) {
|
if ($poll_update) {
|
||||||
$update_query = "UPDATE `devices` SET ";
|
$poll_update_query = "UPDATE `devices` SET ";
|
||||||
$update_query .= $update;
|
$poll_update_query .= $poll_update;
|
||||||
$update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'";
|
$poll_update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'";
|
||||||
echo("Updating " . $device['hostname'] . " - $update_query \n");
|
echo("Updating " . $device['hostname'] . " - $poll_update_query \n");
|
||||||
$update_result = mysql_query($update_query);
|
$poll_update_result = mysql_query($poll_update_query);
|
||||||
} else {
|
} else {
|
||||||
echo("No Changes to " . $device['hostname'] . "\n");
|
echo("No Changes to " . $device['hostname'] . "\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user