diff --git a/includes/common.php b/includes/common.php index 535ee2edbb..2dc3d42bba 100644 --- a/includes/common.php +++ b/includes/common.php @@ -252,11 +252,11 @@ function set_dev_attrib($device, $attrib_type, $attrib_value) function get_dev_attribs($device) { $attribs = array(); - $sql = "SELECT attrib_type, attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "'"; - $data = mysql_query($sql); - while($entry = mysql_fetch_array($data)) + $sql = "SELECT * FROM devices_attribs WHERE `device_id` = '" . mres($device) . "'"; + $query = mysql_query($sql); + while($entry = mysql_fetch_assoc($query)) { - $attribs[$entry['attrib_type']] = $attribs['attrib_value']; + $attribs[$entry['attrib_type']] = $entry['attrib_value']; } return $attribs; } diff --git a/includes/polling/os.inc.php b/includes/polling/os.inc.php new file mode 100644 index 0000000000..d7546e0f27 --- /dev/null +++ b/includes/polling/os.inc.php @@ -0,0 +1,19 @@ + diff --git a/includes/polling/port-etherlike.inc.php b/includes/polling/port-etherlike.inc.php index 3783f03295..0f110215f4 100755 --- a/includes/polling/port-etherlike.inc.php +++ b/includes/polling/port-etherlike.inc.php @@ -9,7 +9,7 @@ if ($port_stats[$port['ifIndex']] && $port['ifType'] == "ethernetCsmacd" $old_rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("etherlike-".$port['ifIndex'].".rrd"); $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("port-".$port['ifIndex']."-dot3.rrd"); - $rrd_create .= "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 \ + $rrd_create = "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"; if (!file_exists($rrdfile)) @@ -40,4 +40,4 @@ if ($port_stats[$port['ifIndex']] && $port['ifType'] == "ethernetCsmacd" echo("EtherLike "); } -?> \ No newline at end of file +?> diff --git a/includes/polling/system.inc.php b/includes/polling/system.inc.php new file mode 100755 index 0000000000..48bb633237 --- /dev/null +++ b/includes/polling/system.inc.php @@ -0,0 +1,131 @@ + ".$poll_device['serial'], $device, 'system'); + } + + if ($poll_device['sysContact'] && $poll_device['sysContact'] != $device['sysContact']) + { + $device['db_update'] .= ", `sysContact` = '".mres($poll_device['sysContact'])."'"; + log_event("Contact -> ".$poll_device['sysContact'], $device, 'system'); + } + + if ($poll_device['sysName'] && $poll_device['sysName'] != $device['sysName']) + { + $device['db_update'] .= ", `sysName` = '".mres($poll_device['sysName'])."'"; + log_event("sysName -> ".$poll_device['sysName'], $device, 'system'); + } + + if ($poll_device['sysDescr'] && $poll_device['sysDescr'] != $device['sysDescr']) + { + $device['db_update'] .= ", `sysDescr` = '".mres($poll_device['sysDescr'])."'"; + log_event("sysDescr -> ".$poll_device['sysDescr'], $device, 'system'); + } + + if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation']) + { + if (!get_dev_attrib($device,'override_sysLocation_bool')) + { + $device['db_update'] .= ", `location` = '".mres($poll_device['sysLocation'])."'"; + } + log_event("Location -> ".$poll_device['sysLocation'], $device, 'system'); + } + + if ($poll_device['version'] && $device['version'] != $poll_device['version']) + { + $device['db_update'] .= ", `version` = '".mres($poll_device['version'])."'"; + log_event("OS Version -> ".$poll_device['version'], $device, 'system'); + } + + if ($poll_device['features'] != $device['features']) + { + $device['db_update'] .= ", `features` = '".mres($poll_device['features'])."'"; + log_event("OS Features -> ".$poll_device['features'], $device, 'system'); + } + + if ($poll_device['hardware'] && $poll_device['hardware'] != $device['hardware']) + { + $device['db_update'] .= ", `hardware` = '".mres($poll_device['hardware'])."'"; + log_event("Hardware -> ".$poll_device['hardware'], $device, 'system'); + } + +?> diff --git a/includes/polling/test.inc.php b/includes/polling/test.inc.php new file mode 100755 index 0000000000..f47a7c6bf1 --- /dev/null +++ b/includes/polling/test.inc.php @@ -0,0 +1,8 @@ + diff --git a/includes/static-config.php b/includes/static-config.php index 8cc8fcc8d2..4034b9cfdd 100644 --- a/includes/static-config.php +++ b/includes/static-config.php @@ -10,6 +10,8 @@ ## List of poller modules. Need to be in the array to be ## considered for execution. +#$config['poller_modules']['system'] = 1; +#$config['poller_modules']['os'] = 1; $config['poller_modules']['ipmi'] = 1; $config['poller_modules']['sensors'] = 1; $config['poller_modules']['processors'] = 1; diff --git a/poller.php b/poller.php index 3bd5c8426d..ec07882d1f 100755 --- a/poller.php +++ b/poller.php @@ -99,6 +99,15 @@ while ($device = mysql_fetch_assoc($device_query)) { $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'")); + poll_device($device, $options); + +} + + +function poll_device($device, $options) { + + global $config; + $status = 0; unset($array); $device_start = utime(); // Start counting device poll time @@ -110,8 +119,7 @@ while ($device = mysql_fetch_assoc($device_query)) } echo("\n"); - 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($serial); + unset($poll_update); unset($poll_update_query); unset($poll_separator); $host_rrd = $config['rrd_dir'] . "/" . $device['hostname']; if (!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); } @@ -147,88 +155,6 @@ while ($device = mysql_fetch_assoc($device_query)) $graphs = array(); $oldgraphs = array(); - $snmpdata = snmp_get_multi($device, "sysUpTime.0 sysLocation.0 sysContact.0 sysName.0", "-OQUs", "SNMPv2-MIB"); - foreach (array_keys($snmpdata[0]) as $key) { $$key = $snmpdata[0][$key]; } - - $sysDescr = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); - - $sysName = strtolower($sysName); - - $hrSystemUptime = snmp_get($device, "hrSystemUptime.0", "-Oqv", "HOST-RESOURCES-MIB"); - $sysObjectID = snmp_get($device, "sysObjectID.0", "-Oqvn"); - -# echo("UPTIMES: ".$hrSystemUptime."|".$sysUpTime."]"); - - if ($hrSystemUptime != "" && !strpos($hrSystemUptime, "No") && ($device['os'] != "windows")) - { - echo("Using hrSystemUptime\n"); - $agent_uptime = $uptime; ## Move uptime into agent_uptime - #HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65 - $hrSystemUptime = str_replace("(", "", $hrSystemUptime); - $hrSystemUptime = str_replace(")", "", $hrSystemUptime); - list($days,$hours, $mins, $secs) = explode(":", $hrSystemUptime); - list($secs, $microsecs) = explode(".", $secs); - $hours = $hours + ($days * 24); - $mins = $mins + ($hours * 60); - $secs = $secs + ($mins * 60); - $uptime = $secs; - } else { - echo("Using Agent Uptime\n"); - #SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31 - $sysUpTime = str_replace("(", "", $sysUpTime); - $sysUpTime = str_replace(")", "", $sysUpTime); - list($days, $hours, $mins, $secs) = explode(":", $sysUpTime); - list($secs, $microsecs) = explode(".", $secs); - $hours = $hours + ($days * 24); - $mins = $mins + ($hours * 60); - $secs = $secs + ($mins * 60); - $uptime = $secs; - } - - if (is_numeric($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, 'reboot', $device['uptime']); - } - - $uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd"; - - if (!is_file($uptimerrd)) - { - 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"); - - $graphs['uptime'] = TRUE; - - echo("Uptime: ".formatUptime($uptime)."\n"); - - $poll_update .= $poll_separator . "`uptime` = '$uptime'"; - $poll_separator = ", "; - } - - if (is_file($config['install_dir'] . "/includes/polling/os/".$device['os'].".inc.php")) - { - /// OS Specific - include($config['install_dir'] . "/includes/polling/os/".$device['os'].".inc.php"); - } - elseif ($device['os_group'] && is_file($config['install_dir'] . "/includes/polling/os/".$device['os_group'].".inc.php")) - { - /// OS Group Specific - include($config['install_dir'] . "/includes/polling/os/".$device['os_group'].".inc.php"); - } - else - { - echo("Generic :(\n"); - } - - echo("Hardware: ".$hardware." Version: ".$version." Features: ".$features."\n"); - - $sysLocation = str_replace("\"","", $sysLocation); - $sysContact = str_replace("\"","", $sysContact); - if ($options['m']) { if (is_file("includes/polling/".$options['m'].".inc.php")) @@ -245,133 +171,44 @@ while ($device = mysql_fetch_assoc($device_query)) } } - unset($update); - unset($seperator); + $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); + $device['db_update'] = " `last_polled` = NOW() " . $device['db_update']; + $device['db_update'] .= ", `last_polled_timetaken` = '$device_time'"; + #echo("$device_end - $device_start; $device_time $device_run"); + echo("Polled in $device_time seconds\n"); - if ($serial && $serial != $device['serial']) + $device['db_update_query'] = "UPDATE `devices` SET "; + $device['db_update_query'] .= $device['db_update']; + $device['db_update_query'] .= " WHERE `device_id` = '" . $device['device_id'] . "'"; + if ($debug) { echo("Updating " . $device['hostname'] . " - ".$device['db_update_query']." \n"); } + if (!mysql_query($device['db_update_query'])) { - $poll_update .= $poll_separator . "`serial` = '".mres($serial)."'"; - $poll_separator = ", "; - log_event("Serial -> $serial", $device, 'system'); + echo("ERROR: " . mysql_error() . "\nSQL: ".$device['db_update_query']."\n"); } + if (mysql_affected_rows() == "1") { echo("UPDATED!\n"); } else { echo("NOT UPDATED!\n"); } - if ($sysContact && $sysContact != $device['sysContact']) - { - $poll_update .= $poll_separator . "`sysContact` = '".mres($sysContact)."'"; - $poll_separator = ", "; - log_event("Contact -> $sysContact", $device, 'system'); - } - - if ($sysName && $sysName != $device['sysName']) - { - $poll_update .= $poll_separator . "`sysName` = '".mres($sysName)."'"; - $poll_separator = ", "; - log_event("sysName -> $sysName", $device, 'system'); - } - - if ($sysDescr && $sysDescr != $device['sysDescr']) - { - $poll_update .= $poll_separator . "`sysDescr` = '".mres($sysDescr)."'"; - $poll_separator = ", "; - log_event("sysDescr -> $sysDescr", $device, 'system'); - } - - if ($sysLocation && $device['location'] != $sysLocation) - { - if (!get_dev_attrib($device,'override_sysLocation_bool')) - { - $poll_update .= $poll_separator . "`location` = '".mres($sysLocation)."'"; - $poll_separator = ", "; - } - log_event("Location -> $sysLocation", $device, 'system'); - } - - if ($version && $device['version'] != $version) - { - $poll_update .= $poll_separator . "`version` = '".mres($version)."'"; - $poll_separator = ", "; - log_event("OS Version -> $version", $device, 'system'); - } - - if ($features != $device['features']) - { - $poll_update .= $poll_separator . "`features` = '".mres($features)."'"; - $poll_separator = ", "; - log_event("OS Features -> $features", $device, 'system'); - } - - if ($hardware && $hardware != $device['hardware']) - { - $poll_update .= $poll_separator . "`hardware` = '".mres($hardware)."'"; - $poll_separator = ", "; - log_event("Hardware -> $hardware", $device, 'system'); - } - - $poll_update .= $poll_separator . "`last_polled` = NOW()"; - $poll_separator = ", "; - $polled_devices++; - echo("\n"); - + unset($storage_cache); // Clear cache of hrStorage ** MAYBE FIXME? ** + unset($cache); // Clear cache (unify all things here?) } - ## FIXME EVENTLOGGING - ### This code cycles through the graphs already known in the database and the ones we've defined as being polled here - ### If there any don't match, they're added/deleted from the database. - ### 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_assoc($query)) - { - if (!isset($graphs[$graph["graph"]])) - { - mysql_query("DELETE FROM `device_graphs` WHERE `device_id` = '".$device['device_id']."' AND `graph` = '".$graph["graph"]."'"); - } else { - $oldgraphs[$graph["graph"]] = TRUE; - } - } - - foreach ($graphs as $graph => $value) - { - if (!isset($oldgraphs[$graph])) - { - mysql_query("INSERT INTO `device_graphs` (`device_id`, `graph`) VALUES ('".$device['device_id']."','".$graph."')"); - } - } - - $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); - $poll_update .= $poll_separator . "`last_polled_timetaken` = '$device_time'"; - #echo("$device_end - $device_start; $device_time $device_run"); - echo("Polled in $device_time seconds\n"); - - $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 (!mysql_query($poll_update_query)) - { - echo("ERROR: " . mysql_error() . "\nSQL: $poll_update_query\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?) } -$poller_end = utime(); $poller_run = $poller_end - $poller_start; $poller_time = substr($poller_run, 0, 5); + $poller_end = utime(); $poller_run = $poller_end - $poller_start; $poller_time = substr($poller_run, 0, 5); -if ($polled_devices) -{ - mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) - VALUES ('poll', '$doing', '$poller_start', '$poller_time', '$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')"); + } -$string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $polled_devices devices polled in $poller_time secs"; -if ($debug) echo("$string\n"); + $string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $polled_devices devices polled in $poller_time secs"; + if ($debug) echo("$string\n"); -logfile($string); + logfile($string); -unset($config); ### Remove this for testing + unset($config); ### Remove this for testing + + #print_r(get_defined_vars()); -#print_r(get_defined_vars()); ?>