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