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
|
|
|
|
2010-02-27 14:44:38 +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");
|
2011-03-17 11:12:32 +00:00
|
|
|
|
|
|
|
while ($device = mysql_fetch_array($device_query))
|
|
|
|
{
|
|
|
|
$port = $device['port'];
|
|
|
|
|
|
|
|
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 ($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 == '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");
|
|
|
|
}
|
2007-04-03 14:10:23 +00:00
|
|
|
}
|
2011-03-17 11:12:32 +00:00
|
|
|
|
|
|
|
?>
|