git-svn-id: http://www.observium.org/svn/observer/trunk@517 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-11-12 11:35:58 +00:00
parent 76582e46a5
commit 45e760ae04
4 changed files with 52 additions and 81 deletions

View File

@@ -1,74 +0,0 @@
#!/usr/bin/php
<?php
$community = $device['community'];
echo("CISCO-CDP-MIB: ");
unset($cdp_array);
$cdp_array = snmpwalk_cache_twopart_oid("cdpCache", $device, $cdp_array, "CISCO-CDP-MIB");
$cdp_array = $cdp_array[$device[device_id]];
unset($cdp_links);
foreach( array_keys($cdp_array) as $key) {
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
$cdp_if_array = $cdp_array[$key];
foreach( array_keys($cdp_if_array) as $entry_key) {
$cdp_entry_array = $cdp_if_array[$entry_key];
if($device['hostname'] && $interface['ifDescr'] && $cdp_entry_array['cdpCacheDeviceId'] && $cdp_entry_array['cdpCacheDevicePort']){
$cdp_links .= $device['hostname'] . "," . $interface['ifDescr'] . "," . $cdp_entry_array['cdpCacheDeviceId'] . "," . $cdp_entry_array['cdpCacheDevicePort'] . "\n";
}
}
}
#echo("$cdp_links");
foreach ( explode("\n" ,$cdp_links) as $link ) {
if ($link == "") { break; }
list($src_host,$src_if, $dst_host, $dst_if) = explode(",", $link);
$dst_host = strtolower($dst_host);
$dst_if = strtolower($dst_if);
$src_host = strtolower($src_host);
$src_if = strtolower($src_if);
$ip = gethostbyname($dst_host);
if ( match_network($config['nets'], $ip) ) {
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host'"), 0) == '0' ) {
if($config['cdp_autocreate']) {
echo("++ Creating: $dst_host \n");
createHost ($dst_host, $community, "v2c");
}
} else {
echo(".");
}
} else {
echo("!($dst_host)");
}
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host'"), 0) == '1' &&
mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$src_host'"), 0) == '1' &&
mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` AS I, `devices` AS D WHERE `ifDescr` = '$dst_if' AND sysName = '$dst_host' AND D.device_id = I.device_id"), 0) == '1' &&
mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` AS I, `devices` AS D WHERE `ifDescr` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0) == '1')
{
$dst_if_id = mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE `ifDescr` = '$dst_if' AND sysName = '$dst_host' AND D.device_id = I.device_id"), 0);
$src_if_id = mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE `ifDescr` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0);
$linkalive[] = $src_if_id . "," . $dst_if_id;
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `links` WHERE `dst_if` = '$dst_if_id' AND `src_if` = '$src_if_id'"),0) == '0')
{
$sql = "INSERT INTO `links` (`src_if`, `dst_if`, `cdp`) VALUES ('$src_if_id', '$dst_if_id', '1')";
mysql_query($sql);
echo("\n++($src_host $src_if -> $dst_host $dst_if)");
} else {
echo("..");
}
} else {
}
# }
}
echo("\n");
}
?>

View File

@@ -8,6 +8,8 @@ RewriteCond %{REQUEST_URI} !^(.*)\.jpg$
RewriteCond %{REQUEST_URI} !^(.*)\.gif$
RewriteCond %{REQUEST_URI} !^(.*)\.png$
RewriteRule ^cust/ ?page=cust
RewriteRule ^bare/(.+)/ index-bare.php?page=$1
RewriteRule ^bare/(.+)/(.+)/ index-bare.php?page=$1&opta=$2
RewriteRule ^bare/(.+)/(.+)/(.+)/ index-bare.php?page=$1&opta=$2&optb=$3

View File

