コード例 #1
0
ファイル: assets.inc.php プロジェクト: ghasedak/openDCIM
 private static function OSS_SNMP_Lookup($dev, $snmplookup, $portid = null, $baseoid = null)
 {
     // This is find out the name of the function that called this to make the error logging more descriptive
     $caller = debug_backtrace();
     $caller = $caller[1]['function'];
     // Since we don't really let the user specify the version right now here's a stop gap
     // Try the default version of 2c first
     $snmpHost = new OSS_SNMP\SNMP($dev->PrimaryIP, $dev->SNMPCommunity, $dev->SNMPVersion, $dev->v3SecurityLevel, $dev->v3AuthProtocol, $dev->v3AuthPassphrase, $dev->v3PrivProtocol, $dev->v3PrivPassphrase);
     try {
         $snmpHost->useSystem()->name();
     } catch (Exception $e) {
         // That shit the bed so drop down to 1
         $snmpHost = new OSS_SNMP\SNMP($dev->PrimaryIP, $dev->SNMPCommunity, 1);
     }
     $snmpresult = false;
     try {
         $snmpresult = is_null($portid) ? $snmpHost->useIface()->{$snmplookup}(true) : $snmpHost->get($baseOID . ".{$portid}");
     } catch (Exception $e) {
         error_log("SwitchInfo::{$caller}({$dev->DeviceID}) " . $e->getMessage());
     }
     return $snmpresult;
 }
コード例 #2
0
ファイル: interfaces.php プロジェクト: lsqtongxin/OSS_SNMP
 - the index of the interface to show details for

If the third argument is missing, it will print interface indexes and names.

For example:

    {$argv[0]} 192.168.10.20 public


HELPTEXT;
    exit(1);
}
require_once dirname(__FILE__) . '/../OSS_SNMP/SNMP.php';
$host = new \OSS_SNMP\SNMP($argv[1], $argv[2]);
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";
    exit(2);
}
$hdr = "\nInterface information for {$names[$id]} ({$host->useIface()->descriptions()[$id]})";
echo $hdr . "\n" . str_repeat('=', strlen($hdr)) . "\n\n";
コード例 #3
0
 /**
  */
 public function portRolesAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->view->portRolesDevice = $device = $this->_getParam('portRolesDevice');
         $this->view->limitToInstance = $limitToInstance = $this->_getParam('limitToInstance', false);
         $this->view->type = $type = $this->getParam('type', 'rstp');
         try {
             $host = new \OSS_SNMP\SNMP($device, $this->_options['community']);
             switch ($type) {
                 case 'mst':
                     $instances = $host->useCisco_SMST()->instances();
                     break;
                 case 'rstp':
                 default:
                     $instances = $host->useCisco_VTP()->vlanNames();
             }
         } catch (\OSS_SNMP\Exception $e) {
             $this->addMessage("Could not query instance and port role information via SNMP from " . $device, OSS_Message::ERROR);
             return;
         }
         $roles = [];
         $unknowns = [];
         $portsInSTP = [];
         if ($limitToInstance && isset($instances[$limitToInstance])) {
             $doInstances[$limitToInstance] = $instances[$limitToInstance];
         } else {
             $doInstances = $instances;
         }
         foreach ($doInstances as $iid => $iname) {
             try {
                 if ($type == 'mst') {
                     $roles[$iid] = $host->useCisco_MST()->portRoles($iid, true);
                 } else {
                     $roles[$iid] = $host->useCisco_RSTP()->portRoles($iid, true);
                 }
                 foreach ($roles[$iid] as $portId => $role) {
                     if (!isset($portsInSTP[$portId])) {
                         $portsInSTP[$portId] = $portId;
                     }
                 }
             } catch (\OSS_SNMP\Exception $e) {
                 $unknowns[$iid] = $iname;
             }
         }
         ksort($portsInSTP, SORT_NUMERIC);
         $this->view->portsInSTP = $portsInSTP;
         $this->view->ports = $host->useIface()->names();
         $this->view->instances = $instances;
         $this->view->roles = $roles;
         $this->view->unknowns = $unknowns;
         unset($host);
     }
 }
