-
-
+
Overview
");
-if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '$device[id]'"), 0) > '0') {
+if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
echo("
-
-
+
Port Details
-
-
+
Port Graphs
");
}
echo(" -
-
+
Host Graphs
");
-if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '$device[id]'"), 0) > '0') {
+if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '" . $device['device_id'] . "'"), 0) > '0') {
echo("
-
-
+
Service Details
@@ -59,14 +59,14 @@ if(mysql_result(mysql_query("select count(service_id) from services WHERE servic
echo("
-
-
+
Eventlog
");
echo("
-
-
+
Syslog
@@ -75,7 +75,7 @@ echo("
if($_SESSION[userlevel] > "5") {
echo("
-
-
+
Edit Device
diff --git a/html/pages/device/dev-graphs.inc b/html/pages/device/dev-graphs.inc
index 9a7f7c2df..11893fdb4 100644
--- a/html/pages/device/dev-graphs.inc
+++ b/html/pages/device/dev-graphs.inc
@@ -1,6 +1,6 @@
-$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";
diff --git a/html/pages/device/dev-overview.inc b/html/pages/device/dev-overview.inc
index e69005302..c2af5c3d1 100644
--- a/html/pages/device/dev-overview.inc
+++ b/html/pages/device/dev-overview.inc
@@ -4,7 +4,7 @@ $overview = 1;
$id = $_GET[id];
-$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '$_GET[id]'"));
+$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '$_GET[id]'"));
$interfaces['total'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id'"),0);
$interfaces['up'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifOperStatus = 'up'"),0);
@@ -51,7 +51,7 @@ echo("
Total Traffic
" . device_traffic_image($device['id'], 490, 100, $day, $now) . "Total Traffic
" . device_traffic_image($device['device_id'], 490, 100, $day, $now) . ""); } 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 @@ -$query = "SELECT * FROM temperature AS T temp_host = '" . $device[id] . "'"; +$query = "SELECT * FROM temperature WHERE temp_host = '" . $device['device_id'] . "'"; $temp_data = mysql_query($query); while($temperature = mysql_fetch_array($temp_data)) { - $community = $temperature[community]; - $hostname = $temperature[hostname]; - $snmpver = $temperature[snmpver]; - $temp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $temperature['temp_oid']; + echo($temp_cmd); $temp = `$temp_cmd`; - $temprrd = "rrd/" . $temperature[hostname] . "-temp" . $temperature[temp_id] . ".rrd"; + $temprrd = "rrd/" . $device[hostname] . "-temp-" . $temperature[temp_id] . ".rrd"; + $temprrdold = "rrd/" . $device[hostname] . "-temp" . $temperature[temp_id] . ".rrd"; + if (is_file($temprrdold)) { + rename($temprrdold, $temprrd); + } + if (!is_file($temprrd)) { `rrdtool create $temprrd \ --step 300 \ diff --git a/includes/procurve.php b/includes/procurve.php index 9e65fb808..15a5ae8a1 100755 --- a/includes/procurve.php +++ b/includes/procurve.php @@ -6,7 +6,7 @@ function pollDeviceHP() { global $device; global $community; - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $hardware = $device['hardware']; $version = $device['version']; diff --git a/includes/snom.php b/includes/snom.php index 727d1d7a2..318a31e3c 100755 --- a/includes/snom.php +++ b/includes/snom.php @@ -7,7 +7,7 @@ function pollDeviceSNOM() { global $device; global $community; $snmpver = $device['snmpver']; - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $hardware = $device['hardware']; $version = $device['version']; diff --git a/includes/unix.php b/includes/unix.php index cfa8bb7b1..00f558c14 100755 --- a/includes/unix.php +++ b/includes/unix.php @@ -2,194 +2,3 @@ include("unix-graphing.php"); -function pollDeviceUnix() { - global $device; - global $community; - global $rrdtool; - $id = $device['id']; - $hostname = $device['hostname']; - $hardware = $device['hardware']; - $version = $device['version']; - $features = $device['features']; - if($device['apache'] == "1") { $apache = "yes"; } - $loadrrd = "rrd/" . $hostname . "-load.rrd"; - $loadgraph = "public_html/graphs/" . $hostname . "-load.png"; - $cpurrd = "rrd/" . $hostname . "-cpu.rrd"; - $cpugraph = "public_html/graphs/" . $hostname . "-cpu.png"; - $memrrd = "rrd/" . $hostname . "-mem.rrd"; - $memgraph = "public_html/graphs/" . $hostname . "-mem.png"; - $sysrrd = "rrd/" . $hostname . "-sys.rrd"; - $sysgraph = "public_html/graphs/" . $hostname . "-sys.png"; - - ## Check Disks - $dq = mysql_query("SELECT * FROM storage WHERE host_id = '$id'"); - while ($dr = mysql_fetch_array($dq)) { - $hrStorageIndex = $dr['hrStorageIndex']; - $hrStorageAllocationUnits = $dr['hrStorageAllocationUnits']; - $hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize']; - $hrStorageDescr = $dr['hrStorageDescr']; - $used = `snmpget -O qv -v2c -c $community $hostname hrStorageUsed.$hrStorageIndex`; - $used = $used * $hrStorageAllocationUnits; - $perc = $used / $hrStorageSize * 100; - - $filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr)); - $storerrd = "rrd/" . $hostname . "-storage-" . $filedesc . ".rrd"; - if (!is_file($storerrd)) { - `rrdtool create $storerrd \ - --step 300 \ - DS:size:GAUGE:600:0:U \ - DS:used:GAUGE:600:0:U \ - DS:perc:GAUGE:600:0:U \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:800 \ - RRA:AVERAGE:0.5:24:800 \ - RRA:AVERAGE:0.5:288:800 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:800 \ - RRA:MAX:0.5:24:800 \ - RRA:MAX:0.5:288:800`; - } - rrd_update($storerrd, "N:$hrStorageSize:$used:$perc"); - } - - ## Set OIDs - $oid_ssCpuRawUser = ".1.3.6.1.4.1.2021.11.50.0"; - $oid_ssCpuRawNice = ".1.3.6.1.4.1.2021.11.51.0"; - $oid_ssCpuRawSystem = ".1.3.6.1.4.1.2021.11.52.0"; - $oid_ssCpuRawIdle = ".1.3.6.1.4.1.2021.11.53.0"; - $oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0"; - $oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0"; - - $s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers .1.3.6.1.4.1.2021.1.101.1`; - list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users, $cputemp) = explode("\n", $s); - - ## Create CPU RRD if it doesn't already exist - if (!is_file($cpurrd)) { - `rrdtool create $cpurrd \ - --step 300 \ - DS:user:COUNTER:600:0:U \ - DS:system:COUNTER:600:0:U \ - DS:nice:COUNTER:600:0:U \ - DS:idle:COUNTER:600:0:U \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:800 \ - RRA:AVERAGE:0.5:24:800 \ - RRA:AVERAGE:0.5:288:800 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:800 \ - RRA:MAX:0.5:24:800 \ - RRA:MAX:0.5:288:800`; - } - rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle"); - - - ## If the device isn't monowall or pfsense, monitor all the pretty things - if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSense" ) { - if (!is_file($sysrrd)) { - `rrdtool create $sysrrd \ - --step 300 \ - DS:users:GAUGE:600:0:U \ - DS:procs:GAUGE:600:0:U \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:800 \ - RRA:AVERAGE:0.5:24:800 \ - RRA:AVERAGE:0.5:288:800 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:800 \ - RRA:MAX:0.5:24:800 \ - RRA:MAX:0.5:288:800`; - } - - if (!is_file($memrrd)) { - `rrdtool create $memrrd \ - --step 300 \ - DS:totalswap:GAUGE:600:0:10000000000 \ - DS:availswap:GAUGE:600:0:10000000000 \ - DS:totalreal:GAUGE:600:0:10000000000 \ - DS:availreal:GAUGE:600:0:10000000000 \ - DS:totalfree:GAUGE:600:0:10000000000 \ - DS:shared:GAUGE:600:0:10000000000 \ - DS:buffered:GAUGE:600:0:10000000000 \ - DS:cached:GAUGE:600:0:10000000000 \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:800 \ - RRA:AVERAGE:0.5:24:800 \ - RRA:AVERAGE:0.5:288:800 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:800 \ - RRA:MAX:0.5:24:800 \ - RRA:MAX:0.5:288:800`; - } - - if(!is_file($loadrrd)) { - `$rrdtool create $loadrrd \ - --step 300 \ - DS:1min:GAUGE:600:0:5000 \ - DS:5min:GAUGE:600:0:5000 \ - DS:15min:GAUGE:600:0:5000 \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:800 \ - RRA:AVERAGE:0.5:24:800 \ - RRA:AVERAGE:0.5:288:800 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:800 \ - RRA:MAX:0.5:24:800 \ - RRA:MAX:0.5:288:800`; - } - - $mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0"; - $mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`; - list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw); - - $load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3"; - $load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`; - list ($load1, $load5, $load10) = explode ("\n", $load_raw); - - rrd_update($sysrrd, "N:$users:$procs"); - rrd_update($loadrrd, "N:$load1:$load5:$load10"); - rrd_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached"); - - if($device['temp'] = 1) { - $temprrd = "rrd/" . $hostname . "-temp.rrd"; - $cputemp = str_replace("\"", "", $cputemp); - if (!is_file($temprrd)) { - $rrdcreate = `rrdtool create $temprrd --step 300 \ - DS:cputemp:GAUGE:600:-25:125 \ - DS:systemp:GAUGE:600:-25:125 \ - RRA:AVERAGE:0.5:1:2000 \ - RRA:AVERAGE:0.5:6:2000 \ - RRA:AVERAGE:0.5:24:2000 \ - RRA:AVERAGE:0.5:288:2000 \ - RRA:MAX:0.5:1:2000 \ - RRA:MAX:0.5:6:2000 \ - RRA:MAX:0.5:24:2000 \ - RRA:MAX:0.5:288:2000`; - } - rrd_update($temprrd, "N:$cputemp:0"); - } - - - if($apache) { - $apacherrd = "rrd/" . $hostname . "-apache.rrd"; - if(!is_file($apacherrd)) { - $woo= `rrdtool create $apacherrd \ - DS:bits:COUNTER:600:U:10000000 \ - DS:hits:COUNTER:600:U:10000000 \ - RRA:AVERAGE:0.5:1:800 \ - RRA:AVERAGE:0.5:6:700 \ - RRA:AVERAGE:0.5:24:775 \ - RRA:AVERAGE:0.5:288:797 \ - RRA:MAX:0.5:1:800 \ - RRA:MAX:0.5:6:700 \ - RRA:MAX:0.5:24:775 \ - RRA:MAX:0.5:288:797`; - } - - list($ahits,$abits) = explode("\n", `./get-apache.sh $hostname`); - $abits = $abits * 8; - - rrd_update($apacherrd,"N:$abits:$ahits"); - } -} // End Monowall Test - -} diff --git a/includes/windows.php b/includes/windows.php index df5d6eb0c..3dff5a1e2 100755 --- a/includes/windows.php +++ b/includes/windows.php @@ -5,7 +5,7 @@ function pollDeviceWin() { global $device; global $community; global $rrdtool; - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $hardware = $device['hardware']; $version = $device['version']; @@ -23,7 +23,9 @@ function pollDeviceWin() { $oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0"; $oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0"; - $s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers`; + $s_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $s_cmd .= " $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers"; + $s = `$s_cmd`; list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users) = explode("\n", $s); if (!is_file($cpurrd)) { @@ -96,11 +98,13 @@ function pollDeviceWin() { } $mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0"; - $mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`; + $mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $mem_get; + $mem_raw = `$mem_cmd`; list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw); $load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3"; - $load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`; + $load_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $load_get; + $load_raw = `$load_cmd`; list ($load1, $load5, $load10) = explode ("\n", $load_raw); rrd_update($sysrrd, "N:$users:$procs"); diff --git a/poll-device.php b/poll-device.php index f9fd3c372..0c53cc153 100755 --- a/poll-device.php +++ b/poll-device.php @@ -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"); } } 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);