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
This commit is contained in:
Tom Laermans
2011-03-15 15:12:16 +00:00
parent 0cbb3ab944
commit 53c3cab362
2 changed files with 69 additions and 30 deletions
+11
View File
@@ -1,6 +1,17 @@
#!/usr/bin/env php
<?php
/* Observium Network Management and Monitoring System
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* See COPYING for more details.
*/
include("includes/defaults.inc.php");
include("config.php");
include("includes/functions.php");
+44 -16
View File
@@ -1,6 +1,17 @@
#!/usr/bin/env php
<?php
/* Observium Network Management and Monitoring System
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* See COPYING for more details.
*/
### Observium Device Poller
include("includes/defaults.inc.php");
@@ -15,7 +26,8 @@ $options = getopt("h:t:i:n:d::a::");
if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; }
elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; }
elseif ($options['h'] == "all") { $where = " "; $doing = "all"; }
elseif ($options['h']) {
elseif ($options['h'])
{
if (is_numeric($options['h']))
{
$where = "AND `device_id` = '".$options['h']."'";
@@ -28,12 +40,14 @@ elseif ($options['h']) {
}
}
if (isset($options['i']) && $options['i'] && isset($options['n'])) {
if (isset($options['i']) && $options['i'] && isset($options['n']))
{
$where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'";
$doing = $options['n'] ."/".$options['i'];
}
if (!$where) {
if (!$where)
{
echo("-h <device id> | <device hostname> 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);
@@ -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");
@@ -229,49 +246,57 @@ while ($device = mysql_fetch_assoc($device_query))
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,7 +315,8 @@ 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)){
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]."'");
@@ -298,6 +324,7 @@ while ($device = mysql_fetch_assoc($device_query))
$oldgraphs[$graph[0]] = TRUE;
}
}
foreach ($graphs as $graph => $value)
{
if (!isset($oldgraphs[$graph]))
@@ -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')");
}