mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
Changed id field in devices table to device_id (!!!1!!1!!eleven!1)
git-svn-id: http://www.observium.org/svn/observer/trunk@69 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+52
-56
@@ -4,34 +4,29 @@
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `id` like '%$argv[1]' AND `ignore` = '0' ORDER BY `id` ASC");
|
||||
$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)) {
|
||||
$hostname = $device['hostname'];
|
||||
$id = $device['id'];
|
||||
$status = $device['status'];
|
||||
$community = $device['community'];
|
||||
$snmpver = $device['snmpver'];
|
||||
|
||||
unset($update); unset($update_query); unset($seperator); unset($newversion); unset($newuptime); unset($newfeatures);
|
||||
unset($newlocation); unset($newhardware);
|
||||
$pingable = isPingable($hostname);
|
||||
$pingable = isPingable($device['hostname']);
|
||||
$snmpable = FALSE;
|
||||
if($pingable) {
|
||||
$snmpable = isSNMPable($hostname, $community, $snmpver);
|
||||
}
|
||||
if ($pingable !== FALSE && $snmpable !== FALSE ) {
|
||||
|
||||
$newstatus = '1';
|
||||
$hardware = $device['hardware'];
|
||||
$version = $device['version'];
|
||||
$old_rebooted = $device['rebooted'];
|
||||
$features = $device['features'];
|
||||
$location = $device['location'];
|
||||
$old_sysDescr = $device['sysDescr'];
|
||||
$os = $device['os'];
|
||||
if($os == "FreeBSD" || $os == "OpenBSD" || $os == "Linux" || $os == "Windows") { $uptimeoid = ".1.3.6.1.2.1.25.1.1.0"; } else { $uptimeoid = "1.3.6.1.2.1.1.3.0"; }
|
||||
if($device['monowall']) { $uptimeoid = ".1.3.6.1.2.1.1.3.0"; }
|
||||
$snmp = "$uptimeoid sysLocation.0 .1.3.6.1.2.1.47.1.1.1.1.13.1 sysDescr.0";
|
||||
$snmpdata = `snmpget -O qv -$snmpver -c $community $hostname $snmp | grep -v "Cisco Internetwork Operating System Software"`;
|
||||
if($pingable) {
|
||||
$snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver']);
|
||||
}
|
||||
|
||||
if ($pingable !== FALSE && $snmpable !== FALSE ) {
|
||||
$status = '1';
|
||||
if($device['os'] == "FreeBSD" || $device['os'] == "OpenBSD" || $device['os'] == "Linux" || $device['os'] == "Windows") {
|
||||
$uptimeoid = ".1.3.6.1.2.1.25.1.1.0";
|
||||
} else {
|
||||
$uptimeoid = "1.3.6.1.2.1.1.3.0";
|
||||
}
|
||||
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
|
||||
$snmp_cmd .= " $uptimeoid sysLocation.0 .1.3.6.1.2.1.47.1.1.1.1.13.1 sysDescr.0";
|
||||
$snmp_cmd .= " | grep -v 'Cisco Internetwork Operating System Software'";
|
||||
$snmpdata = `$snmp_cmd`;
|
||||
$snmpdata = preg_replace("/^.*IOS/","", $snmpdata);
|
||||
$snmpdata = trim($snmpdata);
|
||||
list($sysUptime, $sysLocation, $ciscomodel, $sysDescr) = explode("\n", $snmpdata);
|
||||
@@ -45,7 +40,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$secs = $secs + ($mins * 60);
|
||||
$newuptime = $secs;
|
||||
|
||||
switch ($os) {
|
||||
switch ($device['os']) {
|
||||
case "FreeBSD":
|
||||
case "DragonFly":
|
||||
case "OpenBSD":
|
||||
@@ -54,39 +49,40 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
case "Voswall":
|
||||
case "NetBSD":
|
||||
case "pfSense":
|
||||
if($os == "FreeBSD") {
|
||||
if($device['os'] == "FreeBSD") {
|
||||
$sysDescr = str_replace(" 0 ", " ", $sysDescr);
|
||||
list(,,$newversion) = explode (" ", $sysDescr);
|
||||
$newhardware = "i386";
|
||||
$newfeatures = "GENERIC";
|
||||
} elseif($os == "DragonFly") {
|
||||
} elseif($device['os'] == "DragonFly") {
|
||||
list(,,$newversion,,,$newfeatures,,$newhardware) = explode (" ", $sysDescr);
|
||||
} elseif($os == "NetBSD") {
|
||||
} elseif($device['os'] == "NetBSD") {
|
||||
list(,,$newversion,,,$newfeatures) = explode (" ", $sysDescr);
|
||||
$newfeatures = str_replace("(", "", $newfeatures);
|
||||
$newfeatures = str_replace(")", "", $newfeatures);
|
||||
list(,,$newhardware) = explode ("$newfeatures", $sysDescr);
|
||||
} elseif($os == "OpenBSD") {
|
||||
} elseif($device['os'] == "OpenBSD") {
|
||||
list(,,$newversion,$newfeatures,$newhardware) = explode (" ", $sysDescr);
|
||||
$newfeatures = str_replace("(", "", $newfeatures);
|
||||
$newfeatures = str_replace(")", "", $newfeatures);
|
||||
} elseif($os == "m0n0wall" || $os == "Voswall") {
|
||||
} 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);
|
||||
} elseif ($os == "Linux") {
|
||||
} 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);
|
||||
$newfeatures = `snmpget -O qv -$snmpver -c $community $hostname .1.3.6.1.4.1.2021.7890.1.101.1`;
|
||||
$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);
|
||||
}
|
||||
pollDeviceUnix();
|
||||
include("includes/polling/device-unix.inc.php");
|
||||
break;
|
||||
case "Windows":
|
||||
if($os == "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"; }
|
||||
@@ -95,7 +91,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
pollDeviceWin();
|
||||
break;
|
||||
case "IOS":
|
||||
if ($os == "IOS") {
|
||||
if ($device['os'] == "IOS") {
|
||||
$newversion = str_replace("Cisco IOS Software,", "", $sysDescr);
|
||||
$newversion = str_replace("IOS (tm) ", "", $newversion);
|
||||
$newversion = str_replace(",RELEASE SOFTWARE", "", $newversion);
|
||||
@@ -132,7 +128,8 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
pollDeviceHP();
|
||||
break;
|
||||
case "Snom":
|
||||
$sysDescr = `snmpget -Oqv -$snmpver -c $community $hostname 1.3.6.1.2.1.7526.2.4`;
|
||||
$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);
|
||||
@@ -144,55 +141,54 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
$newlocation = str_replace("\"","", $sysLocation);
|
||||
|
||||
include("includes/polling/temperatures.inc.php");
|
||||
|
||||
include("includes/polling/device-netstats.inc.php");
|
||||
|
||||
} else {
|
||||
$newstatus = '0';
|
||||
}
|
||||
|
||||
if ( $sysDescr && $sysDescr != $old_sysDescr ) {
|
||||
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
|
||||
$update = "`sysDescr` = '$sysDescr'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'New sysDescr - $sysDescr')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
|
||||
}
|
||||
if ( $newlocation && $location != $newlocation ) {
|
||||
if ( $newlocation && $device['location'] != $newlocation ) {
|
||||
$update = "`location` = '$newlocation'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed location from $location to $newlocation')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $newlocation')");
|
||||
}
|
||||
if ( $newversion && $version != $newversion ) {
|
||||
if ( $newversion && $device['version'] != $newversion ) {
|
||||
$update .= $seperator . "`version` = '$newversion'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed version from $version to $newversion')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $newversion')");
|
||||
}
|
||||
if ( $newfeatures && $newfeatures != $features ) {
|
||||
if ( $newfeatures && $newfeatures != $device['features'] ) {
|
||||
$update .= $seperator . "`features` = '$newfeatures'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed features from $features to $newfeatures')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $newfeatures')");
|
||||
}
|
||||
if ( $newhardware && $newhardware != $hardware ) {
|
||||
if ( $newhardware && $newhardware != $device['hardware'] ) {
|
||||
$update .= $seperator . "`hardware` = '$newhardware'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed hardware from $hardware to $newhardware')");
|
||||
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Hardware -> $newhardware')");
|
||||
}
|
||||
|
||||
if( $status != $newstatus ) {
|
||||
if( $device['status'] != $newstatus ) {
|
||||
$update .= $seperator . "`status` = '$newstatus'";
|
||||
$seperator = ", ";
|
||||
if ($newstatus == '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')");
|
||||
}
|
||||
|
||||
if ($newuptime) {
|
||||
echo("Uptime : $newuptime\n");
|
||||
|
||||
$uptimerrd = "rrd/" . $hostname . "-uptime.rrd";
|
||||
$uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
|
||||
if(!is_file($uptimerrd)) {
|
||||
$woo = `rrdtool create $uptimerrd \
|
||||
DS:uptime:GAUGE:600:0:U \
|
||||
@@ -203,9 +199,9 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
}
|
||||
rrd_update($uptimerrd, "N:$newuptime");
|
||||
|
||||
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$newuptime' WHERE `device_id` = '$id' AND `attrib_type` = 'uptime'");
|
||||
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$newuptime' 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 ('$id', 'uptime', '$newuptime')");
|
||||
$insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . $device['device_id'] . "', 'uptime', '$newuptime')");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,11 +209,11 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
if ($update) {
|
||||
$update_query = "UPDATE `devices` SET ";
|
||||
$update_query .= $update;
|
||||
$update_query .= " WHERE `id` = '$id'";
|
||||
echo("Updating $hostname\n$update_query\n\n");
|
||||
$update_query .= " WHERE `id` = '" . $device['device_id'] . "'";
|
||||
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n\n");
|
||||
$update_result = mysql_query($update_query);
|
||||
} else {
|
||||
echo("No Changes to $hostname \n\n");
|
||||
echo("No Changes to " . $device['hostname'] . "\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user