コード例 #4
0
ファイル: mau.php プロジェクト: lsqtongxin/OSS_SNMP
See: https://github.com/opensolutions/OSS_SNMP/

This is an example script to show how to use OSS_SNMP. It requires two or three arguments:

 - the IP address of hostname of a SNMP capable host
 - the SNMP v2 community string for that host

For example:

    {$argv[0]} 192.168.10.20 public


HELPTEXT;
    exit(1);
}
require_once dirname(__FILE__) . '/../OSS_SNMP/SNMP.php';
$host = new \OSS_SNMP\SNMP($argv[1], $argv[2]);
if (count($argv) == 3) {
    echo "\nNumber of interfaces on {$argv[1]}: " . $host->useIface()->numberofInterfaces() . "\n\n";
    echo "ID:  Name  - Index - Type - State - Media Available - Jack Type - State Exits - Jabber State - Autoneg\n\n";
    foreach ($host->useIface()->names() as $id => $name) {
        if ($id > 1100) {
            continue;
        }
        echo "{$id}: {$name} - {$host->useMAU()->index()[$id]}" . " - {$host->useMAU()->types(true)[$id]}" . " - {$host->useMAU()->states(true)[$id]}" . " - {$host->useMAU()->mediaAvailable(true)[$id]}" . " - {$host->useMAU()->jackTypes(true)[$id]}" . " - {$host->useMAU()->mediaAvailableStateExits()[$id]}" . " - {$host->useMAU()->jabberStates(true)[$id]}" . " - " . ($host->useMAU()->autonegSupported()[$id] ? 'Y' : 'N') . " - " . ($host->useMAU()->autonegAdminState()[$id] ? 'Y' : 'N') . "\n";
    }
    echo "\n";
    exit(0);
}
exit(0);
コード例 #5
0
// The array key is the hostname.  The value is the shortened snmp name.
$ignoreports = [];
// parse the command line arguments
parseArguments();
// create a memcache key:
$MCKEY = 'NAGIOS_CHECK_PORT_ERRORS_' . md5($cmdargs['host']);
if (!class_exists('Memcache')) {
    die("ERROR: php5-memcache is required\n");
}
$mc = new Memcache();
$mc->connect('localhost', 11211) or die("ERROR: Could not connect to memcache on localhost:11211\n");
_log("Connected to Memcache with version: " . $mc->getVersion(), LOG__DEBUG);
require 'OSS_SNMP/OSS_SNMP/SNMP.php';
$snmp = new \OSS_SNMP\SNMP($cmdargs['host'], $cmdargs['community']);
// get interface types for later filtering
$types = $snmp->useIface()->types();
$names = filterForType($snmp->useIface()->names(), $types, OSS_SNMP\MIBS\Iface::IF_TYPE_ETHERNETCSMACD);
_log("Found " . count($names) . " physical ethernet ports", LOG__DEBUG);
// get current error counters
$ifInErrors = filterForType($snmp->useIface()->inErrors(), $types, OSS_SNMP\MIBS\Iface::IF_TYPE_ETHERNETCSMACD);
$ifOutErrors = filterForType($snmp->useIface()->outErrors(), $types, OSS_SNMP\MIBS\Iface::IF_TYPE_ETHERNETCSMACD);
_log("Found " . count($ifInErrors) . " entries for in errors on physical ethernet ports", LOG__DEBUG);
_log("Found " . count($ifOutErrors) . " entries for out errors on physical ethernet ports", LOG__DEBUG);
// delete unwanted entries
foreach (array_keys($ignoreports) as $hostkey) {
    if ($cmdargs['host'] == $hostkey) {
        $portid = array_keys($names, $ignoreports[$hostkey])[0];
        if (isset($portid)) {
            unset($ifInErrors[$portid]);
            unset($ifOutErrors[$portid]);
        }