From 9f24ca42483b9ad29d33bf3a9f1fbb1da331fa78 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Thu, 17 Mar 2011 11:12:32 +0000 Subject: [PATCH] moar. git-svn-id: http://www.observium.org/svn/observer/trunk@1899 61d68cd4-352d-0410-923a-c4978735b2b8 --- adduser.php | 6 +-- check-errors.php | 2 +- cleanup.php | 4 +- irc.php | 8 ++-- poll-reachability.php | 88 +++++++++++++++++++++++-------------------- 5 files changed, 57 insertions(+), 51 deletions(-) diff --git a/adduser.php b/adduser.php index a9b74d444..36f58b102 100755 --- a/adduser.php +++ b/adduser.php @@ -13,8 +13,8 @@ else { echo("ERROR: no valid auth_mechanism defined.\n"); exit(); -} - +} + if (auth_usermanagement()) { if ($argv[1] && $argv[2] && $argv[3]) @@ -34,4 +34,4 @@ else echo("Auth module does not allow adding users!\n"); } -?> +?> \ No newline at end of file diff --git a/check-errors.php b/check-errors.php index 8dc52d29f..6e2e8c527 100755 --- a/check-errors.php +++ b/check-errors.php @@ -29,7 +29,7 @@ if ($errored) { ## If there are errored ports $i=0; $msg = "Interfaces with errors : \n\n"; - + foreach ($errored as $int) { $msg .= "$int\n"; ## Add a line to the report email warning about them diff --git a/cleanup.php b/cleanup.php index 917c14601..5e8a685f6 100755 --- a/cleanup.php +++ b/cleanup.php @@ -33,7 +33,7 @@ $query = mysql_query($sql); while ($device = mysql_fetch_array($query)) { echo($device['hostname'] . " \n\n"); - + $oids = snmp_walk($device, "ipAddressIfIndex.ipv6", "-Osq"); $oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids); @@ -134,7 +134,7 @@ while ($link = mysql_fetch_array($link_query)) mysql_query("delete from adjacencies where `adj_id` = '$id'"); echo("Deleting link $id (".$link['cidr']." - ". $link['hostname'] ." - ". $link['ifDescr'] .")\n"); } - + unset($remove); } diff --git a/irc.php b/irc.php index 22c627031..674009cbe 100755 --- a/irc.php +++ b/irc.php @@ -49,13 +49,13 @@ $chan = "#observium"; $bot = &new observiumbot(); $irc = &new Net_SmartIRC(); -$irc->setUseSockets( TRUE ); +$irc->setUseSockets(TRUE); -$irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info' ); -$irc->registerActionhandler( SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info' ); +$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info'); +$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info'); $irc->connect($host, $port)); -$irc->login($nick, 'Observium Bot', 0, $nick ); +$irc->login($nick, 'Observium Bot', 0, $nick); $irc->join(array($chan)))); $irc->listen(); $irc->disconnect(); diff --git a/poll-reachability.php b/poll-reachability.php index 1e28a87bf..e2138fabf 100755 --- a/poll-reachability.php +++ b/poll-reachability.php @@ -6,51 +6,57 @@ include("config.php"); include("includes/functions.php"); $device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' AND disabled = '0' ORDER BY `device_id` DESC"); -while ($device = mysql_fetch_array($device_query)) { - $port = $device['port']; +while ($device = mysql_fetch_array($device_query)) +{ + $port = $device['port']; - echo($device['hostname']. " "); + echo($device['hostname']. " "); - if( isPingable($device['hostname']) ) { - $pos = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); - echo($device['protocol'].":".$device['hostname'].":".$device['port']." - ".$device['community']." ".$device['snmpver'].": "); - if($pos == '') { - $status='0'; - } else { - $status='1'; - } - } else { - $status='0'; - } + if (isPingable($device['hostname'])) + { + $pos = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); + echo($device['protocol'].":".$device['hostname'].":".$device['port']." - ".$device['community']." ".$device['snmpver'].": "); + if ($pos == '') + { + $status='0'; + } else { + $status='1'; + } + } else { + $status='0'; + } + if ($status == '1') + { + echo("Up\n"); + } else { + echo("Down\n"); + } - if($status == '1') { - echo("Up\n"); - } else { - echo("Down\n"); - } + if ($status != $device['status']) + { + mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'"); - if($status != $device['status']) { - - mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'"); - if ($status == '1') { - $stat = "Up"; - mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')"); - if($config['alerts']['email']['enable']) - { - notify($device, "Device Up: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format'])); - } - } else { - $stat = "Down"; - mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')"); - if($config['alerts']['email']['enable']) - { - notify($device, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format'])); - } - } - eventlog("Device status changed to $stat", $device['device_id']); - echo("Status Changed!\n"); - } + if ($status == '1') + { + $stat = "Up"; + mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')"); + if ($config['alerts']['email']['enable']) + { + notify($device, "Device Up: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format'])); + } + } else { + $stat = "Down"; + mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')"); + if ($config['alerts']['email']['enable']) + { + notify($device, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format'])); + } + } + eventlog("Device status changed to $stat", $device['device_id']); + echo("Status Changed!\n"); + } } -?> + +?> \ No newline at end of file