Browse Source

Better port identification for Cisco STP extensions via Entity MIB

Barry O'Donovan 13 years ago
parent
commit
54e87936ac
4 changed files with 1749 additions and 140 deletions
  1. 5 1
      OSS/SNMP/MIBS/Cisco/RSTP.php
  2. 184 0
      OSS/SNMP/MIBS/Entity.php
  3. 1541 129
      OSS/SNMP/MIBS/Iface.php
  4. 19 10
      examples/interfaces.php

+ 5 - 1
OSS/SNMP/MIBS/Cisco/RSTP.php

@@ -151,7 +151,11 @@ class RSTP extends \OSS\SNMP\MIBS\Cisco
             if( $base )
                 $croles[ $base ] = $v;
             else
-                $croles[ $k + 10100 ] = $v;       // FIXME Hack... basePortIfIndexes() does not have all ports...
+            {
+                // and and get port ID from MIBS\Entity
+                // TODO Find a better way to translate these?
+                $croles[ $this->getSNMP()->useEntity()->relPosToAlias()[$k] ] = $v;
+            }
         }
 
         if( !$translate )

+ 184 - 0
OSS/SNMP/MIBS/Entity.php

@@ -0,0 +1,184 @@
+<?php
+
+/*
+    Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
+    All rights reserved.
+
+    Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
+             http://www.opensolutions.ie/
+
+    This file is part of the OSS_SNMP package.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+        * Redistributions of source code must retain the above copyright
+          notice, this list of conditions and the following disclaimer.
+        * Redistributions in binary form must reproduce the above copyright
+          notice, this list of conditions and the following disclaimer in the
+          documentation and/or other materials provided with the distribution.
+        * Neither the name of Open Source Solutions Limited nor the
+          names of its contributors may be used to endorse or promote products
+          derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+namespace OSS\SNMP\MIBS;
+
+/**
+ * A class for performing SNMP V2 queries on generic devices
+ *
+ * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
+ * @author Barry O'Donovan <barry@opensolutions.ie>
+ */
+class Entity extends \OSS\SNMP\MIB
+{
+    const OID_ENTITY_PHYSICAL_CLASS          = '.1.3.6.1.2.1.47.1.1.1.1.5';
+    const OID_ENTITY_PHYSICAL_PARENT_REL_POS = '.1.3.6.1.2.1.47.1.1.1.1.6';
+    const OID_ENTITY_PHYSICAL_ALIAS          = '.1.3.6.1.2.1.47.1.1.1.1.14';
+
+
+
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_CHASSIS = 3;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_CONTAINER = 5;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_POWER_SUPPLY = 6;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_FAN = 7;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_SENSOR = 8;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_MODULE = 9;
+
+    /**
+     * Physical entitly class type
+     * @var Physical entitly class type
+     */
+    const PHYSICAL_CLASS_PORT = 10;
+
+
+    /**
+     * Translator array for physical class types
+     * @var array Translator array for physical class types
+     */
+    public static $ENTITY_PHSYICAL_CLASS = array(
+        self::PHYSICAL_CLASS_CHASSIS      => 'chassis',
+        self::PHYSICAL_CLASS_CONTAINER    => 'container',
+        self::PHYSICAL_CLASS_POWER_SUPPLY => 'powerSupply',
+        self::PHYSICAL_CLASS_FAN          => 'fan',
+        self::PHYSICAL_CLASS_SENSOR       => 'sensor',
+        self::PHYSICAL_CLASS_MODULE       => 'module',
+        self::PHYSICAL_CLASS_PORT         => 'port'
+    );
+
+    /**
+     * Returns an associate array of entPhysicalClass
+     *
+     * e.g.  [1005] => 10 / port
+     *
+     *
+     * @param boolean $translate If true, return the string representation via self::$ENTITY_PHSYICAL_CLASS
+     * @return array Associate array of entPhysicalClass
+     */
+    public function physicalClass( $translate = false )
+    {
+        $classes = $this->getSNMP()->walk1d( self::OID_ENTITY_PHYSICAL_CLASS );
+
+        if( !$translate )
+            return $classes;
+
+        return $this->getSNMP()->translate( $classes, self::$ENTITY_PHSYICAL_CLASS );
+    }
+
+
+    /**
+     * Returns an associate array of entPhysicalParentRelPos
+     *
+     * e.g.  [1005] => 1
+     *
+     *
+     * @return array Associate array of entPhysicalParentRelPos
+     */
+    public function physicalParentRelPos()
+    {
+        return $this->getSNMP()->walk1d( self::OID_ENTITY_PHYSICAL_PARENT_REL_POS );
+    }
+
+    /**
+     * Returns an associate array of physical aliases
+     *
+     * e.g.  [1005] => 10001
+     *
+     *
+     * @return array Associate array of physical aliases
+     */
+    public function physicalAlias()
+    {
+        return $this->getSNMP()->walk1d( self::OID_ENTITY_PHYSICAL_ALIAS );
+    }
+
+
+    /**
+     * Utility function for MIBS\Cisco\RSTP::rstpPortRole() to try and translate a port index
+     * into a port ID
+     *
+     * Makes a number of assumptions including that it has to be of type port, that the ID must be >10000,
+     * etc.
+     *
+     * @return Array of relative positions to port IDs
+     */
+    public function relPosToAlias()
+    {
+        $rtn = [];
+        $aliases = $this->physicalAlias();
+        foreach( $this->physicalParentRelPos() as $index => $pos )
+        {
+            if( isset( $aliases[ $index ] ) && strlen( $aliases[ $index ] )
+                    && is_numeric( $aliases[ $index ] ) && $aliases[ $index ] > 10000
+                    && !isset( $rtn[ $pos ] ) && $this->physicalClass()[ $index ] == self::PHYSICAL_CLASS_PORT )
+                $rtn[ $pos ] = $aliases[ $index ];
+        }
+
+        return $rtn;
+    }
+
+
+}
+
+

