From 96bb007d4b44132ef20e8c522e214d93c1a5722e Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Mon, 2 Feb 2009 16:00:11 +0000 Subject: [PATCH] per-port SNMP polling. thanks to jonathan@studenteninternet.be git-svn-id: http://www.observium.org/svn/observer/trunk@340 61d68cd4-352d-0410-923a-c4978735b2b8 --- addhost.php | 13 ++++++++--- cleanup.php | 11 ++++----- includes/billing.php | 8 +++---- includes/discovery/bgp-peers.php | 4 ++-- includes/discovery/cisco-physical.php | 4 ++-- includes/discovery/cisco-pw.php | 6 ++--- includes/discovery/cisco-vlans.php | 8 +++---- includes/discovery/cisco-vrf.php | 8 +++---- includes/discovery/interfaces.php | 4 ++-- includes/discovery/ipaddresses.php | 4 ++-- includes/discovery/ipv6-addresses.php | 8 +++---- includes/discovery/storage.php | 4 ++-- includes/discovery/temperatures.php | 25 +++++++++++---------- includes/functions.php | 22 +++++++++--------- includes/generic.php | 6 ++--- includes/osdiscovery/discover-fortigate.php | 4 ++-- includes/osdiscovery/discover-junos.php | 2 +- includes/osdiscovery/discover-screenos.php | 3 ++- includes/polling/bgpPeer.inc.php | 2 +- includes/polling/device-fortigate.inc.php | 4 ++-- includes/polling/device-ios.inc.php | 7 +++--- includes/polling/device-netstats.inc.php | 2 +- includes/polling/device-procurve.inc.php | 4 ++-- includes/polling/device-snom.inc.php | 6 ++--- includes/polling/device-unix.inc.php | 12 +++++----- includes/polling/device-windows.inc.php | 6 ++--- includes/polling/interfaces.inc.php | 8 +++---- includes/polling/temperatures.inc.php | 2 +- poll-billing.php | 5 +++-- poll-device.php | 8 +++---- poll-ifstatus.php | 12 +++++----- poll-ifstatus.sh | 4 ++-- poll-os.php | 5 +++-- poll-reachability.php | 6 +++-- update-interface.php | 4 ++-- 35 files changed, 129 insertions(+), 112 deletions(-) diff --git a/addhost.php b/addhost.php index fbfe699c7..7229160b6 100755 --- a/addhost.php +++ b/addhost.php @@ -8,18 +8,25 @@ if($argv[1] && $argv[2] && $argv[3]) { $host = strtolower($argv[1]); $community = $argv[2]; $snmpver = strtolower($argv[3]); + if (is_numeric($argv[4])) + $port = $argv[4]; + else + $port = 161; + list($hostshort) = explode(".", $host); if ( isDomainResolves($argv[1])){ if ( isPingable($argv[1])) { if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) { - $snmphost = trim(`snmpget -Oqv -$snmpver -c $community $host sysName.0 | sed s/\"//g`); + $snmphost = trim(`snmpget -Oqv -$snmpver -c $community $host:$port sysName.0 | sed s/\"//g`); + var_dump($snmphost); if ($snmphost == $host || $hostshort = $host) { - $return = createHost ($host, $community, $snmpver); + $return = createHost ($host, $community, $snmpver, $port); + var_dump($return); if($return) { echo($return . "\n"); } else { echo("Adding $host failed\n"); } } else { echo("Given hostname does not match SNMP-read hostname!\n"); } } else { echo("Already got host $host\n"); } } else { echo("Could not ping $host\n"); } } else { echo("Could not resolve $host\n"); } -} else { echo("Add Host Tool\nUsage: ./addhost.php \n"); } +} else { echo("Add Host Tool\nUsage: ./addhost.php \n"); } ?> diff --git a/cleanup.php b/cleanup.php index e743f2b00..bfb678946 100755 --- a/cleanup.php +++ b/cleanup.php @@ -13,8 +13,8 @@ $data = mysql_query($query); while($row = mysql_fetch_array($data)) { $mask = trim(shell_exec($config['ipcalc'] . " ".$row['addr']."/".$row['cidr']." | grep Netmask: | cut -d \" \" -f 4")); - $response = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntIfIndex.$row[addr] | cut -d " " -f 2`); - $maskcheck = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname] ipAdEntNetMask.$row[addr] | cut -d " " -f 2`); + $response = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname]:$row[port] ipAdEntIfIndex.$row[addr] | cut -d " " -f 2`); + $maskcheck = trim(`snmpget -v2c -Osq -c $row[community] $row[hostname]:$row[port] ipAdEntNetMask.$row[addr] | cut -d " " -f 2`); if($response == $row['ifIndex'] && $mask == $maskcheck) { } else { mysql_query("delete from ipaddr where id = '$row[id]'"); @@ -26,7 +26,7 @@ $sql = "SELECT * FROM devices WHERE status = '1'"; $query = mysql_query($sql); while($device = mysql_fetch_array($query)) { echo($device['hostname'] . " \n\n"); - $oids = shell_exec("snmpwalk -v2c -c ".$device['community']." ".$device['hostname']." ipAddressIfIndex.ipv6 -Osq"); + $oids = shell_exec("snmpwalk -v2c -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAddressIfIndex.ipv6 -Osq"); $oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids); unset($valid_ips); foreach(explode("\n", $oids) as $data) { @@ -52,8 +52,9 @@ $data = mysql_query($query); while($row = mysql_fetch_array($data)) { $index = $row[ifIndex]; $hostname = $row['hostname']; - $community = $row['community']; - $response = trim(`snmpget -v2c -Osq -c $community $hostname ifIndex.$index | cut -d " " -f 2`); + $community = $row['community']; + $port = $row['port']; + $response = trim(`snmpget -v2c -Osq -c $community $hostname:$port ifIndex.$index | cut -d " " -f 2`); if($response != $index) { mysql_query("DELETE from interfaces where interface_id = '" . $row['interface_id'] . "'"); mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $row['interface_id'] . "'"); diff --git a/includes/billing.php b/includes/billing.php index 7872f9ee9..0a2013c74 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -66,15 +66,15 @@ function getDates($dayofmonth) { } -function getValue($host, $community, $id, $inout) { +function getValue($host, $community, $port, $id, $inout) { $oid = "IF-MIB::ifHC" . $inout . "Octets." . $id; - $value = `snmpget -c $community -v2c -O qv $host $oid`; + $value = `snmpget -c $community -v2c -O qv $host:$port $oid`; return $value; } -function getIfName($host, $id) { +function getIfName($host, $port, $id) { $oid = "IF-MIB::ifDescr." . $id; - $value = `snmpget -c xyyz -v2c -O qv $host $oid`; + $value = `snmpget -c xyyz -v2c -O qv $host:$port $oid`; return $value; } diff --git a/includes/discovery/bgp-peers.php b/includes/discovery/bgp-peers.php index dd5802795..b446a9563 100755 --- a/includes/discovery/bgp-peers.php +++ b/includes/discovery/bgp-peers.php @@ -4,7 +4,7 @@ echo("BGP Sessions : "); - $as_cmd = $config['snmpwalk'] . " -CI -Oqvn -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $as_cmd = $config['snmpwalk'] . " -CI -Oqvn -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; $as_cmd .= ".1.3.6.1.2.1.15.2"; $bgpLocalAs = trim(shell_exec($as_cmd)); @@ -14,7 +14,7 @@ if($bgpLocalAs != $device['bgpLocalAs']) { mysql_query("UPDATE devices SET bgpLocalAs = '$bgpLocalAs' WHERE device_id = '".$device['device_id']."'"); echo("Updated AS\n"); } - $peers_cmd = $config['snmpwalk'] . " -CI -Oq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $peers_cmd = $config['snmpwalk'] . " -CI -Oq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; $peers_cmd .= "BGP4-MIB::bgpPeerRemoteAs"; $peers = trim(str_replace("BGP4-MIB::bgpPeerRemoteAs.", "", `$peers_cmd`)); foreach (explode("\n", $peers) as $peer) { diff --git a/includes/discovery/cisco-physical.php b/includes/discovery/cisco-physical.php index d49349ea5..c82ae8a19 100755 --- a/includes/discovery/cisco-physical.php +++ b/includes/discovery/cisco-physical.php @@ -4,7 +4,7 @@ if($config['enable_inventory']) { - $ents_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; + $ents_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['$port'] . " "; $ents_cmd .= "1.3.6.1.2.1.47.1.1.1.1.2 | sed s/.1.3.6.1.2.1.47.1.1.1.1.2.//g | cut -f 1 -d\" \""; $ents = trim(`$ents_cmd | grep -v o`); @@ -12,7 +12,7 @@ foreach(explode("\n", $ents) as $entPhysicalIndex) { $ent_data = "snmpget -Ovqs -"; - $ent_data .= $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $ent_data .= $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] .":".$device['port']; $ent_data .= " entPhysicalDescr." . $entPhysicalIndex; $ent_data .= " entPhysicalContainedIn." . $entPhysicalIndex; $ent_data .= " entPhysicalClass." . $entPhysicalIndex; diff --git a/includes/discovery/cisco-pw.php b/includes/discovery/cisco-pw.php index 859dc5341..f54bd354c 100755 --- a/includes/discovery/cisco-pw.php +++ b/includes/discovery/cisco-pw.php @@ -5,7 +5,7 @@ echo("PW : "); - $oids = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cpwVcID"); + $oids = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcID"); $oids = str_replace(".1.3.6.1.4.1.9.10.106.1.2.1.10.", "", $oids); @@ -14,8 +14,8 @@ if($oid) { list($cpwOid, $cpwVcID) = explode(" ", $oid); if($cpwOid) { - list($cpw_remote_id) = split(":", shell_exec($config['snmpget'] . " -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cpwVcMplsPeerLdpID." . $cpwOid)); - $interface_descr = trim(shell_exec("snmpwalk -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cpwVcName." . $cpwOid)); + list($cpw_remote_id) = split(":", shell_exec($config['snmpget'] . " -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcMplsPeerLdpID." . $cpwOid)); + $interface_descr = trim(shell_exec("snmpwalk -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcName." . $cpwOid)); $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipaddr AS A, interfaces AS I WHERE A.addr = '".$cpw_remote_id."' AND A.interface_id = I.interface_id"),0); $if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `interfaces` WHERE `ifDescr` = '$interface_descr' AND `device_id` = '".$device['device_id']."'"),0); if($cpw_remote_device && $if_id) { diff --git a/includes/discovery/cisco-vlans.php b/includes/discovery/cisco-vlans.php index fee5b8185..48eeb361b 100755 --- a/includes/discovery/cisco-vlans.php +++ b/includes/discovery/cisco-vlans.php @@ -2,24 +2,24 @@ echo("Cisco VLANs : "); - $vtpversion_cmd = $config['snmpget'] . " -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0"; + $vtpversion_cmd = $config['snmpget'] . " -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0"; $vtpversion = trim(`$vtpversion_cmd 2>/dev/null`); if($vtpversion == '1' || $vtpversion == '2') { - $vtp_domain_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.2.1.1.2.1"; + $vtp_domain_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " .1.3.6.1.4.1.9.9.46.1.2.1.1.2.1"; $vtp_domain = trim(str_replace("\"", "", `$vtp_domain_cmd 2>/dev/null`)); echo("VTP v$vtpversion $vtp_domain "); - $vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; + $vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; $vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \""; $vlans = trim(`$vlans_cmd | grep -v o`); foreach(explode("\n", $vlans) as $vlan) { - $vlan_descr_cmd = "snmpget -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; + $vlan_descr_cmd = "snmpget -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; $vlan_descr_cmd .= ".1.3.6.1.4.1.9.9.46.1.3.1.1.4.1." . $vlan; $vlan_descr = `$vlan_descr_cmd`; diff --git a/includes/discovery/cisco-vrf.php b/includes/discovery/cisco-vrf.php index 873b3ebac..fd2d086a6 100755 --- a/includes/discovery/cisco-vrf.php +++ b/includes/discovery/cisco-vrf.php @@ -4,7 +4,7 @@ echo("VRF : "); - $oids = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " mplsVpnVrfRouteDistinguisher"); + $oids = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher"); $oids = str_replace(".1.3.6.1.3.118.1.2.2.1.3.", "", $oids); $oids = str_replace(" \"", "||", $oids); @@ -14,9 +14,9 @@ foreach ( explode("\n", $oids) as $oid ) { if($oid) { list($vrf['oid'], $vrf['mplsVpnVrfRouteDistinguisher']) = explode("||", $oid); - $vrf['name'] = shell_exec($config['snmpget'] . " -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']); + $vrf['name'] = shell_exec($config['snmpget'] . " -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']); list(,$vrf['name'],, $vrf['mplsVpnVrfRouteDistinguisher']) = explode("\"", $vrf['name']); - $vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " mplsVpnVrfDescription.".$vrf['oid'])); + $vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfDescription.".$vrf['oid'])); if(@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0)) { @@ -31,7 +31,7 @@ $vrf_id = mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0); echo("\nRD:".$vrf['mplsVpnVrfRouteDistinguisher']." Id: ($vrf_id) Descr: ".$vrf['mplsVpnVrfDescription']." "); $interfaces_oid = ".1.3.6.1.3.118.1.2.1.1.2." . $vrf['oid']; - $interfaces = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " $interfaces_oid"); + $interfaces = shell_exec($config['snmpwalk'] . " -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $interfaces_oid"); $interfaces = trim(str_replace($interfaces_oid . ".", "", $interfaces)); # list($interfaces) = explode(" ", $interfaces); echo(" ( "); diff --git a/includes/discovery/interfaces.php b/includes/discovery/interfaces.php index 29d36f506..b01d70c88 100755 --- a/includes/discovery/interfaces.php +++ b/includes/discovery/interfaces.php @@ -4,7 +4,7 @@ echo("Interfaces : "); - $cmd = $config['snmpwalk'] . " -O nsq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.2.1.2.2.1.2"; + $cmd = $config['snmpwalk'] . " -O nsq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " .1.3.6.1.2.1.2.2.1.2"; $interfaces = trim(shell_exec($cmd)); $interfaces = str_replace("\"", "", $interfaces); $interfaces = str_replace("ifDescr.", "", $interfaces); @@ -19,7 +19,7 @@ list($ifIndex, $ifName) = explode("||", $entry); if($config['ifdescr'][$device['os']]) { - $ifDescr = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifDescr.$ifIndex"); + $ifDescr = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ifDescr.$ifIndex"); $ifDescr = str_replace("No Such Object available on this agent at this OID", "", $ifDescr); $ifDescr = str_replace("No Such Instance currently exists at this OID", "", $ifDescr); $ifDescr = trim(str_replace("\"", "", $ifDescr)); diff --git a/includes/discovery/ipaddresses.php b/includes/discovery/ipaddresses.php index 8068a727e..1c0e2490c 100755 --- a/includes/discovery/ipaddresses.php +++ b/includes/discovery/ipaddresses.php @@ -2,13 +2,13 @@ echo("IP Addresses : "); - $oids = shell_exec($config['snmpwalk'] . " -".$device['snmpver']." -Osq -c ".$device['community']." ".$device['hostname']." ipAdEntIfIndex"); + $oids = shell_exec($config['snmpwalk'] . " -".$device['snmpver']." -Osq -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAdEntIfIndex"); $oids = trim($oids); $oids = str_replace("ipAdEntIfIndex.", "", $oids); foreach(explode("\n", $oids) as $data) { $data = trim($data); list($oid,$ifIndex) = explode(" ", $data); - $mask = shell_exec($config['snmpget']." -O qv -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." ipAdEntNetMask.$oid"); + $mask = shell_exec($config['snmpget']." -O qv -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAdEntNetMask.$oid"); $mask = trim($mask); $network = trim(shell_exec ($config['ipcalc'] . " $oid/$mask | grep Network | cut -d\" \" -f 4")); list($net,$cidr) = explode("/", $network); diff --git a/includes/discovery/ipv6-addresses.php b/includes/discovery/ipv6-addresses.php index de7a993cd..96d5c381b 100644 --- a/includes/discovery/ipv6-addresses.php +++ b/includes/discovery/ipv6-addresses.php @@ -2,11 +2,11 @@ echo("IPv6 Addresses : "); -$ipv6interfaces = shell_exec($config['snmpget']." -Ovnq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." ipv6Interfaces.0"); +$ipv6interfaces = shell_exec($config['snmpget']." -Ovnq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipv6Interfaces.0"); if($ipv6interfaces){ - $oids = trim(trim(shell_exec($config['snmpwalk']." -".$device['snmpver']." -Ln -c ".$device['community']." ".$device['hostname']." ipAddressIfIndex.ipv6 -Osq | grep -v No"))); + $oids = trim(trim(shell_exec($config['snmpwalk']." -".$device['snmpver']." -Ln -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAddressIfIndex.ipv6 -Osq | grep -v No"))); $oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids); foreach(explode("\n", $oids) as $data) { if($data) { @@ -25,8 +25,8 @@ if($ipv6interfaces){ if($do == 2) { $adsep = ":"; $do = '0'; } else { $adsep = "";} } - $cidr = trim(shell_exec($config['snmpget']." -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." .1.3.6.1.2.1.4.34.1.5.2.16.$oid | sed 's/.*\.//'")); - $origin = trim(shell_exec($config['snmpget']." -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." .1.3.6.1.2.1.4.34.1.6.2.16.$oid")); + $cidr = trim(shell_exec($config['snmpget']." -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.5.2.16.$oid | sed 's/.*\.//'")); + $origin = trim(shell_exec($config['snmpget']." -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.6.2.16.$oid")); $network = trim(shell_exec($config['sipcalc']." $address/$cidr | grep Subnet | cut -f 2 -d '-'")); $comp = trim(shell_exec($config['sipcalc']." $address/$cidr | grep Compressed | cut -f 2 -d '-'")); diff --git a/includes/discovery/storage.php b/includes/discovery/storage.php index 1c754d226..3979351f1 100755 --- a/includes/discovery/storage.php +++ b/includes/discovery/storage.php @@ -4,13 +4,13 @@ echo("Storage : "); - $oids = shell_exec($config['snmpwalk'] . " -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageIndex"); + $oids = shell_exec($config['snmpwalk'] . " -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageIndex"); $oids = trim(str_replace("hrStorageIndex.","",$oids)); foreach(explode("\n", $oids) as $data) { $data = trim($data); list($oid,$hrStorageIndex) = explode(" ", $data); - $temp = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid"); + $temp = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid"); $temp = trim($temp); list($descr, $units, $size, $type) = explode("\n", $temp); list($units) = explode(" ", $units); diff --git a/includes/discovery/temperatures.php b/includes/discovery/temperatures.php index 7099af7f0..b5fa431ca 100755 --- a/includes/discovery/temperatures.php +++ b/includes/discovery/temperatures.php @@ -3,13 +3,14 @@ $hostname = $device['hostname']; $community = $device['community']; $snmpver = $device['snmpver']; + $port = $device['port']; echo("Temperatures : "); ## JunOS Temperatures if($device['os'] == "JunOS") { echo("JunOS "); - $oids = shell_exec($config['snmpwalk'] . " -v2c -CI -Osqn -c $community $hostname 1.3.6.1.4.1.2636.3.1.13.1.7"); + $oids = shell_exec($config['snmpwalk'] . " -v2c -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.2636.3.1.13.1.7"); $oids = trim($oids); foreach(explode("\n", $oids) as $data) { $data = trim($data); @@ -18,10 +19,10 @@ list($oid) = explode(" ", $data); $temp_oid = "1.3.6.1.4.1.2636.3.1.13.1.7.$oid"; $descr_oid = "1.3.6.1.4.1.2636.3.1.13.1.5.$oid"; - $descr = trim(shell_exec("snmpget -O qv -v2c -c $community $hostname $descr_oid")); - $temp = trim(shell_exec("snmpget -O qv -v2c -c $community $hostname $temp_oid")); + $descr = trim(shell_exec("snmpget -O qv -v2c -c $community $hostname:$port $descr_oid")); + $temp = trim(shell_exec("snmpget -O qv -v2c -c $community $hostname:$port $temp_oid")); if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" && $temp != "0") { - $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; + $descr = `snmpget -O qv -v2c -c $community $hostname:$port $descr_oid`; $descr = str_replace("\"", "", $descr); $descr = str_replace("temperature", "", $descr); $descr = str_replace("temp", "", $descr); @@ -40,12 +41,12 @@ ## Begin Observer-Style if($device['os'] == "Linux") { echo("Observer-Style "); - $oids = `snmpwalk -$snmpver -Osqn -CI -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 -$snmpver -Osqn -CI -c $community $hostname:$port .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 = trim($oids); foreach(explode("\n",$oids) as $oid) { $oid = trim($oid); if($oid != "") { - $descr = trim(str_replace("\"", "", `snmpget -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //`)); + $descr = trim(str_replace("\"", "", `snmpget -v2c -Osqn -c $community $hostname:$port .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //`)); $fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1"; if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) { echo("+"); @@ -64,13 +65,13 @@ ## Dell Temperatures if(strstr($device['hardware'], "Dell")) { echo("Dell OMSA "); - $oids = `snmpwalk -$snmpver -CI -Osqn -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8`; + $oids = `snmpwalk -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.674.10892.1.700.20.1.8`; $oids = trim($oids); foreach(explode("\n",$oids) as $oid) { $oid = substr(trim($oid), 36); 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`)); + $descr = trim(str_replace("\"", "", `snmpget -v2c -Onvq -c $community $hostname:$port .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"; 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');"); @@ -90,7 +91,7 @@ ## Cisco Temperatures if($device['os'] == "IOS") { echo("Cisco "); - $oids = shell_exec($config['snmpwalk'] . " -v2c -CI -Osqn -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g"); + $oids = shell_exec($config['snmpwalk'] . " -v2c -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g"); $oids = trim($oids); foreach(explode("\n", $oids) as $data) { $data = trim($data); @@ -98,10 +99,10 @@ list($oid) = explode(" ", $data); $temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid"; $descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid"; - $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; - $temp = `snmpget -O qv -v2c -c $community $hostname $temp_oid`; + $descr = `snmpget -O qv -v2c -c $community $hostname:$port $descr_oid`; + $temp = `snmpget -O qv -v2c -c $community $hostname:$port $temp_oid`; if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" ) { - $descr = `snmpget -O qv -v2c -c $community $hostname $descr_oid`; + $descr = `snmpget -O qv -v2c -c $community $hostname:$port $descr_oid`; $descr = str_replace("\"", "", $descr); $descr = str_replace("temperature", "", $descr); $descr = str_replace("temp", "", $descr); diff --git a/includes/functions.php b/includes/functions.php index c25beab88..c60a008ca 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -60,11 +60,11 @@ function rrdtool_update($rrdfile, $rrdupdate) { return shell_exec($config['rrdtool'] . " update $rrdfile $rrdupdate"); } -function getHostOS($hostname, $community, $snmpver) { +function getHostOS($hostname, $community, $snmpver, $port) { global $config; - $sysDescr_cmd = $config['snmpget']." -O qv -" . $snmpver . " -c " . $community . " " . $hostname . " sysDescr.0"; + $sysDescr_cmd = $config['snmpget']." -O qv -" . $snmpver . " -c " . $community . " " . $hostname.":".$port . " sysDescr.0"; $sysDescr = str_replace("\"", "", trim(shell_exec($sysDescr_cmd))); $dir_handle = @opendir($config['install_dir'] . "/includes/osdiscovery") or die("Unable to open $path"); while ($file = readdir($dir_handle)) { @@ -362,16 +362,16 @@ function delHost($id) } -function addHost($host, $community, $snmpver) +function addHost($host, $community, $snmpver, $port = 161) { global $config; list($hostshort) = explode(".", $host); if ( isDomainResolves($host)){ if ( isPingable($host)) { if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) { - $snmphost = shell_exec($config['snmpget'] ." -Oqv -$snmpver -c $community $host sysName.0"); + $snmphost = shell_exec($config['snmpget'] ." -Oqv -$snmpver -c $community $host:$port sysName.0"); if ($snmphost == $host || $hostshort = $host) { - createHost ($host, $community, $snmpver); + createHost ($host, $community, $snmpver, $port); } else { echo("Given hostname does not match SNMP-read hostname!\n"); } } else { echo("Already got host $host\n"); } } else { echo("Could not ping $host\n"); } @@ -481,13 +481,13 @@ function formatUptime($diff, $format="long") return "$uptime"; } -function isSNMPable($hostname, $community, $snmpver) +function isSNMPable($hostname, $community, $snmpver, $port) { global $config; - $pos = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname sysDescr.0"); + $pos = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname:$port sysDescr.0"); if($pos == '') { $status='0'; - $posb = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname 1.3.6.1.2.1.7526.2.4"); + $posb = shell_exec($config['snmpget'] ." -$snmpver -c $community -t 1 $hostname:$port 1.3.6.1.2.1.7526.2.4"); if($posb == '') { } else { $status='1'; } } else { $status='1'; @@ -599,11 +599,11 @@ function fixIOSHardware($hardware){ } -function createHost ($host, $community, $snmpver){ +function createHost ($host, $community, $snmpver, $port = 161){ $host = trim(strtolower($host)); - $host_os = getHostOS($host, $community, $snmpver); + $host_os = getHostOS($host, $community, $snmpver, $port); if($host_os) { - $sql = mysql_query("INSERT INTO `devices` (`hostname`, `community`, `os`, `status`) VALUES ('$host', '$community', '$host_os', '1')"); + $sql = mysql_query("INSERT INTO `devices` (`hostname`, `community`, `port`, `os`, `status`) VALUES ('$host', '$community', '$port', '$host_os', '1')"); if(mysql_affected_rows()) { return("Created host : $host ($host_os)"); } else { return FALSE; } diff --git a/includes/generic.php b/includes/generic.php index 23b3206d3..a47f5eba0 100755 --- a/includes/generic.php +++ b/includes/generic.php @@ -20,19 +20,19 @@ function pollDevice() { $memrrd = "rrd/" . $device['hostname'] . "-mem.rrd"; $memgraph = "public_html/graphs/" . $device['hostname'] . "-mem.png"; - $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname']." 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0"; + $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname'].":".$device['port']." 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0"; list ($cpu5m, $cpu5s) = explode("\n", shell_exec($cmd)); $cpu5m = $cpu5m + 0; $cpu5s = $cpu5s + 0; - $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname']." .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2"; + $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname'].":".$device['port']." .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2"; list ($tempin1, $tempout1) = explode("\n", shell_exec($cmd)); $tempin1 = $tempin1 +0; $tempout1 = $tempout1 + 0; - $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname']; + $cmd = $config['snmpget'] . " -O qv -v2c -c ".$community." ".$device['hostname'].":".$device['port']; $cmd .= " .1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1"; list ($memfreeio, $memfreeproc, $memusedio, $memusedproc) = explode("\n", shell_exec($cmd)); diff --git a/includes/osdiscovery/discover-fortigate.php b/includes/osdiscovery/discover-fortigate.php index 7ba86935c..143ea02ca 100755 --- a/includes/osdiscovery/discover-fortigate.php +++ b/includes/osdiscovery/discover-fortigate.php @@ -2,9 +2,9 @@ if(!$os) { - $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname ." .1.3.6.1.2.1.1.2.0"); + $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname.":".$port ." .1.3.6.1.2.1.1.2.0"); if(strstr($sysObjectId, "fortinet")) { - $fnSysVersion = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname ." fnSysVersion.0"); + $fnSysVersion = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname.":".$port ." fnSysVersion.0"); if(strstr($fnSysVersion, "Fortigate")) { $os = "Fortigate"; } diff --git a/includes/osdiscovery/discover-junos.php b/includes/osdiscovery/discover-junos.php index 80b3bded7..896fecbfc 100755 --- a/includes/osdiscovery/discover-junos.php +++ b/includes/osdiscovery/discover-junos.php @@ -2,7 +2,7 @@ if(!$os) { - $sysObjectId = shell_exec($config['snmpget'] . " -Ovqn -v2c -c ". $community ." ". $hostname ." sysObjectID.0"); + $sysObjectId = shell_exec($config['snmpget'] . " -Ovqn -v2c -c ". $community ." ". $hostname.":".$port ." sysObjectID.0"); if(strstr($sysObjectId, ".1.3.6.1.4.1.2636")) { $os = "JunOS"; } } diff --git a/includes/osdiscovery/discover-screenos.php b/includes/osdiscovery/discover-screenos.php index af2538a97..6ea05a5cf 100755 --- a/includes/osdiscovery/discover-screenos.php +++ b/includes/osdiscovery/discover-screenos.php @@ -2,7 +2,8 @@ if(!$os) { - $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname ." .1.3.6.1.2.1.1.2.0"); +var_dump($port); + $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -v2c -c ". $community ." ". $hostname.":".$port ." .1.3.6.1.2.1.1.2.0"); if(strstr($sysObjectId, "netscreen")) { $os = "ScreenOS"; } elseif (strstr($sysObjectId, "enterprises.3224.1")) { $os = "ScreenOS"; } diff --git a/includes/polling/bgpPeer.inc.php b/includes/polling/bgpPeer.inc.php index 1b7f9a579..6d0777eb6 100755 --- a/includes/polling/bgpPeer.inc.php +++ b/includes/polling/bgpPeer.inc.php @@ -12,7 +12,7 @@ while($peer = mysql_fetch_array($peers)) { echo("Checking ".$peer['bgpPeerIdentifier']."\n"); - $peer_cmd = $config['snmpget'] . " -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $peer_cmd = $config['snmpget'] . " -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; $peer_cmd .= "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; $peer_cmd .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; $peer_cmd .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; diff --git a/includes/polling/device-fortigate.inc.php b/includes/polling/device-fortigate.inc.php index 2af53300b..0646b2b20 100755 --- a/includes/polling/device-fortigate.inc.php +++ b/includes/polling/device-fortigate.inc.php @@ -2,8 +2,8 @@ echo("Fortinet Fortigate Poller\n"); -$fnSysVersion = shell_exec($config['snmpget']." -".$device['snmpver']." -Ovq -c ".$device['community']." ".$device['hostname']." fnSysVersion.0"); -$serial = shell_exec($config['snmpget']." -".$device['snmpver']." -Ovq -c ".$device['community']." ".$device['hostname']." fnSysSerial.0"); +$fnSysVersion = shell_exec($config['snmpget']." -".$device['snmpver']." -Ovq -c ".$device['community']." ".$device['hostname'].":".$device['port']." fnSysVersion.0"); +$serial = shell_exec($config['snmpget']." -".$device['snmpver']." -Ovq -c ".$device['community']." ".$device['hostname'].":".$device['port']." fnSysSerial.0"); $version = preg_replace("/(.+)\ (.+),(.+),(.+)/", "Fortinet \\1||\\2||\\3||\\4", $fnSysVersion); list($hardware,$version,$features) = explode("||", $version); diff --git a/includes/polling/device-ios.inc.php b/includes/polling/device-ios.inc.php index 369049ac4..87761603a 100755 --- a/includes/polling/device-ios.inc.php +++ b/includes/polling/device-ios.inc.php @@ -3,6 +3,7 @@ $community = $device['community']; $id = $device['device_id']; $hostname = $device['hostname']; + $port = $device['port']; $Otemprrd = "rrd/" . $hostname . "-temp.rrd"; $Ocpurrd = "rrd/" . $hostname . "-cpu.rrd"; @@ -48,15 +49,15 @@ } - list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`); + list ($cpu5m, $cpu5s) = explode("\n", `snmpget -O qv -v2c -c $community $hostname:$port 1.3.6.1.4.1.9.2.1.58.0 1.3.6.1.4.1.9.2.1.56.0`); $cpu5m = $cpu5m + 0; $cpu5s = $cpu5s + 0; - list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`); + list ($tempin1, $tempout1) = explode("\n", `snmpget -O qv -v2c -c $community $hostname:$port .1.3.6.1.4.1.9.9.13.1.3.1.3.1 .1.3.6.1.4.1.9.9.13.1.3.1.3.2`); $tempin1 = $tempin1 +0; $tempout1 = $tempout1 + 0; $mem_get = ".1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.6.3"; $mem_get .= ".1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.3"; - $mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`; + $mem_raw = `snmpget -O qv -v2c -c $community $hostname:$port $mem_get`; $mem_raw = str_replace("No Such Instance currently exists at this OID", "0", $mem_raw); list ($memfreeio, $memfreeproc, $memfreeprocb, $memusedio, $memusedproc, $memusedprocb) = explode("\n", $mem_raw); echo("$hostname\n"); diff --git a/includes/polling/device-netstats.inc.php b/includes/polling/device-netstats.inc.php index e17584589..95d416653 100755 --- a/includes/polling/device-netstats.inc.php +++ b/includes/polling/device-netstats.inc.php @@ -27,7 +27,7 @@ if($device[os] != "Snom") { } if(!file_exists($rrdfile)) { `$rrd_create`; } - $snmpdata_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " $snmpstring"; + $snmpdata_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $snmpstring"; $snmpdata = trim(`$snmpdata_cmd`); $rrdupdate = "N"; foreach(explode("\n", $snmpdata) as $data) { diff --git a/includes/polling/device-procurve.inc.php b/includes/polling/device-procurve.inc.php index 4b6d2c332..16623f5c4 100755 --- a/includes/polling/device-procurve.inc.php +++ b/includes/polling/device-procurve.inc.php @@ -10,11 +10,11 @@ if(is_file($Omemrrd) && !is_file($memrrd)) { rename($Omemrrd, $memrrd); echo("Moving $Omemrrd to $memrrd"); } -$cpu_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; +$cpu_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " 1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; $cpu = `$cpu_cmd`; -$mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; +$mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $mem_cmd .= " 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.5.1 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6.1 1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.7.1"; $mem = `$mem_cmd`; diff --git a/includes/polling/device-snom.inc.php b/includes/polling/device-snom.inc.php index d36b5ed7d..cf5083cc4 100755 --- a/includes/polling/device-snom.inc.php +++ b/includes/polling/device-snom.inc.php @@ -4,7 +4,7 @@ // Get SNOM specific version string from silly SNOM location. Silly SNOM! - $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.2.1.7526.2.4"; + $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " 1.3.6.1.2.1.7526.2.4"; $sysDescr = `$cmd`; $sysDescr = str_replace("-", " ", $sysDescr); $sysDescr = str_replace("\"", "", $sysDescr); @@ -12,8 +12,8 @@ // Get data for calls and network from SNOM specific SNMP OIDs. - $cmda = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.2.1.7526.2.1.1 1.3.6.1.2.1.7526.2.1.2 1.3.6.1.2.1.7526.2.2.1 1.3.6.1.2.1.7526.2.2.2"; - $cmdb = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.2.1.7526.2.5 1.3.6.1.2.1.7526.2.6"; + $cmda = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " 1.3.6.1.2.1.7526.2.1.1 1.3.6.1.2.1.7526.2.1.2 1.3.6.1.2.1.7526.2.2.1 1.3.6.1.2.1.7526.2.2.2"; + $cmdb = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " 1.3.6.1.2.1.7526.2.5 1.3.6.1.2.1.7526.2.6"; echo($cmda); $snmpdata = `$cmda`; $snmpdatab = `$cmdb`; diff --git a/includes/polling/device-unix.inc.php b/includes/polling/device-unix.inc.php index 972fcfe7e..956f04bc8 100755 --- a/includes/polling/device-unix.inc.php +++ b/includes/polling/device-unix.inc.php @@ -42,12 +42,12 @@ if(is_file($Osysrrd) && !is_file($sysrrd)) { rename($Osysrrd, $sysrrd); echo("Mo list(,,$version) = explode (" ", $sysDescr); if(strstr($sysDescr, "386")|| strstr($sysDescr, "486")||strstr($sysDescr, "586")||strstr($sysDescr, "686")) { $hardware = "Generic x86"; } if(strstr($sysDescr, "x86_64")) { $hardware = "Generic x86 64-bit"; } - $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.2021.7890.1.101.1"; + $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']. " .1.3.6.1.4.1.2021.7890.1.101.1"; $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"; + $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " .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; } } @@ -60,7 +60,7 @@ while ($dr = mysql_fetch_array($dq)) { $hrStorageAllocationUnits = $dr['hrStorageAllocationUnits']; $hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize']; $hrStorageDescr = $dr['hrStorageDescr']; - $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageUsed.$hrStorageIndex"; + $cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageUsed.$hrStorageIndex"; $used_units = trim(`$cmd`); $used = $used_units * $hrStorageAllocationUnits; $perc = round($used / $hrStorageSize * 100, 2); @@ -120,7 +120,7 @@ $oid_ssCpuUser = ".1.3.6.1.4.1.2021.11.9.0"; $oid_ssCpuSystem = ".1.3.6.1.4.1.2021.11.10.0"; -$cpu_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; +$cpu_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $cpu_cmd .= " $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses"; $cpu_cmd .= " $oid_hrSystemNumUsers $oid_ssCpuUser $oid_ssCpuSystem .1.3.6.1.4.1.2021.1.101.1"; $cpu = `$cpu_cmd`; @@ -209,12 +209,12 @@ if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSe } // end create load rrd $mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0"; - $mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $mem_get; + $mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $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_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $load_get; + $load_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $load_get; $load_raw = `$load_cmd`; list ($load1, $load5, $load10) = explode ("\n", $load_raw); diff --git a/includes/polling/device-windows.inc.php b/includes/polling/device-windows.inc.php index d77349a3d..8a7c7a789 100755 --- a/includes/polling/device-windows.inc.php +++ b/includes/polling/device-windows.inc.php @@ -22,7 +22,7 @@ $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_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $s_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $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); @@ -97,12 +97,12 @@ } $mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0"; - $mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $mem_get; + $mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $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_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $load_get; + $load_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $load_get; $load_raw = `$load_cmd`; list ($load1, $load5, $load10) = explode ("\n", $load_raw); diff --git a/includes/polling/interfaces.inc.php b/includes/polling/interfaces.inc.php index dd4355046..b03210aef 100644 --- a/includes/polling/interfaces.inc.php +++ b/includes/polling/interfaces.inc.php @@ -18,7 +18,7 @@ while ($interface = mysql_fetch_array($interface_query)) { echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n"); - $snmp_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $snmp_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex']; $snmp_output = trim(`$snmp_cmd`); @@ -93,8 +93,8 @@ 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 = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; + $snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex']; $snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex']; $snmp_data_cmd .= " ifInNUcastPkts." . $interface['ifIndex'] . " ifOutNUcastPkts." . $interface['ifIndex']; @@ -106,7 +106,7 @@ while ($interface = mysql_fetch_array($interface_query)) { list($ifHCInOctets, $ifHCOutOctets, $ifInErrors, $ifOutErrors, $ifInUcastPkts, $ifOutUcastPkts, $ifInNUcastPkts, $ifOutNUcastPkts) = explode("\n", $snmp_data); if($ifHCInOctets == "" || strpos($ifHCInOctets, "No") !== FALSE ) { - $octets_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $octets_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $octets_cmd .= " ifInOctets." . $interface['ifIndex'] . " ifOutOctets." . $interface['ifIndex']; $octets = `$octets_cmd`; list ($ifHCInOctets, $ifHCOutOctets) = explode("\n", $octets); diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index 074f268cc..38d5aa4d7 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -4,7 +4,7 @@ $query = "SELECT * FROM temperature WHERE temp_host = '" . $device['device_id'] $temp_data = mysql_query($query); while($temperature = mysql_fetch_array($temp_data)) { - $temp_cmd = "snmpget -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $temperature['temp_oid']; + $temp_cmd = "snmpget -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['temp_oid']; $temp = `$temp_cmd`; echo("Checking temp " . $temperature['temp_descr'] . "... "); diff --git a/poll-billing.php b/poll-billing.php index a5ffc9993..18b5e745c 100644 --- a/poll-billing.php +++ b/poll-billing.php @@ -35,11 +35,12 @@ function CollectData($bill_id) { $port_id = $port_data['port_id']; $host = $port_data['hostname']; + $port = $port_data['port']; echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n"); - $port_in_measurement = trim(getValue($host, $port_data['community'], $port_data['ifIndex'], "In")); - $port_out_measurement = trim(getValue($host, $port_data['community'], $port_data['ifIndex'], "Out")); + $port_in_measurement = trim(getValue($host, $port_data['community'], $port, $port_data['ifIndex'], "In")); + $port_out_measurement = trim(getValue($host, $port_data['community'], $port, $port_data['ifIndex'], "Out")); echo("$port_in_measurement and $port_out_measurement \n"); diff --git a/poll-device.php b/poll-device.php index 41fca95f3..a35874c79 100755 --- a/poll-device.php +++ b/poll-device.php @@ -42,7 +42,7 @@ while ($device = mysql_fetch_array($device_query)) { $snmpable = FALSE; if($pingable) { - $snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver']); + $snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver'], $device['port']); if($snmpable) { echo("SNMP : yes :)\n"); } else { echo("SNMP : no :(\n"); } } @@ -56,11 +56,11 @@ while ($device = mysql_fetch_array($device_query)) { } else { $uptimeoid = "1.3.6.1.2.1.1.3.0"; } - $snmp_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $snmp_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $snmp_cmd .= " $uptimeoid sysLocation.0 sysContact.0"; #$snmp_cmd .= " | grep -v 'Cisco Internetwork Operating System Software'"; if($device['os'] == "IOS" || $device['os'] == "IOS XE") { - $snmp_cmdb = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; + $snmp_cmdb = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; $snmp_cmdb .= " .1.3.6.1.2.1.47.1.1.1.1.13.1"; $snmp_cmdb .= " | grep -v 'Cisco Internetwork Operating System Software'"; $ciscomodel = str_replace("\"", "", trim(`$snmp_cmdb`)); @@ -71,7 +71,7 @@ while ($device = mysql_fetch_array($device_query)) { $snmpdata = trim($snmpdata); $snmpdata = str_replace("\"", "", $snmpdata); list($sysUptime, $sysLocation, $sysContact) = explode("\n", $snmpdata); - $sysDescr = trim(shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " sysDescr.0")); + $sysDescr = trim(shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " sysDescr.0")); $sysUptime = str_replace("(", "", $sysUptime); $sysUptime = str_replace(")", "", $sysUptime); list($days, $hours, $mins, $secs) = explode(":", $sysUptime); diff --git a/poll-ifstatus.php b/poll-ifstatus.php index f35c039ec..be7a06c40 100755 --- a/poll-ifstatus.php +++ b/poll-ifstatus.php @@ -1,13 +1,15 @@ -#!/usr/local/bin/php +#!/usr/bin/php