function OSS_SNMP_Lookup($dev, $snmplookup, $oid = null) { // This is find out the name of the function that called this to make the error logging more descriptive $caller = "OSS_SNMP_Lookup"; $failed = false; $snmpHost = new OSS_SNMP\SNMP($dev->PrimaryIP, $dev->SNMPCommunity, $dev->SNMPVersion, $dev->v3SecurityLevel, $dev->v3AuthProtocol, $dev->v3AuthPassphrase, $dev->v3PrivProtocol, $dev->v3PrivPassphrase); $snmpresult = false; try { $snmpresult = is_null($oid) ? $snmpHost->useSystem()->{$snmplookup}(true) : $snmpHost->get($oid); } catch (Exception $e) { IncrementFailures($dev->DeviceID); $failed = true; error_log("PowerDistribution::{$caller}({$dev->DeviceID}) " . $e->getMessage()); } if (!$failed) { ResetFailures($dev->DeviceID); } return $snmpresult; }
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; }
// SNMP Test if (isset($_POST['snmptest'])) { // Parse through the post data and pull in site defaults if necessary $community = $_POST['SNMPCommunity'] == "" ? $config->ParameterArray["SNMPCommunity"] : $_POST['SNMPCommunity']; $version = $_POST['SNMPVersion'] == "" ? $config->ParameterArray["SNMPVersion"] : $_POST['SNMPVersion']; $v3SecurityLevel = $_POST['v3SecurityLevel'] == "" ? $config->ParameterArray["v3SecurityLevel"] : $_POST['v3SecurityLevel']; $v3AuthProtocol = $_POST['v3AuthProtocol'] == "" ? $config->ParameterArray["v3AuthProtocol"] : $_POST['v3AuthProtocol']; $v3AuthPassphrase = $_POST['v3AuthPassphrase'] == "" ? $config->ParameterArray["v3AuthPassphrase"] : $_POST['v3AuthPassphrase']; $v3PrivProtocol = $_POST['v3PrivProtocol'] == "" ? $config->ParameterArray["v3PrivProtocol"] : $_POST['v3PrivProtocol']; $v3PrivPassphrase = $_POST['v3PrivPassphrase'] == "" ? $config->ParameterArray["v3PrivPassphrase"] : $_POST['v3PrivPassphrase']; // Init the snmp handler $snmpHost = new OSS_SNMP\SNMP($_POST['PrimaryIP'], $community, $version, $v3SecurityLevel, $v3AuthProtocol, $v3AuthPassphrase, $v3PrivProtocol, $v3PrivPassphrase); // Try to connect to keep us from killing the system on a failure $error = false; try { $snmpresults = $snmpHost->useSystem()->name(); } catch (Exception $e) { $error = true; } // Show the end user something to make them feel good about it being correct if (!$error) { foreach ($snmpHost->realWalk('1.3.6.1.2.1.1') as $oid => $value) { print "{$oid} => {$value} <br>\n"; } } else { print __("Something isn't working correctly"); } exit; } // Get CDU uptime if (isset($_POST['cduuptime'])) {
Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland All rights reserved. See: https://github.com/opensolutions/OSS_SNMP/ This is an example script to show how to use OSS_SNMP. It requires two arguments: - the IP address of hostname of a SNMP capable host (with Asterisk SNMP enabled) - 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]); echo "\nSystem information for {$argv[1]}:\n\n"; print_r($host->useSystem()->getAll()); echo "\n\n"; echo "\n\nPlatform details for {$argv[1]}:\n" . "\nVendor: " . $host->getPlatform()->getVendor() . "\nModel: " . $host->getPlatform()->getModel() . "\nOS: " . $host->getPlatform()->getOs() . "\nOS Version: " . $host->getPlatform()->getOsVersion(); echo "\n\n"; echo "Temperature alarm: " . ($host->useExtreme_System_Common()->overTemperatureAlarm() ? 'YES' : 'NO') . "\n"; echo "Temperature : " . $host->useExtreme_System_Common()->currentTemperature() . "C\n"; echo "\n\n"; print_r($host->useExtreme_SwMonitor_Memory()->percentUsage()); echo "\n\n"; exit(0);