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