From e52334f578ee515efb08bb0c5a66a23e185a21ec Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sun, 8 Apr 2007 14:34:19 +0000 Subject: [PATCH] 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 --- html/graph.php | 22 +-- html/includes/print-device-graph.php | 16 +- html/includes/print-menubar.php | 7 +- html/includes/topnav.inc | 8 +- html/pages/default.php | 24 +-- html/pages/device.php | 22 +-- html/pages/device/dev-graphs.inc | 2 +- html/pages/device/dev-overview.inc | 4 +- html/pages/devices.php | 5 +- includes/functions.php | 52 ++---- includes/graphing.php | 14 +- includes/ios.php | 2 +- includes/polling/device-netstats.inc.php | 7 +- includes/polling/temperatures.inc.php | 14 +- includes/procurve.php | 2 +- includes/snom.php | 2 +- includes/unix.php | 191 ----------------------- includes/windows.php | 12 +- poll-device.php | 108 ++++++------- poll-interface.php | 4 +- 20 files changed, 151 insertions(+), 367 deletions(-) diff --git a/html/graph.php b/html/graph.php index a0d04db01..eb34be280 100644 --- a/html/graph.php +++ b/html/graph.php @@ -11,15 +11,15 @@ include("includes/authenticate.inc"); if($_GET['host']) { - $device = $_GET['host']; + $device_id = $_GET['host']; } elseif($_GET['device']) { - $device = $_GET['device']; - } else { - $device = getifhost($_GET['if']); + $device_id = $_GET['device']; + } elseif($_GET['if']) { + $device_id = getifhost($_GET['if']); $ifIndex = getifindexbyid($_GET['if']); } - if($device) { - $hostname = gethostbyid($device); + if($device_id) { + $hostname = gethostbyid($device_id); } $from = $_GET['from']; @@ -33,7 +33,7 @@ $graphfile = $hostname . ".". $ifIndex . "-" . $type . ".png"; - $os = gethostosbyid($device); + $os = gethostosbyid($device_id); switch ($type) { @@ -41,7 +41,7 @@ $graph = graph_global_bits ("global_bits.png", $from, $to, $width, $height); break; case 'device_bits': - $graph = graph_device_bits ($device, $graphfile, $from, $to, $width, $height, $title, $vertical); + $graph = graph_device_bits ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical); break; case 'bits': $graph = trafgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical); @@ -59,7 +59,7 @@ $graph = uptimegraph ($hostname . "-uptime.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical); break; case 'unixfs': - $graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical); + $graph = unixfsgraph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical); break; case 'calls': $graph = callsgraphSNOM ($hostname . "-data.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical); @@ -90,7 +90,7 @@ } break; case 'temp': - $graph = temp_graph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical); + $graph = temp_graph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical); break; case 'mem': if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) { @@ -127,7 +127,7 @@ break; case 'unixfs': if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) { - $graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical); + $graph = unixfsgraph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical); } break; case 'postfix': diff --git a/html/includes/print-device-graph.php b/html/includes/print-device-graph.php index 5a6d1b3c2..900cf48dc 100644 --- a/html/includes/print-device-graph.php +++ b/html/includes/print-device-graph.php @@ -1,16 +1,16 @@ ', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index f7698d3e3..60f35a805 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -7,15 +7,14 @@ $query_a = mysql_query("SELECT * FROM `devices`"); while($device = mysql_fetch_array($query_a)) { - - if($device[status] == 0 && $device[ignore] == '0') { $this_alert = "1"; } elseif($device[ignore] == '0') { + if($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif($device['ignore'] == '0') { if(mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_host = '$device[id]'"),0)) { $this_alert = "1"; } - if(mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '$device[id]'"),0)) { $this_alert = "1"; } + if(mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '" . $device[device_id] . "'"),0)) { $this_alert = "1"; } } if($this_alert) { $device_alerts++; - $device_alert_sql .= " OR `id` = '$device[id]'"; + $device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'"; } unset($this_alert); } diff --git a/html/includes/topnav.inc b/html/includes/topnav.inc index 0769fdcec..8e2e9b0d6 100644 --- a/html/includes/topnav.inc +++ b/html/includes/topnav.inc @@ -1,9 +1,9 @@ '0' AND U.device_uptime < '86400'"); +$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS U WHERE D.device_id = U.device_id AND U.attrib_type = 'uptime' AND U.attrib_value > '0' AND U.attrib_value < '86400'"); while($device = mysql_fetch_array($sql)){ - $rebooted[] = "$device[id]"; + $rebooted[] = "$device[device_id]"; } ?> @@ -20,41 +20,41 @@ while($device = mysql_fetch_array($sql)){ unset($already); $i = 0; while ($i <= count($nodes)) { - $thisnode = "$device[id]"; + $thisnode = $device['device_id']; if ($nodes[$i] == $thisnode) { $already = "yes"; } $i++; } - if(!$already) { $nodes[] = "$device[id]"; } + if(!$already) { $nodes[] = $device['device_id']; } } -$sql = mysql_query("SELECT D.id as `id` FROM `interfaces` AS I, `devices` AS D WHERE I.host = D.id AND up = 'down' AND up_admin = 'up'"); +$sql = mysql_query("SELECT * FROM `interfaces` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up'"); while($device = mysql_fetch_array($sql)){ unset($already); $i = 0; while ($i <= count($nodes)) { - $thisnode = "$device[id]"; + $thisnode = $device['device_id']; if ($nodes[$i] == $thisnode) { $already = "yes"; } $i++; } - if(!$already) { $nodes[] = "$device[id]"; } + if(!$already) { $nodes[] = $device['device_id']; } } -$sql = mysql_query("SELECT D.id as `id` FROM `services` AS S, `devices` AS D WHERE S.service_host = D.id AND service_status = 'down'"); +$sql = mysql_query("SELECT D.device_id FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down'"); while($device = mysql_fetch_array($sql)){ unset($already); $i = 0; while ($i <= count($nodes)) { - $thisnode = "$device[id]"; + $thisnode = $device['device_id']; if ($nodes[$i] == $thisnode) { $already = "yes"; } $i++; } - if(!$already) { $nodes[] = "$device[id]"; } + if(!$already) { $nodes[] = $device['device_id']; } } foreach($nodes as $node) { @@ -63,11 +63,11 @@ foreach($nodes as $node) { $host = gethostbyid($node); - $ints = mysql_result(mysql_query("SELECT count(id) FROM `interfaces` WHERE `up` = 'down' AND `up_admin` = 'up' AND `host` = '$node'"),0); + $ints = mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `device_id` = '$node'"),0); $services = mysql_result(mysql_query("SELECT count(service_id) FROM `services` WHERE `service_status` = '0' AND `service_host` = '$node'"),0); $intlist = array(); - $sql = mysql_query("SELECT `if`, `name` FROM interfaces WHERE `up` = 'down' AND `up_admin` = 'up' AND `host` = '$node'"); + $sql = mysql_query("SELECT `ifDescr`, `ifAlias` FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `device_id` = '$node'"); while($int = mysql_fetch_row($sql)) { $intlist[] = "$int[0] - $int[1]"; } foreach ($intlist as $intname) { $intpop .= "$br $intname"; $br = "
"; } unset($br); diff --git a/html/pages/device.php b/html/pages/device.php index 8761a50b8..0423e9252 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -10,7 +10,7 @@ $sectionx = str_replace("-", "", $section); $select[$sectionx] = "selected"; -$device_query = mysql_query("select * from devices WHERE id = '$_GET[id]'"); +$device_query = mysql_query("select * from devices WHERE `device_id` = '$_GET[id]'"); while($device = mysql_fetch_array($device_query)) { $hostname = $device[hostname]; #$bg="#ffffff"; @@ -23,34 +23,34 @@ echo("
"); echo("
"); } if($interfaces['total']) { diff --git a/html/pages/devices.php b/html/pages/devices.php index 2749e44b8..75f98eff8 100644 --- a/html/pages/devices.php +++ b/html/pages/devices.php @@ -1,15 +1,12 @@ ');\" onmouseout=\"return nd();\">$text"; + $link = "');\" onmouseout=\"return nd();\">$text"; return $link; } function generatedevicelink($device, $text=0) { global $twoday; global $now; - if($device['dev_id']) { $id = $device['dev_id']; } else { $id = $device['id']; } $class = devclass($device); - if(!$text) { $text = $device[hostname]; } - $graph_url = "graph.php?host=$id&from=$twoday&to=$now&width=400&height=120&type=cpu"; - $link = "');\" onmouseout=\"return nd();\">$text"; + if(!$text) { $text = $device['hostname']; } + $graph_url = "graph.php?host=" . $device[device_id] . "&from=$twoday&to=$now&width=400&height=120&type=cpu"; + $link = "');\" onmouseout=\"return nd();\">$text"; return $link; } @@ -85,7 +84,7 @@ function devclass($device) { function getImage($host) { -$sql = "SELECT * FROM `devices` WHERE `id` = '$host'"; +$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; $data = mysql_fetch_array(mysql_query($sql)); $type = strtolower($data['os']); @@ -108,8 +107,8 @@ $type = strtolower($data['os']); function delHost($id) { - $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE id = '$id'"), 0); - mysql_query("DELETE FROM `devices` WHERE `id` = '$id'"); + $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); + mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'"); $int_query = mysql_query("SELECT * FROM `interfaces` WHERE `host` = '$id'"); while($int_data = mysql_fetch_array($int_query)) { $int_if = $int_data['if']; @@ -123,7 +122,7 @@ function delHost($id) { mysql_query("DELETE FROM `storage` WHERE `host_id` = '$id'"); mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'"); - mysql_query("DELETE FROM `interfaces` WHERE `host` = '$id'"); + mysql_query("DELETE FROM `interfaces` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'"); `rm -f rrd/$host-*.rrd`; echo("Removed device $host
"); @@ -282,12 +281,12 @@ function isValidInterface($if) { } else { return 0; } } -function ifclass($up, $up_admin) { +function ifclass($ifOperStatus, $ifAdminStatus) { $ifclass = "interface-upup"; - if ($up_admin == "down") { $ifclass = "interface-admindown"; } - if ($up_admin == "up" && $up == "down") { $ifclass = "interface-updown"; } - if ($up_admin == "up" && $up == "up") { $ifclass = "interface-upup"; } + if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } + if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } + if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } return $ifclass; } @@ -939,37 +938,18 @@ function createHost ($host, $community, $snmpver){ } } -function createInterface ($host, $if, $ifIndex, $up,$up_admin,$speed,$duplex,$mac,$name){ - $sql = "INSERT INTO `interfaces` (`host`,`if`,`ifIndex`, `up`,`up_admin`,`speed`,`duplex`,`mac`,`name`)"; - $sql = $sql . " VALUES ('$host', '$if','$ifIndex','$up','$up_admin','$speed','$duplex','$mac',\"$name\")"; - mysql_query($sql); -} - -function updateInterfaceStatus ($id,$ifOperStatus,$ifAdminStatus,$speed,$duplex,$mac,$ifAlias) { - $sql = "UPDATE `interfaces` SET `up` = '$ifOperStatus', `up_admin` = '$ifAdminStatus', `speed` = '$speed', "; - $sql .= "`duplex` = '$duplex', `mac` = '$mac', `name` = \"$ifAlias\" WHERE `id` = '$id'"; - mysql_query($sql); - echo("$sql\n"); -} - -function updateInterface ($host, $if, $ifIndex, $up, $up_admin, $speed, $duplex, $mac, $name){ - $sql = "UPDATE `interfaces` SET `up` = '$up',`up_admin` = '$up_admin',`speed` = '$speed',`duplex` = '$duplex',`mac` = '$mac',`name` = \"$name\""; - $sql .= " WHERE `host` = '$host' AND `if` = '$if'"; - mysql_query($sql); -} - function isDomainResolves($domain){ return gethostbyname($domain) != $domain; } function hoststatus($id) { - $sql = mysql_query("SELECT `status` FROM `devices` WHERE `id` = '$id'"); + $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); $result = @mysql_result($sql, 0); return $result; } function gethostbyid($id) { - $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `id` = '$id'"); + $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); $result = @mysql_result($sql, 0); return $result; } @@ -993,13 +973,13 @@ function getifbyid($id) { } function getidbyname($domain){ - $sql = mysql_query("SELECT `id` FROM `devices` WHERE `hostname` = '$domain'"); + $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); $result = @mysql_result($sql, 0); return $result; } function gethostosbyid($id) { - $sql = mysql_query("SELECT `os` FROM `devices` WHERE `id` = '$id'"); + $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); $result = @mysql_result($sql, 0); return $result; } diff --git a/includes/graphing.php b/includes/graphing.php index c96b79e75..55e967005 100644 --- a/includes/graphing.php +++ b/includes/graphing.php @@ -12,18 +12,18 @@ function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vert $iter = "1"; $sql = mysql_query("SELECT * FROM temperature where temp_host = '$device'"); $optsa[] = "COMMENT: Cur Max"; - while($fs = mysql_fetch_array($sql)) { + while($temperature = mysql_fetch_array($sql)) { if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE"; } elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D"; } elseif($iter=="7") {$colour="FF0084"; unset($iter); } - $fs[temp_descr] = str_pad($fs[temp_descr], 28); - $fs[temp_descr] = substr($fs[temp_descr],0,28); + $temperature['temp_descr'] = str_pad($temperature['temp_descr'], 28); + $temperature['temp_descr'] = substr($temperature['temp_descr'],0,28); - $optsa[] = "DEF:temp$fs[temp_id]=rrd/$hostname-temp$fs[temp_id].rrd:temp:AVERAGE"; - $optsa[] = "LINE1:temp$fs[temp_id]#" . $colour . ":$fs[temp_descr]"; - $optsa[] = "GPRINT:temp$fs[temp_id]:LAST:%3.0lf°C"; - $optsa[] = "GPRINT:temp$fs[temp_id]:MAX:%3.0lf°C\l"; + $optsa[] = "DEF:temp" . $temperature[temp_id] . "=rrd/" . $hostname . "-temp-" . $temperature['temp_id'] . ".rrd:temp:AVERAGE"; + $optsa[] = "LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":" . $temperature[temp_descr]; + $optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lf°C"; + $optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf°C\l"; $iter++; } if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font", diff --git a/includes/ios.php b/includes/ios.php index 854c5d1ff..5576c66ca 100755 --- a/includes/ios.php +++ b/includes/ios.php @@ -4,7 +4,7 @@ function pollDeviceIOS() { global $device; global $community; - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $hardware = $device['hardware']; $version = $device['version']; diff --git a/includes/polling/device-netstats.inc.php b/includes/polling/device-netstats.inc.php index 67fa7cdeb..d573a18f5 100755 --- a/includes/polling/device-netstats.inc.php +++ b/includes/polling/device-netstats.inc.php @@ -7,7 +7,7 @@ $oids = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests',' 'tcpEstabResets','tcpInSegs','tcpOutSegs','tcpRetransSegs','udpInDatagrams','udpOutDatagrams','udpInErrors', 'udpNoPorts'); -$rrdfile = "rrd/" . $hostname . "-netinfo.rrd"; +$rrdfile = "rrd/" . $device['hostname'] . "-netinfo.rrd"; $rrd_create = "rrdtool create $rrdfile "; $rrd_create .= "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ @@ -22,7 +22,8 @@ foreach($oids as $oid){ if(!file_exists($rrdfile)) { `$rrd_create`; } -$snmpdata = trim(`snmpget -O qv -$snmpver -c $community $hostname $snmpstring`); +$snmpdata_cmd = "snmpbulkget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " $snmpstring"; +$snmpdata = trim(`$snmpdata_cmd`); $rrdupdate = "N"; @@ -31,8 +32,6 @@ foreach(explode("\n", $snmpdata) as $data) { $rrdupdate .= ":$data"; } -echo("\n$rrdfile $rrdupdate\n"); - rrd_update($rrdfile, $rrdupdate); rrd_error(); diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index e88a33553..174663612 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -1,17 +1,19 @@ $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"); } } diff --git a/poll-interface.php b/poll-interface.php index 0b80ef504..295d09480 100755 --- a/poll-interface.php +++ b/poll-interface.php @@ -7,7 +7,7 @@ include("includes/functions.php"); $interface_query = mysql_query("SELECT * FROM `interfaces`"); while ($interface = mysql_fetch_array($interface_query)) { - $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '" . $interface['device_id'] . "'")); + $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'")); if($device['status'] == '1') { $snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifName." . $interface['ifIndex']; @@ -15,8 +15,6 @@ while ($interface = mysql_fetch_array($interface_query)) { $snmp_cmd .= "ifAlias." . $interface['ifIndex'] . " ifSpeed." . $interface['ifIndex'] . " 1.3.6.1.2.1.10.7.2.1." . $interface['ifIndex']; $snmp_cmd .= " ifType." . $interface['ifIndex'] . " ifMtu." . $interface['ifIndex'] . " ifPhysAddress." . $interface['ifIndex']; - echo($snmp_cmd); - $snmp_output = trim(`$snmp_cmd`); $snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output); $snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);