Files
librenms-librenms/poll-reachability.php
T

65 lines
2.1 KiB
PHP
Raw Normal View History

2010-09-03 18:26:59 +00:00
#!/usr/bin/env php
2009-09-07 11:07:59 +00:00
<?php
2007-04-03 14:10:23 +00:00
include("includes/defaults.inc.php");
2007-04-03 14:10:23 +00:00
include("config.php");
include("includes/functions.php");
2009-03-17 20:26:29 +00:00
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' AND disabled = '0' ORDER BY `device_id` DESC");
2007-04-03 14:10:23 +00:00
while ($device = mysql_fetch_array($device_query)) {
2007-04-08 21:27:05 +00:00
$id = $device['device_id'];
2007-04-03 14:10:23 +00:00
$hostname = $device['hostname'];
$old_status = $device['status'];
$community = $device['community'];
$snmpver = $device['snmpver'];
$port = $device['port'];
2007-04-03 14:10:23 +00:00
2009-07-31 10:53:54 +00:00
echo("$hostname ");
2007-04-03 14:10:23 +00:00
2008-03-17 00:24:06 +00:00
$status = shell_exec($config['fping'] . " $hostname | cut -d ' ' -f 3");
2007-04-03 14:10:23 +00:00
$status = trim($status);
2007-04-09 13:14:03 +00:00
if(strstr($status, "alive")) {
2009-04-23 21:13:56 +00:00
$pos = shell_exec($config['snmpget'] . " -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysDescr.0");
echo($config['snmpget'] . " -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysDescr.0");
2007-04-03 14:10:23 +00:00
if($pos == '') {
$status='0';
} else {
$status='1';
}
} else {
$status='0';
}
2009-07-31 10:53:54 +00:00
if($status == '1') {
echo("Up\n");
} else {
echo("Down\n");
}
2007-04-08 21:27:05 +00:00
if($status != $device['status']) {
2007-04-08 21:27:05 +00:00
mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'");
2007-04-03 14:10:23 +00:00
if ($status == '1') {
$stat = "Up";
2007-04-08 21:27:05 +00:00
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']));
}
2007-04-03 14:10:23 +00:00
} else {
2009-07-31 10:53:54 +00:00
$stat = "Down";
2007-04-08 21:27:05 +00:00
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']));
}
2007-04-03 14:10:23 +00:00
}
eventlog("Device status changed to $stat", $device['device_id']);
2007-04-03 14:10:23 +00:00
echo("Status Changed!\n");
}
}
?>