@@ -96,7 +96,6 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) {
$cmd .= $oid;
$data = trim(shell_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: $oid\n");
foreach(explode("\n", $data) as $entry) {
$entry = str_replace($oid.".", "", $entry);
list($slotport, $value) = explode("=", $entry);
@@ -159,13 +158,14 @@ function snmp_cache_portIfIndex ($device, $array) {
$cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " portIfIndex";
$output = trim(shell_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: portIfIndex\n");
foreach(explode("\n", $output) as $entry){
$entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry);
list($slotport, $ifIndex) = explode(" ", $entry);
if($slotport && $ifIndex){
$array[$device_id][$ifIndex]['portIfIndex'] = $slotport;
$array[$device_id][$slotport]['ifIndex'] = $ifIndex;
}
}
return $array;
}

View File

@@ -4,8 +4,14 @@ if($device['os'] == "IOS") {
$array = snmp_cache_portIfIndex ($device, $array);
$cpe_oids = array("cpeExtPsePortEnable", "cpeExtPsePortDiscoverMode", "cpeExtPsePortDeviceDetected", "cpeExtPsePortIeeePd", "cpeExtPsePortAdditionalStatus", "cpeExtPsePortPwrMax", "cpeExtPsePortPwrAllocated", "cpeExtPsePortPwrAvailable", "cpeExtPsePortPwrConsumption", "cpeExtPsePortMaxPwrDrawn", "cpeExtPsePortEntPhyIndex", "cpeExtPsePortEntPhyIndex", "cpeExtPsePortPolicingCapable", "cpeExtPsePortPolicingEnable", "cpeExtPsePortPolicingAction", "cpeExtPsePortPwrManAlloc");
$peth_oids = array("pethPsePortAdminEnable", "pethPsePortPowerPairsControlAbility", "pethPsePortPowerPairs", "pethPsePortDetectionStatus", "pethPsePortPowerPriority", "pethPsePortMPSAbsentCounter", "pethPsePortType", "pethPsePortPowerClassifications", "pethPsePortInvalidSignatureCounter", "pethPsePortPowerDeniedCounter", "pethPsePortOverLoadCounter", "pethPsePortShortCounter");
$cpe_oids = array("cpeExtPsePortEnable", "cpeExtPsePortDiscoverMode", "cpeExtPsePortDeviceDetected", "cpeExtPsePortIeeePd",
"cpeExtPsePortAdditionalStatus", "cpeExtPsePortPwrMax", "cpeExtPsePortPwrAllocated", "cpeExtPsePortPwrAvailable", "cpeExtPsePortPwrConsumption",
"cpeExtPsePortMaxPwrDrawn", "cpeExtPsePortEntPhyIndex", "cpeExtPsePortEntPhyIndex", "cpeExtPsePortPolicingCapable", "cpeExtPsePortPolicingEnable",
"cpeExtPsePortPolicingAction", "cpeExtPsePortPwrManAlloc");
$peth_oids = array("pethPsePortAdminEnable", "pethPsePortPowerPairsControlAbility", "pethPsePortPowerPairs", "pethPsePortDetectionStatus",
"pethPsePortPowerPriority", "pethPsePortMPSAbsentCounter", "pethPsePortType", "pethPsePortPowerClassifications", "pethPsePortInvalidSignatureCounter",
"pethPsePortPowerDeniedCounter", "pethPsePortOverLoadCounter", "pethPsePortShortCounter");
$sub_start = utime();
echo("Caching Oids: ");
@@ -14,6 +20,43 @@ if($device['os'] == "IOS") {
$end = utime(); $run = $end - $sub_start; $proctime = substr($run, 0, 5);
echo("\n$proctime secs\n");
$polled = time();
$port_query = mysql_query("SELECT * FROM `interfaces` WHERE `device_id` = '".$device['device_id']."'");
while ($port = mysql_fetch_array($port_query)) {
if($array[$device[device_id]][$port[ifIndex]]) { // Check to make sure Port data is cached.
echo(" --> " . $port['ifDescr'] . " POE");
/// Update RRDs
$rrdfile = $host_rrd . "/" . $port['ifIndex'] . ".rrd";
if(!is_file($rrdfile)) {
$woo = shell_exec($config['rrdtool'] . " create $rrdfile -s 300 \
DS:PortPwrAllocated:GAUGE:600:0:12500000000 \
DS:PortPwrAvailable:GAUGE:600:0:12500000000 \
DS:PortConsumption:DERIVE:600:0:12500000000 \
DS:PortMaxPwrDrawn:GAUGE:600:0:12500000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797");
}
$woo = "$polled:".$port['cpeExtPsePortPwrAllocated'].":".$port['cpeExtPsePortPwrAvailable'].":".$port['cpeExtPsePortPwrConsumption'].":".$port['cpeExtPsePortMaxPwrDrawn'];
$ret = rrdtool_update("$rrdfile", $woo);
/// End Update POE-RRD
}
}
}