File diff suppressed because it is too large
+ 1541 - 129
OSS/SNMP/MIBS/Iface.php


+ 19 - 10
examples/interfaces.php

@@ -4,15 +4,15 @@
 /*
     Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
     All rights reserved.
-    
+
     Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
     http://www.opensolutions.ie/
-    
+
     This file is part of the OSS_SNMP package.
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
-    
+
     * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
@@ -21,7 +21,7 @@
     * Neither the name of Open Source Solutions Limited nor the
     names of its contributors may be used to endorse or promote products
     derived from this software without specific prior written permission.
-    
+
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -53,7 +53,7 @@ This is an example script to show how to use OSS_SNMP. It requires two or three
  - the IP address of hostname of a SNMP capable host
  - the SNMP v2 community string for that host
  - the index of the interface to show details for
- 
+
 If the third argument is missing, it will print interface indexes and names.
 
 For example:
@@ -75,20 +75,20 @@ if( count( $argv ) == 3 )
     echo "\nNumber of interfaces on {$argv[1]}: " . $host->useIface()->numberofInterfaces() . "\n\n";
 
     echo "ID:  Name  - Descrition - Type - Admin/Operational State\n\n";
-    
+
     foreach( $host->useIface()->names() as $id => $name )
     {
         echo "{$id}: {$name} - {$host->useIface()->descriptions()[$id]} - {$host->useIface()->types(1)[$id]}"
             . " - {$host->useIface()->adminStates(1)[$id]}/{$host->useIface()->operationStates(1)[$id]}\n";
     }
-    
+
     echo "\n";
     exit( 0 );
 }
 
 $names = $host->useIface()->names();
 $id = $argv[3];
- 
+
 if( !isset( $names[ $id ] ) )
 {
     echo "Unknown interface index!\n";
@@ -110,6 +110,11 @@ Speeds:                    {$host->useIface()->speeds()[$id]}
 Physical Address:          {$host->useIface()->physAddresses()[$id]}
 Last Change:               {$host->useIface()->lastChanges()[$id]}
 
+INTINFO;
+
+try
+{
+    echo <<<INTINFO
 In/Out Octets:             {$host->useIface()->inOctets()[$id]} / {$host->useIface()->outOctets()[$id]}
 In/Out Unicast:            {$host->useIface()->inUnicastPackets()[$id]} / {$host->useIface()->outUnicastPackets()[$id]}
 In/Out Non Unicats:        {$host->useIface()->inNonUnicastPackets()[$id]} / {$host->useIface()->outNonUnicastPackets()[$id]}
@@ -119,7 +124,11 @@ In/Out Errors:             {$host->useIface()->inErrors()[$id]} / {$host->useIfa
 In Unknown Protocols:      {$host->useIface()->inUnknownProtocols()[$id]}
 Out Queue Length:          {$host->useIface()->outQueueLength()[$id]}
 
-
 INTINFO;
+}
+catch( \OSS\Exception $e )
+{
+    echo "\nCould not poll interface statistics for this interface.\n";
+}
 
 exit( 0 );