mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Updating polling system
git-svn-id: http://www.observium.org/svn/observer/trunk@75 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -5,7 +5,7 @@ include("config.php");
|
||||
include("includes/functions.php");
|
||||
include("includes/cdp.php");
|
||||
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `status` = '1' AND `os` = 'IOS' ORDER BY `id` DESC");
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `status` = '1' AND `os` = 'IOS' ORDER BY `device_id` DESC");
|
||||
|
||||
while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
|
@@ -1,9 +1,5 @@
|
||||
<?php
|
||||
# ini_set('display_errors', 1);
|
||||
# ini_set('display_startup_errors', 1);
|
||||
# ini_set('log_errors', 1);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
# ini_set('error_reporting', E_ALL);
|
||||
|
||||
include("../config.php");
|
||||
include("../includes/functions.php");
|
||||
|
@@ -1,57 +1,47 @@
|
||||
<?php
|
||||
|
||||
$sql = "select *, I.id as iid, I.ifIndex as ifIndex, D.id as did, D.hostname as hostname, I.if as ifname, I.name as ifalias ";
|
||||
$sql .= "from interfaces as I, devices as D WHERE `name` like 'Cust: %' AND I.host = D.id AND D.hostname LIKE '%" . $mydomain . "' ORDER BY I.name";
|
||||
$sql = "SELECT * FROM `interfaces` AS I, `devices` AS D";
|
||||
$sql .= " WHERE `ifAlias` like 'Cust: %' AND I.device_id = D.device_id AND D.hostname LIKE '%" . $mydomain . "' ORDER BY I.ifAlias";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
|
||||
|
||||
echo("<table border=0 cellspacing=0 cellpadding=2 class=devicetable width=100%>");
|
||||
|
||||
while($data = mysql_fetch_array($query)) {
|
||||
while($interface = mysql_fetch_array($query)) {
|
||||
$device = &$interface;
|
||||
|
||||
unset($class);
|
||||
$iid = $data['iid'];
|
||||
$ifIndex = $data['ifIndex'];
|
||||
$did = $data['did'];
|
||||
$device[id] = $did;
|
||||
$device['hostname'] = $data['hostname'];
|
||||
$hostname = $data['hostname'];
|
||||
$up = $data['up'];
|
||||
$up_admin = $data['up_admin'];
|
||||
$ifname = fixifname($data['ifname']);
|
||||
$ifalias = $data['ifalias'];
|
||||
$ifalias = str_replace("Cust: ", "", $ifalias);
|
||||
$ifalias = str_replace("[PNI]", "Private", $ifalias);
|
||||
$ifclass = ifclass($up, $up_admin);
|
||||
|
||||
$ifname = fixifname($device['ifDescr']);
|
||||
|
||||
$interface['ifAlias'] = str_replace("Cust: ", "", $interface['ifAlias']);
|
||||
$interface['ifAlias'] = str_replace("[PNI]", "Private", $interface['ifAlias']);
|
||||
|
||||
$ifclass = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
|
||||
|
||||
$displayifalias = $ifalias;
|
||||
$ifalias = str_replace(" [","|",$ifalias);
|
||||
$ifalias = str_replace("] (","|",$ifalias);
|
||||
$ifalias = str_replace(" (","||",$ifalias);
|
||||
$ifalias = str_replace("]","|",$ifalias);
|
||||
$ifalias = str_replace(")","|",$ifalias);
|
||||
list($ifalias,$class,$notes) = explode("|", $ifalias);
|
||||
$useifalias = $ifalias;
|
||||
$displayifalias = $device['ifAlias'];
|
||||
$device['ifAlias'] = str_replace(" [","|",$device['ifAlias']);
|
||||
$device['ifAlias'] = str_replace("] (","|",$device['ifAlias']);
|
||||
$device['ifAlias'] = str_replace(" (","||",$device['ifAlias']);
|
||||
$device['ifAlias'] = str_replace("]","|",$device['ifAlias']);
|
||||
$device['ifAlias'] = str_replace(")","|",$device['ifAlias']);
|
||||
list($device['ifAlias'],$class,$notes) = explode("|", $device['ifAlias']);
|
||||
$useifalias = $device['ifAlias'];
|
||||
$used = '1';
|
||||
if ($ifalias == $previfalias) { unset($useifalias );
|
||||
if ($device['ifAlias'] == $previfalias) { unset($useifalias );
|
||||
} elseif ($previfalias) {
|
||||
echo("<tr bgcolor='#ffffff' height='5'><td></td></tr>");
|
||||
if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
|
||||
}
|
||||
$previfalias = $ifalias;
|
||||
|
||||
$mouseoverint = "onmouseover=\"return overlib('<img src=\'graph.php?if=$iid&from=$twoday&to=$now&width=400&height=120&type=bits\'>');\"
|
||||
onmouseout=\"return nd();\"";
|
||||
$mouseoverhost = "onmouseover=\"return overlib('<img src=\'graph.php?host=$did&from=$week&to=$now&width=400&height=120&type=cpu\'>');\"
|
||||
onmouseout=\"return nd();\"";
|
||||
|
||||
$previfalias = $device['ifAlias'];
|
||||
|
||||
echo("
|
||||
<tr bgcolor='$bg'>
|
||||
<td width='7'></td>
|
||||
<td width='250'><span style='font-weight: bold;' class=interface>$useifalias</span></td>
|
||||
<td width='200'>" . generatedevicelink($device) . "</td>
|
||||
<td width='100'>" . generateiflink($data, makeshortif($data['if'])) . "</td>
|
||||
<td width='100'>" . generateiflink($interface, makeshortif($interface['ifDescr'])) . "</td>
|
||||
<td>$notes</td>
|
||||
</tr>
|
||||
");
|
||||
|
150
poll-device.php
150
poll-device.php
@@ -7,8 +7,8 @@ include("includes/functions.php");
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` like '%$argv[1]' AND `ignore` = '0' ORDER BY `device_id` ASC");
|
||||
while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
unset($update); unset($update_query); unset($seperator); unset($newversion); unset($newuptime); unset($newfeatures);
|
||||
unset($newlocation); unset($newhardware);
|
||||
unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features);
|
||||
unset($location); unset($hardware);
|
||||
$pingable = isPingable($device['hostname']);
|
||||
$snmpable = FALSE;
|
||||
|
||||
@@ -38,7 +38,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$hours = $hours + ($days * 24);
|
||||
$mins = $mins + ($hours * 60);
|
||||
$secs = $secs + ($mins * 60);
|
||||
$newuptime = $secs;
|
||||
$uptime = $secs;
|
||||
|
||||
switch ($device['os']) {
|
||||
case "FreeBSD":
|
||||
@@ -51,100 +51,95 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
case "pfSense":
|
||||
if($device['os'] == "FreeBSD") {
|
||||
$sysDescr = str_replace(" 0 ", " ", $sysDescr);
|
||||
list(,,$newversion) = explode (" ", $sysDescr);
|
||||
$newhardware = "i386";
|
||||
$newfeatures = "GENERIC";
|
||||
list(,,$version) = explode (" ", $sysDescr);
|
||||
$hardware = "i386";
|
||||
$features = "GENERIC";
|
||||
} elseif($device['os'] == "DragonFly") {
|
||||
list(,,$newversion,,,$newfeatures,,$newhardware) = explode (" ", $sysDescr);
|
||||
list(,,$version,,,$features,,$hardware) = explode (" ", $sysDescr);
|
||||
} elseif($device['os'] == "NetBSD") {
|
||||
list(,,$newversion,,,$newfeatures) = explode (" ", $sysDescr);
|
||||
$newfeatures = str_replace("(", "", $newfeatures);
|
||||
$newfeatures = str_replace(")", "", $newfeatures);
|
||||
list(,,$newhardware) = explode ("$newfeatures", $sysDescr);
|
||||
list(,,$version,,,$features) = explode (" ", $sysDescr);
|
||||
$features = str_replace("(", "", $features);
|
||||
$features = str_replace(")", "", $features);
|
||||
list(,,$hardware) = explode ("$features", $sysDescr);
|
||||
} elseif($device['os'] == "OpenBSD") {
|
||||
list(,,$newversion,$newfeatures,$newhardware) = explode (" ", $sysDescr);
|
||||
$newfeatures = str_replace("(", "", $newfeatures);
|
||||
$newfeatures = str_replace(")", "", $newfeatures);
|
||||
list(,,$version,$features,$hardware) = explode (" ", $sysDescr);
|
||||
$features = str_replace("(", "", $features);
|
||||
$features = str_replace(")", "", $features);
|
||||
} elseif($device['os'] == "m0n0wall" || $device['os'] == "Voswall") {
|
||||
list(,,$newversion,$newhardware,$freebsda, $freebsdb, $arch) = split(" ", $sysDescr);
|
||||
$newfeatures = $freebsda . " " . $freebsdb;
|
||||
$newhardware = "$newhardware ($arch)";
|
||||
$newhardware = str_replace("\"", "", $newhardware);
|
||||
list(,,$version,$hardware,$freebsda, $freebsdb, $arch) = split(" ", $sysDescr);
|
||||
$features = $freebsda . " " . $freebsdb;
|
||||
$hardware = "$hardware ($arch)";
|
||||
$hardware = str_replace("\"", "", $hardware);
|
||||
} elseif ($device['os'] == "Linux") {
|
||||
list(,,$newversion) = explode (" ", $sysDescr);
|
||||
if(strstr($sysDescr, "386")|| strstr($sysDescr, "486")||strstr($sysDescr, "586")||strstr($sysDescr, "686")) { $newhardware = "Generic x86"; }
|
||||
# list($newversion,$newfeatures,$newfeaturesb) = explode("-", $newversion);
|
||||
list(,,$version) = explode (" ", $sysDescr);
|
||||
if(strstr($sysDescr, "386")|| strstr($sysDescr, "486")||strstr($sysDescr, "586")||strstr($sysDescr, "686")) { $hardware = "Generic x86"; }
|
||||
# list($version,$features,$featuresb) = explode("-", $version);
|
||||
$cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.2021.7890.1.101.1";
|
||||
$newfeatures = `$cmd`;
|
||||
$newfeatures = str_replace("No Such Object available on this agent at this OID", "", $newfeatures);
|
||||
$newfeatures = str_replace("\"", "", $newfeatures);
|
||||
$features = `$cmd`;
|
||||
$features = str_replace("No Such Object available on this agent at this OID", "", $features);
|
||||
$features = str_replace("\"", "", $features);
|
||||
}
|
||||
include("includes/polling/device-unix.inc.php");
|
||||
break;
|
||||
case "Windows":
|
||||
if($device['os'] == "Windows") {
|
||||
if(strstr($sysDescr, "x86")) { $newhardware = "Generic x86"; }
|
||||
if(strstr($sysDescr, "Windows Version 5.2")) { $newversion = "2003 Server"; }
|
||||
if(strstr($sysDescr, "Uniprocessor Free")) { $newfeatures = "Uniprocessor"; }
|
||||
if(strstr($sysDescr, "Multiprocessor Free")) { $newfeatures = "Multiprocessor"; }
|
||||
if(strstr($sysDescr, "x86")) { $hardware = "Generic x86"; }
|
||||
if(strstr($sysDescr, "Windows Version 5.2")) { $version = "2003 Server"; }
|
||||
if(strstr($sysDescr, "Uniprocessor Free")) { $features = "Uniprocessor"; }
|
||||
if(strstr($sysDescr, "Multiprocessor Free")) { $features = "Multiprocessor"; }
|
||||
}
|
||||
pollDeviceWin();
|
||||
break;
|
||||
case "IOS":
|
||||
if ($device['os'] == "IOS") {
|
||||
$newversion = str_replace("Cisco IOS Software,", "", $sysDescr);
|
||||
$newversion = str_replace("IOS (tm) ", "", $newversion);
|
||||
$newversion = str_replace(",RELEASE SOFTWARE", "", $newversion);
|
||||
$newversion = str_replace(",MAINTENANCE INTERIM SOFTWARE", "", $newversion);
|
||||
$newversion = str_replace("Version ","", $newversion);
|
||||
$newversion = str_replace("Cisco Internetwork Operating System Software", "", $newversion);
|
||||
$newversion = trim($newversion);
|
||||
list($newversion) = explode("\n", $newversion);
|
||||
$newversion = preg_replace("/^[A-Za-z0-9\ \_]*\(([A-Za-z0-9\-\_]*)\), (.+), .*/", "\\1|\\2", $newversion);
|
||||
$newversion = str_replace("-M|", "|", $newversion);
|
||||
$newversion = str_replace("-", "|", $newversion);
|
||||
list($newhardware, $newfeatures, $newversion) = explode("|", $newversion);
|
||||
$newfeatures = fixIOSFeatures($newfeatures);
|
||||
#$newhardware = fixIOSHardware($newhardware);
|
||||
$version = str_replace("Cisco IOS Software,", "", $sysDescr);
|
||||
$version = str_replace("IOS (tm) ", "", $version);
|
||||
$version = str_replace(",RELEASE SOFTWARE", "", $version);
|
||||
$version = str_replace(",MAINTENANCE INTERIM SOFTWARE", "", $version);
|
||||
$version = str_replace("Version ","", $version);
|
||||
$version = str_replace("Cisco Internetwork Operating System Software", "", $version);
|
||||
$version = trim($version);
|
||||
list($version) = explode("\n", $version);
|
||||
$version = preg_replace("/^[A-Za-z0-9\ \_]*\(([A-Za-z0-9\-\_]*)\), (.+), .*/", "\\1|\\2", $version);
|
||||
$version = str_replace("-M|", "|", $version);
|
||||
$version = str_replace("-", "|", $version);
|
||||
list($hardware, $features, $version) = explode("|", $version);
|
||||
$features = fixIOSFeatures($features);
|
||||
#$hardware = fixIOSHardware($hardware);
|
||||
$ciscomodel = str_replace("\"", "", $ciscomodel);
|
||||
if(strstr($ciscomodel, "OID")){ unset($ciscomodel); }
|
||||
echo("\n|$ciscomodel|$newhardware\n");
|
||||
echo("\n|$ciscomodel|$hardware\n");
|
||||
if(!strstr($ciscomodel, " ") && strlen($ciscomodel) >= '3') {
|
||||
echo("$ciscomodel");
|
||||
$newhardware = $ciscomodel;
|
||||
$hardware = $ciscomodel;
|
||||
}
|
||||
|
||||
}
|
||||
pollDeviceIOS();
|
||||
include("includes/polling/device-ios.inc.php");
|
||||
break;
|
||||
case "ProCurve":
|
||||
$sysDescr = str_replace(", ", ",", $sysDescr);
|
||||
list($newhardware, $newfeatures, $newversion) = explode(",", $sysDescr);
|
||||
list($newversion) = explode("(", $newversion);
|
||||
list($hardware, $features, $version) = explode(",", $sysDescr);
|
||||
list($version) = explode("(", $version);
|
||||
if(!strstr($ciscomodel, " ")) {
|
||||
echo("$ciscomodel");
|
||||
$newhardware = str_replace("\"", "", $ciscomodel);
|
||||
$hardware = str_replace("\"", "", $ciscomodel);
|
||||
}
|
||||
include("includes/polling/device-procurve.inc.php");
|
||||
break;
|
||||
case "Snom":
|
||||
$cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.2.1.7526.2.4";
|
||||
$sysDescr = `$cmd`;
|
||||
$sysDescr = str_replace("-", " ", $sysDescr);
|
||||
$sysDescr = str_replace("\"", "", $sysDescr);
|
||||
list($newhardware, $newfeatures, $newversion) = explode(" ", $sysDescr);
|
||||
pollDeviceSnom();
|
||||
include("includes/polling/device-snom.inc.php");
|
||||
break;
|
||||
default:
|
||||
pollDevice();
|
||||
}
|
||||
$newlocation = str_replace("\"","", $sysLocation);
|
||||
$location = str_replace("\"","", $sysLocation);
|
||||
|
||||
include("includes/polling/temperatures.inc.php");
|
||||
include("includes/polling/device-netstats.inc.php");
|
||||
|
||||
} else {
|
||||
$newstatus = '0';
|
||||
$status = '0';
|
||||
}
|
||||
|
||||
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
|
||||
@@ -152,31 +147,31 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
|
||||
}
|
||||
if ( $newlocation && $device['location'] != $newlocation ) {
|
||||
$update = "`location` = '$newlocation'";
|
||||
if ( $location && $device['location'] != $location ) {
|
||||
$update = "`location` = '$location'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $newlocation')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $location')");
|
||||
}
|
||||
if ( $newversion && $device['version'] != $newversion ) {
|
||||
$update .= $seperator . "`version` = '$newversion'";
|
||||
if ( $version && $device['version'] != $version ) {
|
||||
$update .= $seperator . "`version` = '$version'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $newversion')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $version')");
|
||||
}
|
||||
if ( $newfeatures && $newfeatures != $device['features'] ) {
|
||||
$update .= $seperator . "`features` = '$newfeatures'";
|
||||
if ( $features && $features != $device['features'] ) {
|
||||
$update .= $seperator . "`features` = '$features'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $newfeatures')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $features')");
|
||||
}
|
||||
if ( $newhardware && $newhardware != $device['hardware'] ) {
|
||||
$update .= $seperator . "`hardware` = '$newhardware'";
|
||||
if ( $hardware && $hardware != $device['hardware'] ) {
|
||||
$update .= $seperator . "`hardware` = '$hardware'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Hardware -> $newhardware')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Hardware -> $hardware')");
|
||||
}
|
||||
|
||||
if( $device['status'] != $newstatus ) {
|
||||
$update .= $seperator . "`status` = '$newstatus'";
|
||||
if( $device['status'] != $status ) {
|
||||
$update .= $seperator . "`status` = '$status'";
|
||||
$seperator = ", ";
|
||||
if ($newstatus == '1') { $stat = "Up";
|
||||
if ($status == '1') { $stat = "Up";
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')");
|
||||
} else {
|
||||
$stat = "Down";
|
||||
@@ -185,8 +180,9 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to $stat')");
|
||||
}
|
||||
|
||||
if ($newuptime) {
|
||||
echo("Uptime : $newuptime\n");
|
||||
|
||||
if ($uptime) {
|
||||
echo("Uptime : $uptime\n");
|
||||
|
||||
$uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
|
||||
if(!is_file($uptimerrd)) {
|
||||
@@ -197,11 +193,11 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
RRA:AVERAGE:0.5:24:775 \
|
||||
RRA:AVERAGE:0.5:288:797`;
|
||||
}
|
||||
rrd_update($uptimerrd, "N:$newuptime");
|
||||
rrd_update($uptimerrd, "N:$uptime");
|
||||
|
||||
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$newuptime' WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'");
|
||||
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$uptime' WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'");
|
||||
if(mysql_affected_rows() == '0') {
|
||||
$insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . $device['device_id'] . "', 'uptime', '$newuptime')");
|
||||
$insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . $device['device_id'] . "', 'uptime', '$uptime')");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +205,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
if ($update) {
|
||||
$update_query = "UPDATE `devices` SET ";
|
||||
$update_query .= $update;
|
||||
$update_query .= " WHERE `id` = '" . $device['device_id'] . "'";
|
||||
$update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'";
|
||||
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n\n");
|
||||
$update_result = mysql_query($update_query);
|
||||
} else {
|
||||
|
@@ -4,10 +4,10 @@
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
$device_query = mysql_query("SELECT id,hostname,os,community,snmpver FROM `devices` WHERE `id` LIKE '%" . $argv[1] . "' AND status = '1' ORDER BY id DESC");
|
||||
$device_query = mysql_query("SELECT device_id,hostname,os,community,snmpver FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' AND status = '1' ORDER BY device_id DESC");
|
||||
while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
$id = $device['id'];
|
||||
$id = $device['device_id'];
|
||||
$hostname = $device['hostname'];
|
||||
$old_os = $device['os'];
|
||||
$community = $device['community'];
|
||||
|
@@ -7,16 +7,16 @@
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
$device_query = mysql_query("SELECT id,hostname,status,community,snmpver FROM `devices` WHERE `id` LIKE '%" . $argv[1] . "' ORDER BY `id` DESC");
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' ORDER BY `device_id` DESC");
|
||||
while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
$id = $device['id'];
|
||||
$id = $device['device_id'];
|
||||
$hostname = $device['hostname'];
|
||||
$old_status = $device['status'];
|
||||
$community = $device['community'];
|
||||
$snmpver = $device['snmpver'];
|
||||
|
||||
echo("- > $hostname\n");
|
||||
echo("$hostname\n");
|
||||
|
||||
$status = `$fping $hostname | cut -d " " -f 3`;
|
||||
$status = trim($status);
|
||||
@@ -34,19 +34,17 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$status='0';
|
||||
}
|
||||
|
||||
echo("$old_status => $status \n");
|
||||
|
||||
|
||||
if($status != $old_status) {
|
||||
mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `id` = '$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', '$id', 'Device is up\n')");
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')");
|
||||
} else {
|
||||
$stat = "Down";
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '$id', 'Device is down\n')");
|
||||
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')");
|
||||
}
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Device status changed to $stat')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to $stat')");
|
||||
echo("Status Changed!\n");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user