From ad4160c2eabd7d7ee45aff5e3e816a8c22be63cf Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sun, 20 May 2007 19:21:35 +0000 Subject: [PATCH] Foob git-svn-id: http://www.observium.org/svn/observer/trunk@98 61d68cd4-352d-0410-923a-c4978735b2b8 --- discover-cdp.php | 2 +- discover-storage.php | 37 +++++++++-- discover-temperatures.php | 61 ++++++++++++++++-- html/includes/print-interface-graphs.php | 16 ++--- html/includes/print-syslog.inc | 10 +-- html/pages/device.php | 6 +- html/pages/device/dev-overview.inc | 82 ++++++++++++++++++++---- html/pages/device/dev-syslog.inc | 14 +++- includes/functions.php | 10 +++ includes/graphing.php | 8 +-- includes/polling/device-ios.inc.php | 5 -- includes/polling/device-unix.inc.php | 8 ++- includes/polling/temperatures.inc.php | 9 ++- poll-device.php | 69 ++++++++++---------- poll-interface.php | 28 +++++++- process-syslog.php | 6 +- 16 files changed, 275 insertions(+), 96 deletions(-) diff --git a/discover-cdp.php b/discover-cdp.php index eecfe1917..27703c721 100755 --- a/discover-cdp.php +++ b/discover-cdp.php @@ -42,7 +42,7 @@ while ($device = mysql_fetch_array($device_query)) { $ip = gethostbyname($dst_host); if ( match_network($nets, $ip) ) { if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$dst_host'"), 0) == '0' ) { - createHost ($dst_host); + createHost ($dst_host, $community, "v2c"); } else { #echo("Already got host $dst_host\n"); } diff --git a/discover-storage.php b/discover-storage.php index b84fbb608..41c88d891 100755 --- a/discover-storage.php +++ b/discover-storage.php @@ -3,9 +3,9 @@ include("config.php"); include("includes/functions.php"); -$device_query = mysql_query("SELECT * FROM `devices` WHERE os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' AND monowall = '0' AND status = '1'"); +$device_query = mysql_query("SELECT * FROM `devices` WHERE os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' AND status = '1'"); while ($device = mysql_fetch_array($device_query)) { - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $community = $device['community']; echo("\n***$hostname***\n"); @@ -13,19 +13,46 @@ while ($device = mysql_fetch_array($device_query)) { $oids = trim($oids); foreach(explode("\n", $oids) as $data) { $data = trim($data); - list($oid,$ifIndex) = explode(" ", $data); + list($oid,$hrStorageIndex) = explode(" ", $data); $temp = `snmpget -O qv -v2c -c $community $hostname hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid`; $temp = trim($temp); list($descr, $units, $size, $type) = explode("\n", $temp); list($units) = explode(" ", $units); if(strstr($type, "FixedDisk") && $size > '0') { echo("$oid,$descr,$units,$size\n"); - if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$ifIndex' AND host_id = '$id'"),0) == '0') { - $query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) values ('$id', '$ifIndex', '$descr', '$size', '$units')"; + if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"),0) == '0') { + $query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')"; echo("$query \n"); mysql_query($query); } + $storage_exists[] = "$id $hrStorageIndex"; } } } + +$sql = "SELECT * FROM storage"; +$query = mysql_query($sql); + +while ($store = mysql_fetch_array($query)) { + + unset($exists); + + $i = 0; + while ($i < count($storage_exists) && !$exists) { + $thisstore = $store['host_id'] . " " . $store['hrStorageIndex']; + if ($storage_exists[$i] == $thisstore) { $exists = 1; echo("Match!"); } + $i++; + echo("$storage_exists[$i] == $thisstore \n"); + } + + if(!$exists) { + echo("Deleting...\n"); +# mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'"); + } + + +} + + + ?> diff --git a/discover-temperatures.php b/discover-temperatures.php index 1d887aefe..b5a68b2a1 100755 --- a/discover-temperatures.php +++ b/discover-temperatures.php @@ -4,17 +4,16 @@ include("config.php"); include("includes/functions.php"); -### Discovery Observer-style temperature sensors +### Discovery Observer-style NetSNMP temperatures $device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os != 'IOS' AND os != 'ProCurve'"); while ($device = mysql_fetch_array($device_query)) { - $id = $device['id']; + $id = $device['device_id']; $hostname = $device['hostname']; $community = $device['community']; $snmpver = $device['snmpver']; echo("\n***$hostname***\n"); $oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep ".1.1 " | grep -v ".101." | cut -d"." -f 1`; - #$oids = `snmpwalk -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '1.1.1' | grep -v 0 | cut -d " " -f 2`; $oids = trim($oids); if(strstr($oids, "no")) { unset ($oids); } foreach(explode("\n",$oids) as $oid) { @@ -26,9 +25,63 @@ while ($device = mysql_fetch_array($device_query)) { if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) { mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`) VALUES ('$id', '$fulloid', '$descr');"); echo("Created $fulloid on $hostname\n"); - } + } else { $temp_exists[] = "$id $fulloid"; } } } } + +// Discover Dell temperatures + +$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND hardware like 'Dell %'"); +while ($device = mysql_fetch_array($device_query)) { + $id = $device['device_id']; + $hostname = $device['hostname']; + $community = $device['community']; + $snmpver = $device['snmpver']; + echo("\n***$hostname***\n"); + $oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8`; + $oids = trim($oids); + if(strstr($oids, "no")) { unset ($oids); } + foreach(explode("\n",$oids) as $oid) { + $oid = substr(trim($oid), 36); + echo("$oid \n"); + list($oid) = explode(" ", $oid); + if($oid != "") { + $descr = trim(str_replace("\"", "", `snmpget -v2c -Onvq -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid`)); + $fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid"; + echo("Detected : $fulloid ($descr)\n"); + if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) { + mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_tenths`) VALUES ('$id', '$fulloid', '$descr', '1');"); + echo("Created $fulloid on $hostname\n"); + } + $temp_exists[] = "$id $fulloid"; + } + } +} + +$sql = "SELECT * FROM temperature"; +$query = mysql_query($sql); + +while ($sensor = mysql_fetch_array($query)) { + + unset($exists); + + $i = 0; + while ($i < count($temp_exists) && !$exists) { + $thistemp = $sensor['temp_host'] . " " . $sensor['temp_oid']; + if ($temp_exists[$i] == $thistemp) { $exists = 1; echo("Match!"); } + $i++; + echo("$temp_exists[$i] == $thistemp \n"); + } + + if(!$exists) { + echo("Deleting...\n"); +# mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'"); + } + + +} + + ?> diff --git a/html/includes/print-interface-graphs.php b/html/includes/print-interface-graphs.php index 3d84aa81a..145e93938 100644 --- a/html/includes/print-interface-graphs.php +++ b/html/includes/print-interface-graphs.php @@ -1,16 +1,16 @@ ', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/html/includes/print-syslog.inc b/html/includes/print-syslog.inc index c43e55f53..6014e19c9 100644 --- a/html/includes/print-syslog.inc +++ b/html/includes/print-syslog.inc @@ -15,16 +15,16 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } echo(" - $entry[datetime] + " . $entry['datetime'] . " - $entry[priority] + " . $entry['priority'] . " - $entry[program] - + " . $entry['program'] . " + - $entry[msg] + " . htmlspecialchars($entry['msg']) . " "); diff --git a/html/pages/device.php b/html/pages/device.php index 92563ceb0..557624327 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -30,7 +30,7 @@ if(@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = echo("
  • - VLANs + VLANs
  • "); } @@ -39,7 +39,7 @@ if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE d echo("
  • - Port Details + Port Details
  • @@ -60,7 +60,7 @@ if(mysql_result(mysql_query("select count(service_id) from services WHERE servic echo("
  • - Service Details + Service Details
  • "); diff --git a/html/pages/device/dev-overview.inc b/html/pages/device/dev-overview.inc index afd4ecaf6..2191eb966 100644 --- a/html/pages/device/dev-overview.inc +++ b/html/pages/device/dev-overview.inc @@ -6,15 +6,15 @@ $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); -$interfaces['down'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifOperStatus = 'down' AND ifAdminStatus = 'up'"),0); -$interfaces['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifAdminStatus = 'down'"),0); +$interfaces['total'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '" . $device['device_id'] . "'"),0); +$interfaces['up'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '" . $device['device_id'] . "' AND ifOperStatus = 'up'"),0); +$interfaces['down'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '" . $device['device_id'] . "' AND ifOperStatus = 'down' AND ifAdminStatus = 'up'"),0); +$interfaces['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '" . $device['device_id'] . "' AND ifAdminStatus = 'down'"),0); -$services['total'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id'"),0); -$services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id' AND service_status = '1' AND service_ignore ='0'"),0); -$services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id' AND service_status = '0' AND service_ignore = '0'"),0); -$services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '$id' AND service_ignore = '1'"),0); +$services['total'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "'"),0); +$services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_status = '1' AND service_ignore ='0'"),0); +$services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_status = '0' AND service_ignore = '0'"),0); +$services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_ignore = '1'"),0); if($services['down']) { $services_colour = $warn_colour_a; } else { $services_colour = $list_colour_a; } if($interfaces['down']) { $interfaces_colour = $warn_colour_a; } else { $interfaces_colour = $list_colour_a; } @@ -32,13 +32,69 @@ if(file_exists("includes/dev-data-" . strtolower($device[os]) . ".inc")) { } +if(mysql_result(mysql_query("SELECT count(storage_id) from storage WHERE host_id = '" . $device['device_id'] . "'"),0)) { + echo("
    "); + echo("

    Storage

    "); + echo(""); + $i = '1'; + echo(" + "); + $drives = mysql_query("SELECT * FROM `storage` WHERE host_id = '" . $device['device_id'] . "'"); + while($drive = mysql_fetch_array($drives)) { + $total = $drive['hrStorageSize'] * $drive['hrStorageAllocationUnits']; + $used = $drive['hrStorageUsed'] * $drive['hrStorageAllocationUnits']; + $perc = $drive['storage_perc']; + $total = formatStorage($total); + $used = formatStorage($used); + if($perc > '80') { $drv_class='red'; } else { $drvclass=''; } + echo(""); + $i++; + } + echo("
    MountpointUsage%TotalUsed
    " . $drive['hrStorageDescr'] . " + " . $perc . "%" . $total . "" . $used . "
    "); + echo("
    "); +} + +unset($temp_seperator); +if(mysql_result(mysql_query("SELECT count(temp_id) from temperature WHERE temp_host = '" . $device['device_id'] . "'"),0)) { + $total = mysql_result(mysql_query("SELECT count(temp_id) from temperature WHERE temp_host = '" . $device['device_id'] . "'"),0); + $rows = round($total / 2,0); + echo("
    "); + echo("

    Temperatures

    "); + $i = '1'; + $temps = mysql_query("SELECT * FROM temperature WHERE temp_host = '" . $device['device_id'] . "'"); + echo(""); + echo(""); + echo("
    "); + echo(""); + while($temp = mysql_fetch_array($temps)) { + if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + if($temp['temp_current'] < '30') { $temp_class=''; + } elseif($temp['temp_current'] < '40') { $temp_class='blue'; + } elseif($temp['temp_current'] < '50') { $temp_class='green'; + } elseif($temp['temp_current'] < '60') { $temp_class='orange'; + } else { $temp_class='red'; } + + $temp['temp_descr'] = truncate($temp['temp_descr'], 25, ''); + echo(""); + if($i == $rows) { echo("
    " . $temp['temp_descr'] . "" . $temp['temp_current'] . "°C
    "); } + $i++; + } + echo("
    "); + echo("
    "); + echo("
    "); +} + + + echo("
    "); +echo("

    Recent Events

    "); $query = "SELECT *,DATE_FORMAT(datetime, '%d/%b/%y %T') as humandate FROM `eventlog` WHERE `host` = '$_GET[id]' ORDER BY `datetime` DESC LIMIT 0,10"; $data = mysql_query($query); -echo("

    Recent Events

    -"); +echo("
    "); while($entry = mysql_fetch_array($data)) { @@ -69,7 +125,7 @@ echo(" echo("
    "); - $sql = "SELECT * FROM interfaces WHERE `device_id` = '$id'"; + $sql = "SELECT * FROM interfaces WHERE `device_id` = '" . $device['device_id'] . "'"; $query = mysql_query($sql); while($data = mysql_fetch_array($query)) { echo("$ifsep" . generateiflink($data, makeshortif(strtolower($data['ifDescr'])))); @@ -100,7 +156,7 @@ echo(" echo("
    "); - $sql = "SELECT * FROM services WHERE service_host = '$id' ORDER BY service_type"; + $sql = "SELECT * FROM services WHERE service_host = '" . $device['device_id'] . "' ORDER BY service_type"; $query = mysql_query($sql); while($data = mysql_fetch_array($query)) { if ($data[service_status] == "0" && $data[service_ignore] == "1") { $status = "grey"; } @@ -115,8 +171,6 @@ echo(" } - - echo("
    "); ?> diff --git a/html/pages/device/dev-syslog.inc b/html/pages/device/dev-syslog.inc index 032032dc3..e4c51d37a 100644 --- a/html/pages/device/dev-syslog.inc +++ b/html/pages/device/dev-syslog.inc @@ -1,8 +1,20 @@
    + +
    "); + echo(""); while($entry = mysql_fetch_array($data)) { diff --git a/includes/functions.php b/includes/functions.php index ad3e1a25a..2a33f5cd2 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -8,6 +8,16 @@ include("procurve.php"); include("snom.php"); include("graphing.php"); +function formatStorage($size) { + $sizes = Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'); + $ext = $sizes[0]; + for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { + $size = $size / 1024; + $ext = $sizes[$i]; + } + return round($size, 2).$ext; +} + function print_error($text){ echo("
    $text
    "); diff --git a/includes/graphing.php b/includes/graphing.php index 6f4700a67..81d6d0b92 100644 --- a/includes/graphing.php +++ b/includes/graphing.php @@ -17,11 +17,11 @@ function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vert } elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D"; } elseif($iter=="7") {$colour="FF0084"; unset($iter); } - $temperature['temp_descr'] = str_pad($temperature['temp_descr'], 28); - $temperature['temp_descr'] = substr($temperature['temp_descr'],0,28); + $temperature['temp_descr_fixed'] = str_pad($temperature['temp_descr'], 28); + $temperature['temp_descr_fixed'] = substr($temperature['temp_descr_fixed'],0,28); - $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[] = "DEF:temp" . $temperature[temp_id] . "=rrd/" . $hostname . "-temp-" . str_replace(" ", "_", $temperature['temp_descr']) . ".rrd:temp:AVERAGE"; + $optsa[] = "LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":" . $temperature[temp_descr_fixed]; $optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lf°C"; $optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf°C\l"; $iter++; diff --git a/includes/polling/device-ios.inc.php b/includes/polling/device-ios.inc.php index 2eb71ee51..64ce6fc45 100755 --- a/includes/polling/device-ios.inc.php +++ b/includes/polling/device-ios.inc.php @@ -3,11 +3,6 @@ $community = $device['community']; $id = $device['device_id']; $hostname = $device['hostname']; - $hardware = $device['hardware']; - $version = $device['version']; - $features = $device['features']; - $location = $device['location']; - $os = $device['location']; $temprrd = "rrd/" . $hostname . "-temp.rrd"; $tempgraph = "public_html/graphs/" . $hostname . "-temp.png"; diff --git a/includes/polling/device-unix.inc.php b/includes/polling/device-unix.inc.php index 3a8d7bf2d..85e8cab63 100755 --- a/includes/polling/device-unix.inc.php +++ b/includes/polling/device-unix.inc.php @@ -20,9 +20,9 @@ while ($dr = mysql_fetch_array($dq)) { $hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize']; $hrStorageDescr = $dr['hrStorageDescr']; $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageUsed.$hrStorageIndex"; - $used = `$cmd`; - $used = $used * $hrStorageAllocationUnits; - $perc = $used / $hrStorageSize * 100; + $used_units = trim(`$cmd`); + $used = $used_units * $hrStorageAllocationUnits; + $perc = round($used / $hrStorageSize * 100, 2); $filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr)); $storerrd = "rrd/" . $hostname . "-storage-" . $filedesc . ".rrd"; @@ -42,6 +42,8 @@ while ($dr = mysql_fetch_array($dq)) { RRA:MAX:0.5:288:800`; } rrd_update($storerrd, "N:$hrStorageSize:$used:$perc"); + mysql_query("UPDATE `storage` SET `hrStorageUsed` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'"); + } ## Set OIDs diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index 174663612..93efdc5af 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -8,11 +8,9 @@ while($temperature = mysql_fetch_array($temp_data)) { echo($temp_cmd); $temp = `$temp_cmd`; - $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); - } + + + $temprrd = "rrd/" . $device[hostname] . "-temp-" . str_replace(" ", "_",$temperature['temp_descr']) . ".rrd"; if (!is_file($temprrd)) { `rrdtool create $temprrd \ @@ -25,6 +23,7 @@ while($temperature = mysql_fetch_array($temp_data)) { } $temp = str_replace("\"", "", $temp); + if($temperature['temp_tenths']) { $temp = $temp / 10; } echo("$temprrd, N:$temp"); `rrdtool update $temprrd N:$temp`; diff --git a/poll-device.php b/poll-device.php index 3db8b9fd6..9fe6562c2 100755 --- a/poll-device.php +++ b/poll-device.php @@ -75,50 +75,51 @@ while ($device = mysql_fetch_array($device_query)) { } elseif ($device['os'] == "Linux") { 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); + if(strstr($sysDescr, "x86_64")) { $hardware = "Generic x86_64"; } $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.2021.7890.1.101.1"; - $features = `$cmd`; + $features = trim(`$cmd`); $features = str_replace("No Such Object available on this agent at this OID", "", $features); $features = str_replace("\"", "", $features); - } + // Detect Dell hardware via OpenManage SNMP + $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.674.10892.1.300.10.1.9.1"; + $hw = trim(str_replace("\"", "", `$cmd`)); + if(strstr($hw, "No")) { unset($hw); } else { $hardware = "Dell " . $hw; } + } + include("includes/polling/device-unix.inc.php"); break; case "Windows": - if($device['os'] == "Windows") { - 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"; } - } + 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") { - $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|$hardware\n"); - if(!strstr($ciscomodel, " ") && strlen($ciscomodel) >= '3') { - echo("$ciscomodel"); - $hardware = $ciscomodel; - } - + $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); } + if(!strstr($ciscomodel, " ") && strlen($ciscomodel) >= '3') { + $hardware = $ciscomodel; } + echo($device['version'] . " $version"); include("includes/polling/device-ios.inc.php"); break; + case "ProCurve": $sysDescr = str_replace(", ", ",", $sysDescr); list($hardware, $features, $version) = explode(",", $sysDescr); @@ -147,13 +148,13 @@ while ($device = mysql_fetch_array($device_query)) { unset( $update ) ; if ( $sysDescr && $sysDescr != $device['sysDescr'] ) { - $update .= "`sysDescr` = '$sysDescr'"; + $update .= $seperator . "`sysDescr` = '$sysDescr'"; $seperator = ", "; mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')"); } if ( $location && $device['location'] != $location ) { - $update .= "`location` = '$location'"; + $update .= $seperator . "`location` = '$location'"; $seperator = ", "; mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $location')"); } diff --git a/poll-interface.php b/poll-interface.php index 3da0fc0d6..f8865fd28 100755 --- a/poll-interface.php +++ b/poll-interface.php @@ -81,6 +81,7 @@ while ($interface = mysql_fetch_array($interface_query)) { } if($ifOperStatus == "up") { + $snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; $snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex']; $snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex']; @@ -104,9 +105,32 @@ while ($interface = mysql_fetch_array($interface_query)) { echo("Interface " . $device['hostname'] . " " . $interface['ifDescr'] . " is down\n"); } } -} -mysql_query("UPDATE interfaces set ifPhysAddress = '' WHERE ifPhysAddress = 'No Such Instance currently exists at this OID'"); + if ( $interface['ifAlias'] != $ifAlias ) { + $update .= $seperator . "`ifAlias` = '$ifAlias'"; + $seperator = ", "; + mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')"); + } + if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) { + $update .= $seperator . "`ifOperStatus` = '$ifOperStatus'"; + $seperator = ", "; + mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')"); + } + if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) { + $update .= $seperator . "`ifAdminStatus` = '$ifAdminStatus'"; + $seperator = ", "; + if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; } + mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')"); + } + if ($update) { + $update_query = "UPDATE `interfaces` SET "; + $update_query .= $update; + $update_query .= " WHERE `interface_id` = '" . $interface['interface_id'] . "'"; + $update_result = mysql_query($update_query); + } + + +} ?> diff --git a/process-syslog.php b/process-syslog.php index a5be0ffb1..2b8070288 100755 --- a/process-syslog.php +++ b/process-syslog.php @@ -9,6 +9,9 @@ $discard = 0; $total = 0; +mysql_query("DELETE FROM `logs` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.44]:%'"); +mysql_query("DELETE FROM `logs` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.35]:%'"); + $q = mysql_query("SELECT * FROM `logs`"); while($l = mysql_fetch_array($q)){ @@ -55,6 +58,5 @@ while($l = mysql_fetch_array($q)){ } -echo("$total records processed: $add added to database, $discard discarded"); - +#echo("$total records processed: $add added to database, $discard discarded"); ?>