1--TEST-- 2OO API: getErrno & getError methods 3--CREDITS-- 4Boris Lytochkin 5--EXTENSIONS-- 6snmp 7--SKIPIF-- 8<?php 9require_once(__DIR__.'/skipif.inc'); 10if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN'); 11?> 12--FILE-- 13<?php 14require_once(__DIR__.'/snmp_include.inc'); 15 16//EXPECTF format is quickprint OFF 17snmp_set_enum_print(false); 18snmp_set_quick_print(false); 19snmp_set_valueretrieval(SNMP_VALUE_PLAIN); 20snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL); 21 22echo "SNMP::ERRNO_NOERROR\n"; 23$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); 24var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); 25var_dump($session->getErrno() == SNMP::ERRNO_NOERROR); 26var_dump($session->getError()); 27$session->close(); 28 29echo "SNMP::ERRNO_TIMEOUT\n"; 30$session = new SNMP(SNMP::VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries); 31$session->valueretrieval = SNMP_VALUE_LIBRARY; 32var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); 33var_dump($session->getErrno() == SNMP::ERRNO_TIMEOUT); 34var_dump($session->getError()); 35$session->close(); 36 37echo "SNMP::ERRNO_ERROR_IN_REPLY\n"; 38$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); 39var_dump(@$session->get('.1.3.6.1.2.1.1.1.110')); 40var_dump($session->getErrno() == SNMP::ERRNO_ERROR_IN_REPLY); 41var_dump($session->getError()); 42$session->close(); 43 44echo "SNMP::ERRNO_GENERIC\n"; 45$session = new SNMP(SNMP::VERSION_3, $hostname, 'somebogususer', $timeout, $retries); 46$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); 47var_dump(@$session->get('.1.3.6.1.2.1.1.1.0')); 48var_dump($session->getErrno() == SNMP::ERRNO_GENERIC); 49var_dump($session->getError()); 50var_dump(@$session->get(array('.1.3.6.1.2.1.1.1.0'))); 51$session->close(); 52 53echo "SNMP::ERRNO_OID_PARSING_ERROR\n"; 54echo "GET: Single wrong OID\n"; 55$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); 56var_dump(@$session->get('.1.3.6.1.2..1.1.1.0')); 57var_dump($session->getErrno() == SNMP::ERRNO_OID_PARSING_ERROR); 58var_dump($session->getError()); 59$session->close(); 60echo "GET: Miltiple OID, one wrong\n"; 61$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); 62var_dump(@$session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2..1.1.1.0'))); 63var_dump($session->getErrno() == SNMP::ERRNO_OID_PARSING_ERROR); 64var_dump($session->getError()); 65$session->close(); 66echo "WALK: Single wrong OID\n"; 67$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries); 68var_dump(@$session->walk('.1.3.6.1.2..1.1')); 69var_dump($session->getErrno() == SNMP::ERRNO_OID_PARSING_ERROR); 70var_dump($session->getError()); 71$session->close(); 72echo "SET: Wrong type\n"; 73$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries); 74$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); 75$oid1 = 'SNMPv2-MIB::sysContact.0'; 76var_dump(@$session->set($oid1, 'q', 'blah')); 77var_dump($session->getErrno() == SNMP::ERRNO_OID_PARSING_ERROR); 78var_dump($session->getError()); 79 80echo "SNMP::ERRNO_MULTIPLE_SET_QUERIES\n"; 81$oid1 = 'SNMPv2-MIB::sysContact.0'; 82$oid2 = 'SNMPv2-MIB::sysLocation.0'; 83$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries); 84$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass); 85$session->max_oids = 1; 86$oldvalue1 = $session->get($oid1); 87$newvalue1 = $oldvalue1 . '0'; 88$oldvalue2 = $session->get($oid2); 89$newvalue2 = $oldvalue2 . '0'; 90$z = @$session->set(array($oid1, $oid2), array('s','s'), array($newvalue1, $newvalue2)); 91var_dump($z); 92var_dump($session->getErrno() == SNMP::ERRNO_MULTIPLE_SET_QUERIES); 93var_dump($session->getError()); 94var_dump(($session->get($oid1) === $newvalue1)); 95var_dump(($session->get($oid2) === $newvalue2)); 96$z = @$session->set(array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2)); 97var_dump($z); 98var_dump($session->getErrno() == SNMP::ERRNO_MULTIPLE_SET_QUERIES); 99var_dump($session->getError()); 100var_dump(($session->get($oid1) === $oldvalue1)); 101var_dump(($session->get($oid2) === $oldvalue2)); 102var_dump($session->close()); 103?> 104--EXPECTF-- 105SNMP::ERRNO_NOERROR 106string(%d) "%s" 107bool(true) 108string(0) "" 109SNMP::ERRNO_TIMEOUT 110bool(false) 111bool(true) 112string(%d) "No response from %s" 113SNMP::ERRNO_ERROR_IN_REPLY 114bool(false) 115bool(true) 116string(%d) "Error in packet %s" 117SNMP::ERRNO_GENERIC 118bool(false) 119bool(true) 120string(%d) "Fatal error: Unknown user name" 121bool(false) 122SNMP::ERRNO_OID_PARSING_ERROR 123GET: Single wrong OID 124bool(false) 125bool(true) 126string(46) "Invalid object identifier: .1.3.6.1.2..1.1.1.0" 127GET: Miltiple OID, one wrong 128bool(false) 129bool(true) 130string(46) "Invalid object identifier: .1.3.6.1.2..1.1.1.0" 131WALK: Single wrong OID 132bool(false) 133bool(true) 134string(42) "Invalid object identifier: .1.3.6.1.2..1.1" 135SET: Wrong type 136bool(false) 137bool(true) 138string(129) "Could not add variable: OID='.iso.org.dod.internet.mgmt.mib-2.system.sysContact.0' type='q' value='blah': Bad variable type ("q")" 139SNMP::ERRNO_MULTIPLE_SET_QUERIES 140bool(true) 141bool(true) 142string(73) "Cannot fit all OIDs for SET query into one packet, using multiple queries" 143bool(true) 144bool(true) 145bool(true) 146bool(true) 147string(73) "Cannot fit all OIDs for SET query into one packet, using multiple queries" 148bool(true) 149bool(true) 150bool(true) 151