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