updates, more mibs, cleanups

git-svn-id: http://www.observium.org/svn/observer/trunk@486 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-10-13 20:07:31 +00:00
parent 1ddbacb7ce
commit 8828225659
8 changed files with 2520 additions and 13 deletions

View File

@@ -26,6 +26,9 @@ if($_GET['debug']) {
} elseif($_GET['if']) {
$device_id = getifhost($_GET['if']);
$ifIndex = getifindexbyid($_GET['if']);
} elseif($_GET['port']) {
$device_id = getifhost($_GET['port']);
$ifIndex = getifindexbyid($_GET['port']);
} elseif($_GET['peer']) {
$device_id = getpeerhost($_GET['peer']);
}

View File

@@ -166,7 +166,7 @@ echo("</td>");
$br = "<br />";
}
unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
# unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
}
@@ -178,9 +178,26 @@ echo("</td>");
P.cpwVcID = '".$pseudowire['cpwVcID']."' AND
P.interface_id = I.interface_id"));
$pw_peer_int = ifNameDescr($pw_peer_int);
echo("<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generateiflink($pw_peer_int, makeshortif($pw_peer_int['label'])) ." on ". generatedevicelink($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . "</b>");
echo("$br<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generateiflink($pw_peer_int, makeshortif($pw_peer_int['label'])) ." on ". generatedevicelink($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . "</b>");
$br = "<br />";
}
$members = mysql_query("SELECT * FROM `interfaces` WHERE `pagpGroupIfIndex` = '".$interface['ifIndex']."' and `device_id` = '".$device['device_id']."'");
while($member = mysql_fetch_array($members)) {
echo("$br<img src='images/16/brick_link.png' align=absmiddle> <strong>" . generateiflink($member) . " (PAgP)</strong>");
$br = "<br />";
}
if($interface['pagpGroupIfIndex'] && $interface['pagpGroupIfIndex'] != $interface['ifIndex']) {
$parent = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE `ifIndex` = '".$interface['pagpGroupIfIndex']."' and `device_id` = '".$device['device_id']."'"));
echo("$br<img src='images/16/bricks.png' align=absmiddle> <strong>" . generateiflink($parent) . " (PAgP)</strong>");
$br = "<br />";
}
unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
echo("</td></tr>");

View File

@@ -42,6 +42,10 @@ $interface = mysql_fetch_array($interface_query);
$broke = yes;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `pagpGroupIfIndex` = '".$interface['ifIndex']."' and `device_id` = '".$device['device_id']."'"),0)) {
$pagp = " | <a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/pagp/'>PAgP</a>";
}
echo("<div style='clear: both;'>");
echo("
@@ -56,7 +60,9 @@ echo("
<div style='margin: auto; text-align: left; padding: 2px 5px; padding-left: 11px; clear: both; display:block; height:20px;'>
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/'>Graphs</a> |
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/arp/'>ARP Table</a>");
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/arp/'>ARP Table</a>$pagp");
if(mysql_result(mysql_query("SELECT count(*) FROM mac_accounting WHERE interface_id = '".$interface['interface_id']."'"),0)){

View File

@@ -236,11 +236,11 @@ function interface_rates ($rrd_file) // Returns the last in/out value in RRD
return $rate;
}
function interface_errors ($rrd_file) // Returns the last in/out errors value in RRD
function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD
{
global $config;
#$rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
$cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
$data = trim(shell_exec($cmd));
foreach( explode("\n", $data) as $entry) {
list($in, $out) = explode(" ", $entry);

View File

@@ -64,4 +64,28 @@ $week = time() - (7 * 24 * 60 * 60);
$month = time() - (31 * 24 * 60 * 60);
$year = time() - (365 * 24 * 60 * 60);
### Update Database between 0.6.0 and 0.6.1 (slight slowdown)
$exists = false;
$columns = mysql_query("SHOW columns FROM `interfaces`");
while($c = mysql_fetch_assoc($columns)){
if($c['Field'] == "pagpOperationMode"){
$pagp = true;
break;
}
}
if(!$pagp) {
mysql_query("ALTER TABLE `interfaces` ADD `pagpOperationMode` VARCHAR( 32 ) NULL ,
ADD `pagpPortState` VARCHAR( 16 ) NULL ,
ADD `pagpPartnerDeviceId` VARCHAR( 48 ) NULL ,
ADD `pagpPartnerLearnMethod` VARCHAR( 16 ) NULL ,
ADD `pagpPartnerIfIndex` INT NULL ,
ADD `pagpPartnerGroupIfIndex` INT NULL ,
ADD `pagpPartnerDeviceName` VARCHAR( 128 ) NULL ,
ADD `pagpEthcOperationMode` VARCHAR( 16 ) NULL ,
ADD `pagpDeviceId` VARCHAR( 48 ) NULL ,
ADD `pagpGroupIfIndex` INT NULL");
}
?>

1005
mibs/CISCO-PAGP-MIB.my Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -13,6 +13,7 @@ function snmp_array($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) {
list ($this_oid, $this_value) = split("=", $entry);
list ($this_oid, $this_index) = explode(".", $this_oid);
@@ -26,26 +27,72 @@ function snmp_array($oid, $device, $array, $mib = 0) {
return $array;
}
$i = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE `ignore` = '0' AND `disabled` = '0' AND `status` = '1' $where ORDER BY device_id DESC");
while ($device = mysql_fetch_array($device_query)) {
echo($device['hostname'] . "\n");
echo("-> " . $device['hostname'] . "\n");
$i++;
$data_oids = array('ifName','ifDescr','ifAlias', 'ifAdminStatus', 'ifOperStatus', 'ifMtu', 'ifSpeed', 'ifHCSpeed', 'ifType', 'ifPhysAddress');
// Build SNMP Cache Array
$data_oids = array('ifName','ifDescr','ifAlias', 'ifAdminStatus', 'ifOperStatus', 'ifMtu', 'ifSpeed', 'ifHighSpeed', 'ifType', 'ifPhysAddress');
$stat_oids = array('ifHCInOctets', 'ifHCOutOctets', 'ifInErrors', 'ifOutErrors', 'ifInUcastPkts', 'ifOutUcastPkts', 'ifInNUcastPkts', 'ifOutNUcastPkts');
$cisco_oids = array('locIfHardType', 'vmVlan', 'vlanTrunkPortEncapsulationOperType');
$etherlike_oids = array('dot3StatsAlignmentErrors', 'dot3StatsFCSErrors', 'dot3StatsSingleCollisionFrames', 'dot3StatsMultipleCollisionFrames', 'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions', 'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors', 'dot3StatsSymbolErrors', 'dot3StatsDuplexStatus');
$cisco_oids = array('locIfHardType', 'vmVlan', 'vlanTrunkPortEncapsulationOperType', 'vlanTrunkPortNativeVlan', 'locIfInRunts', 'locIfInGiants', 'locIfInCRC', 'locIfInFrame', 'locIfInOverrun', 'locIfInIgnored', 'locIfInAbort', 'locIfCollisions', 'locIfInputQueueDrops', 'locIfOutputQueueDrops');
$pagp_oids = array('pagpOperationMode', 'pagpPortState', 'pagpPartnerDeviceId', 'pagpPartnerLearnMethod', 'pagpPartnerIfIndex', 'pagpPartnerGroupIfIndex', 'pagpPartnerDeviceName', 'pagpEthcOperationMode', 'pagpDeviceId', 'pagpGroupIfIndex');
foreach ($data_oids as $oid) {
$array = snmp_array($oid, $device, $array);
# $array = snmp_array($oid, $device, $array);
}
foreach ($stat_oids as $oid) {
$array = snmp_array($oid, $device, $array);
# $array = snmp_array($oid, $device, $array);
}
foreach ($etherlike_oids as $oid) {
# $array = snmp_array($oid, $device, $array, "EtherLike-MIB");
}
foreach ($cisco_oids as $oid) {
$array = snmp_array($oid, $device, $array, "CISCO-SMI:CISCO-VLAN-MEMBERSHIP-MIB:CISCO-VTP-MIB");
# $array = snmp_array($oid, $device, $array, "CISCO-SMI:CISCO-VLAN-MEMBERSHIP-MIB:CISCO-VTP-MIB:OLD-CISCO-INTERFACES-MIB");
}
foreach ($pagp_oids as $oid) {
$array = snmp_array($oid, $device, $array, "CISCO-PAGP-MIB");
}
// End Building SNMP Cache Array
// New interface detection
///// TO DO
// End New interface detection
// Loop interfaces in the DB and update where necessary
$port_query = mysql_query("SELECT * FROM `interfaces` WHERE `device_id` = '".$device['device_id']."'");
while ($port = mysql_fetch_array($port_query)) {
echo(" --> " . $port['ifDescr'] . " ");
if($array[$device[device_id]][$port[ifIndex]]) { // Check to make sure Port data is cached.
$this_port = $array[$device[device_id]][$port[ifIndex]];
if($this_port['pagpOperationMode']) { // Check if this port has PAgP enabled.
echo($this_port['pagpOperationMode'] ." -> " . $port['pagpOperationMode'] . " ");
unset($separator); unset($update);
foreach ($pagp_oids as $oid) { // Loop the OIDs
if ( $this_port[$oid] != $port[$oid] ) { // If data has changed, build a query
$update .= $separator . "`$oid` = '".$this_port[$oid]."'";
$separator = ", ";
}
}
if ($update) {
$update_query = "UPDATE `interfaces` SET ";
$update_query .= $update;
$update_query .= " WHERE `interface_id` = '" . $port['interface_id'] . "'";
@mysql_query($update_query);
echo("PAgP ");
unset($separator); unset($update_query); unset($update);
}
}
} else {
echo("Port Deleted?"); // Port missing from SNMP cache?
}
echo("\n");
}
print_r($array);
unset($array);
echo("\n");
}
echo("$i devices polled");