diff --git a/includes/discovery/cisco-pw.inc.php b/includes/discovery/cisco-pw.inc.php index da757b517..3d5eda05b 100755 --- a/includes/discovery/cisco-pw.inc.php +++ b/includes/discovery/cisco-pw.inc.php @@ -3,7 +3,7 @@ if($config['enable_pseudowires'] && $device['os_group'] == "ios") { unset( $cpw_count ); - unset($cpw_exists); + unset( $cpw_exists ); echo("Cisco Pseudowires : "); @@ -13,53 +13,53 @@ if($config['enable_pseudowires'] && $device['os_group'] == "ios") { $oids = trim($oids); foreach ( explode("\n", $oids) as $oid ) { - if($oid) { - list($cpwOid, $cpwVcID) = explode(" ", $oid); - if($cpwOid) { - list($cpw_remote_id) = split(":", shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcMplsPeerLdpID." . $cpwOid)); - $interface_descr = trim(shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcName." . $cpwOid)); - $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.interface_id = I.interface_id"),0); - $if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `ifDescr` = '$interface_descr' AND `device_id` = '".$device['device_id']."'"),0); - if($cpw_remote_device && $if_id) { - $hostname = gethostbyid($cpw_remote_device); - #echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))"); - if(mysql_result(mysql_query("SELECT count(*) FROM pseudowires WHERE `interface_id` = '$if_id' - AND `cpwVcID`='".$cpwVcID."'"),0)) { - echo("."); - } else { - $insert_query = "INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`) "; - $insert_query .= "VALUES ('$if_id','$cpw_remote_device','$cpw_remote_id','$cpwVcID', '$cpwOid')"; - mysql_query($insert_query); - echo("+"); - #echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n"); - } + if($oid) { + list($cpwOid, $cpwVcID) = explode(" ", $oid); + if($cpwOid) { + list($cpw_remote_id) = split(":", shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcMplsPeerLdpID." . $cpwOid)); + $interface_descr = trim(shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcName." . $cpwOid)); + $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.interface_id = I.interface_id"),0); + $if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `ifDescr` = '$interface_descr' AND `device_id` = '".$device['device_id']."'"),0); + if($cpw_remote_device && $if_id) { + $hostname = gethostbyid($cpw_remote_device); +#echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))"); + if(mysql_result(mysql_query("SELECT count(*) FROM pseudowires WHERE `interface_id` = '$if_id' + AND `cpwVcID`='".$cpwVcID."'"),0)) { + echo("."); + } else { + $insert_query = "INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`) "; + $insert_query .= "VALUES ('$if_id','$cpw_remote_device','$cpw_remote_id','$cpwVcID', '$cpwOid')"; + mysql_query($insert_query); + echo("+"); +#echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n"); + } $cpw_exists[] = $device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID"; + } } } } -} -$sql = "SELECT * FROM pseudowires AS P, ports AS I, devices as D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; -$query = mysql_query($sql); + $sql = "SELECT * FROM pseudowires AS P, ports AS I, devices as D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + $query = mysql_query($sql); -while ($cpw = mysql_fetch_array($query)) { - unset($exists); - $i = 0; - while ($i < count($cpw_exists) && !$exists) { - $this_cpw = $cpw['device_id'] . " " . $cpw['cpwOid'] . " " . $cpw['peer_device_id'] . " " . $cpw['interface_id'] . " " . $cpw['cpwVcID']; - if ($cpw_exists[$i] == $this_cpw) { $exists = 1; + while ($cpw = mysql_fetch_array($query)) { + unset($exists); + $i = 0; + while ($i < count($cpw_exists) && !$exists) { + $this_cpw = $cpw['device_id'] . " " . $cpw['cpwOid'] . " " . $cpw['peer_device_id'] . " " . $cpw['interface_id'] . " " . $cpw['cpwVcID']; + if ($cpw_exists[$i] == $this_cpw) { $exists = 1; # echo($cpw_exists[$i]. " || $this_cpw \n"); + } + $i++; } - $i++; - } - if(!$exists) { - echo("-"); + if(!$exists) { + echo("-"); # echo($this_cpw . "\n"); - mysql_query("DELETE FROM pseudowires WHERE pseudowire_id = '" . $cpw['pseudowire_id'] . "'"); + mysql_query("DELETE FROM pseudowires WHERE pseudowire_id = '" . $cpw['pseudowire_id'] . "'"); + } } -} -echo("\n"); + echo("\n"); } diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index ad8c774f0..b32870681 100755 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -1,59 +1,58 @@ diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php index ca4255d9e..4b4e4abb8 100755 --- a/includes/discovery/ports.inc.php +++ b/includes/discovery/ports.inc.php @@ -2,83 +2,83 @@ # Discover ports - echo("Ports : "); +echo("Ports : "); - $ports = snmp_walk($device, "ifDescr", "-Onsq", "IF-MIB"); +$ports = snmp_walk($device, "ifDescr", "-Onsq", "IF-MIB"); - $ports = str_replace("\"", "", $ports); - $ports = str_replace("ifDescr.", "", $ports); - $ports = str_replace(" ", "||", $ports); +$ports = str_replace("\"", "", $ports); +$ports = str_replace("ifDescr.", "", $ports); +$ports = str_replace(" ", "||", $ports); - $interface_ignored = 0; - $interface_added = 0; +$interface_ignored = 0; +$interface_added = 0; - foreach(explode("\n", $ports) as $entry){ +foreach(explode("\n", $ports) as $entry){ - $entry = trim($entry); - list($ifIndex, $ifDescr) = explode("||", $entry); + $entry = trim($entry); + list($ifIndex, $ifDescr) = explode("||", $entry); - if(!strstr($entry, "irtual")) { - $if = trim(strtolower($ifDescr)); - $nullintf = 0; - foreach($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } } - if(is_array($config['bad_if_regexp'])) { - foreach($config['bad_if_regexp'] as $bi) { - if (preg_match($bi ."i", $if)) { - $nullintf = 1; - } - } + if(!strstr($entry, "irtual")) { + $if = trim(strtolower($ifDescr)); + $nullintf = 0; + foreach($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } } + if(is_array($config['bad_if_regexp'])) { + foreach($config['bad_if_regexp'] as $bi) { + if (preg_match($bi ."i", $if)) { + $nullintf = 1; + } } + } - if($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; } - $ifDescr = fixifName($ifDescr); - if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; } - if(isset($config['allow_ng']) && !$config['allow_ng']) { - if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = 1; } + if($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; } + $ifDescr = fixifName($ifDescr); + if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; } + if(isset($config['allow_ng']) && !$config['allow_ng']) { + if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = 1; } + } + if ($debug) echo("\n $if "); + if ($nullintf == 0) { + if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') { + mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','$ifDescr')"); +# Add Interface + echo("+"); + } else { + mysql_query("UPDATE `ports` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); + echo("."); } - if ($debug) echo("\n $if "); - if ($nullintf == 0) { - if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') { - mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','$ifDescr')"); - # Add Interface - echo("+"); - } else { - mysql_query("UPDATE `ports` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); - echo("."); - } - $int_exists[] = "$ifIndex"; - } else { - # Ignored Interface - if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') { - mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); - # Delete Interface - echo("-"); ## Deleted Interface - } else { - echo("X"); ## Ignored Interface - } + $int_exists[] = "$ifIndex"; + } else { +# Ignored Interface + if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') { + mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); +# Delete Interface + echo("-"); ## Deleted Interface + } else { + echo("X"); ## Ignored Interface } - } + } + } +} + + +$sql = "SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = '0'"; +$query = mysql_query($sql); + +while ($test_if = mysql_fetch_array($query)) { + unset($exists); + $i = 0; + while ($i < count($int_exists) && !isset($exists)) { + $this_if = $test_if['ifIndex']; + if ($int_exists[$i] == $this_if) { $exists = 1; } + $i++; } - - - $sql = "SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = '0'"; - $query = mysql_query($sql); - - while ($test_if = mysql_fetch_array($query)) { - unset($exists); - $i = 0; - while ($i < count($int_exists) && !isset($exists)) { - $this_if = $test_if['ifIndex']; - if ($int_exists[$i] == $this_if) { $exists = 1; } - $i++; - } - if(!$exists) { - echo("-"); - mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'"); - } + if(!$exists) { + echo("-"); + mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'"); } +} - unset($temp_exists); - echo("\n"); +unset($temp_exists); +echo("\n"); ?> diff --git a/includes/discovery/processors-ios.inc.php b/includes/discovery/processors-ios.inc.php index e85a1007f..7820b3d4d 100755 --- a/includes/discovery/processors-ios.inc.php +++ b/includes/discovery/processors-ios.inc.php @@ -1,52 +1,52 @@ $entry) { - echo("CISCO-PROCESS-MIB : "); - $processors_array = snmpwalk_cache_oid("cpmCPU", $device, $processors_array, "CISCO-PROCESS-MIB"); - if($debug) { print_r($processors_array); } - foreach($processors_array[$device['device_id']] as $index => $entry) + if ($entry['cpmCPUTotal5minRev'] || $entry['cpmCPUTotal5min']) { - if ($entry['cpmCPUTotal5minRev'] || $entry['cpmCPUTotal5min']) + $entPhysicalIndex = $entry['cpmCPUTotalPhysicalIndex']; + + if($entry['cpmCPUTotal5minRev']) { + $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.8." . $index; + $usage = $entry['cpmCPUTotal5minRev']; + } elseif($entry['cpmCPUTotal5min']) { + $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.5." . $index; + $usage = $entry['cpmCPUTotal5min']; + } + + $descr_oid = "entPhysicalName." . $entPhysicalIndex; + $descr = snmp_get($device, $descr_oid, "-Oqv", "ENTITY-MIB"); + if(!$descr) { $descr = "Processor $index"; } + + $old_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("cpmCPU-" . $index . ".rrd"); + $new_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-cpm-" . $index . ".rrd"); + + if($debug) { echo("$old_rrd $new_rrd"); } + if (is_file($old_rrd)) { + shell_exec("mv -f $old_rrd $new_rrd"); + echo("Moved RRD "); + } + + if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" ) { - $entPhysicalIndex = $entry['cpmCPUTotalPhysicalIndex']; - - if($entry['cpmCPUTotal5minRev']) { - $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.8." . $index; - $usage = $entry['cpmCPUTotal5minRev']; - } elseif($entry['cpmCPUTotal5min']) { - $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.5." . $index; - $usage = $entry['cpmCPUTotal5min']; - } - - $descr_oid = "entPhysicalName." . $entPhysicalIndex; - $descr = snmp_get($device, $descr_oid, "-Oqv", "ENTITY-MIB"); - if(!$descr) { $descr = "Processor $index"; } - - $old_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("cpmCPU-" . $index . ".rrd"); - $new_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-cpm-" . $index . ".rrd"); - - if($debug) { echo("$old_rrd $new_rrd"); } - if (is_file($old_rrd)) { - shell_exec("mv -f $old_rrd $new_rrd"); - echo("Moved RRD "); - } - - if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" ) - { - discover_processor($valid_processor, $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); - } + discover_processor($valid_processor, $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); } } - if(!is_array($valid_processor['cpm'])) { - $avgBusy5 = snmp_get($device, ".1.3.6.1.4.1.9.2.1.58.0", "-Oqv"); - if(is_numeric($avgBusy5)) { - discover_processor($valid_processor, $device, ".1.3.6.1.4.1.9.2.1.58.0", "0", "ios", "Processor", "1", $avgBusy5, NULL, NULL); - } + } + if(!is_array($valid_processor['cpm'])) { + $avgBusy5 = snmp_get($device, ".1.3.6.1.4.1.9.2.1.58.0", "-Oqv"); + if(is_numeric($avgBusy5)) { + discover_processor($valid_processor, $device, ".1.3.6.1.4.1.9.2.1.58.0", "0", "ios", "Processor", "1", $avgBusy5, NULL, NULL); } - } - ## End Cisco Processors + } +} +## End Cisco Processors - unset ($processors_array); +unset ($processors_array); ?>