From 53c3cab362c85de1d5c9bfdcb9d761a5ea42cbeb Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Tue, 15 Mar 2011 15:12:16 +0000 Subject: [PATCH] cleanup poller and discovery, add gpl notice at the top git-svn-id: http://www.observium.org/svn/observer/trunk@1850 61d68cd4-352d-0410-923a-c4978735b2b8 --- discovery.php | 19 +++++++++--- poller.php | 80 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/discovery.php b/discovery.php index ff238a9b64..a1517f487f 100755 --- a/discovery.php +++ b/discovery.php @@ -1,6 +1,17 @@ #!/usr/bin/env php | Poll single device\n"); echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"); @@ -133,13 +144,13 @@ while ($device = mysql_fetch_array($device_query)) $device_start = utime(); // Start counting device poll time echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." "); - if($device['os'] != strtolower($device['os'])) + if ($device['os'] != strtolower($device['os'])) { mysql_query("UPDATE `devices` SET `os` = '".strtolower($device['os'])."' WHERE device_id = '".$device['device_id']."'"); $device['os'] = strtolower($device['os']); echo("OS lowercased."); } - if($config['os'][$device['os']]['group']) + if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; echo("(".$device['os_group'].")"); @@ -195,7 +206,7 @@ while ($device = mysql_fetch_array($device_query)) $end = utime(); $run = $end - $start; $proctime = substr($run, 0, 5); -if($discovered_devices) +if ($discovered_devices) { mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) VALUES ('discover', '$doing', '$start', '$proctime', '$discovered_devices')"); diff --git a/poller.php b/poller.php index bc93216af5..dd866335ea 100755 --- a/poller.php +++ b/poller.php @@ -1,6 +1,17 @@ #!/usr/bin/env php | Poll single device\n"); echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"); echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n"); @@ -46,7 +60,8 @@ if (!$where) { exit; } -if (isset($options['d'])) { +if (isset($options['d'])) +{ echo("DEBUG!\n"); $debug = TRUE; ini_set('display_errors', 1); @@ -74,7 +89,7 @@ while ($device = mysql_fetch_assoc($device_query)) $device_start = utime(); // Start counting device poll time echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." "); - if($config['os'][$device['os']]['group']) + if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; echo("(".$device['os_group'].")"); @@ -89,9 +104,11 @@ while ($device = mysql_fetch_assoc($device_query)) $device['pingable'] = isPingable($device['hostname']); - if($device['pingable']) { + if ($device['pingable']) + { $device['snmpable'] = isSNMPable($device['hostname'], $device['community'], $device['snmpver'], $device['port']); - if($device['snmpable']) { + if ($device['snmpable']) + { $status = "1"; } else { echo("SNMP Unreachable"); @@ -102,7 +119,7 @@ while ($device = mysql_fetch_assoc($device_query)) $status = "0"; } - if ( $device['status'] != $status ) + if ($device['status'] != $status ) { $poll_update .= $poll_separator . "`status` = '$status'"; $poll_separator = ", "; @@ -159,7 +176,7 @@ while ($device = mysql_fetch_assoc($device_query)) if (is_numeric($uptime)) { - if ( $uptime < $device['uptime'] ) { + if ($uptime < $device['uptime'] ) { notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago."); log_event('Device rebooted after '.formatUptime($device['uptime']), $device['device_id'], 'reboot', $device['uptime']); } @@ -226,52 +243,60 @@ while ($device = mysql_fetch_assoc($device_query)) include("includes/polling/cisco-ipsec-flow-monitor.inc.php"); include("includes/polling/cisco-remote-access-monitor.inc.php"); - unset( $update ) ; - unset( $seperator) ; + unset($update); + unset($seperator); - if ( $serial && $serial != $device['serial'] ) { + if ($serial && $serial != $device['serial']) + { $poll_update .= $poll_separator . "`serial` = '".mres($serial)."'"; $poll_separator = ", "; log_event("Serial -> $serial", $device['device_id'], 'system'); } - if ( $sysContact && $sysContact != $device['sysContact'] ) { + if ($sysContact && $sysContact != $device['sysContact']) + { $poll_update .= $poll_separator . "`sysContact` = '".mres($sysContact)."'"; $poll_separator = ", "; log_event("Contact -> $sysContact", $device['device_id'], 'system'); } - if ( $sysName && $sysName != $device['sysName'] ) { + if ($sysName && $sysName != $device['sysName']) + { $poll_update .= $poll_separator . "`sysName` = '$sysName'"; $poll_separator = ", "; log_event("sysName -> $sysName", $device['device_id'], 'system'); } - if ( $sysDescr && $sysDescr != $device['sysDescr'] ) { + if ($sysDescr && $sysDescr != $device['sysDescr']) + { $poll_update .= $poll_separator . "`sysDescr` = '$sysDescr'"; $poll_separator = ", "; log_event("sysDescr -> $sysDescr", $device['device_id'], 'system'); } - if ( $sysLocation && $device['location'] != $sysLocation ) { + if ($sysLocation && $device['location'] != $sysLocation) + { $poll_update .= $poll_separator . "`location` = '$sysLocation'"; $poll_separator = ", "; log_event("Location -> $sysLocation", $device['device_id'], 'system'); } - if ( $version && $device['version'] != $version ) { + if ($version && $device['version'] != $version) + { $poll_update .= $poll_separator . "`version` = '$version'"; $poll_separator = ", "; log_event("OS Version -> $version", $device['device_id'], 'system'); } - if ( $features != $device['features'] ) { + if ($features != $device['features']) + { $poll_update .= $poll_separator . "`features` = '$features'"; $poll_separator = ", "; log_event("OS Features -> $features", $device['device_id'], 'system'); } - if ( $hardware && $hardware != $device['hardware'] ) { + if ($hardware && $hardware != $device['hardware']) + { $poll_update .= $poll_separator . "`hardware` = '$hardware'"; $poll_separator = ", "; log_event("Hardware -> $hardware", $device['device_id'], 'system'); @@ -290,17 +315,19 @@ while ($device = mysql_fetch_assoc($device_query)) ### Ideally we should hold graphs for xx days/weeks/polls so that we don't needlessly hide information. $query = mysql_query("SELECT `graph` FROM `device_graphs` WHERE `device_id` = '".$device['device_id']."'"); - while($graph = mysql_fetch_array($query)){ - if(!isset($graphs[$graph[0]])) + while ($graph = mysql_fetch_array($query)) + { + if (!isset($graphs[$graph[0]])) { mysql_query("DELETE FROM `device_graphs` WHERE `device_id` = '".$device['device_id']."' AND `graph` = '".$graph[0]."'"); } else { $oldgraphs[$graph[0]] = TRUE; } } - foreach($graphs as $graph => $value) + + foreach ($graphs as $graph => $value) { - if(!isset($oldgraphs[$graph])) + if (!isset($oldgraphs[$graph])) { mysql_query("INSERT INTO `device_graphs` (`device_id`, `graph`) VALUES ('".$device['device_id']."','".$graph."')"); } @@ -315,9 +342,9 @@ while ($device = mysql_fetch_assoc($device_query)) $poll_update_query = "UPDATE `devices` SET "; $poll_update_query .= $poll_update; $poll_update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'"; - if($debug) {echo("Updating " . $device['hostname'] . " - $poll_update_query \n");} + if ($debug) { echo("Updating " . $device['hostname'] . " - $poll_update_query \n"); } $poll_update_result = mysql_query($poll_update_query); - if(mysql_affected_rows() == "1") { echo("UPDATED!\n"); } else { echo("NOT UPDATED!\n"); } + if (mysql_affected_rows() == "1") { echo("UPDATED!\n"); } else { echo("NOT UPDATED!\n"); } unset($storage_cache); // Clear cache of hrStorage ** MAYBE FIXME? ** unset($cache); // Clear cache (unify all things here?) @@ -326,7 +353,8 @@ while ($device = mysql_fetch_assoc($device_query)) $poller_end = utime(); $poller_run = $poller_end - $poller_start; $poller_time = substr($poller_run, 0, 5); -if($polled_devices) { +if ($polled_devices) +{ mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) VALUES ('poll', '$doing', '$poller_start', '$poller_time', '$polled_devices')"); }