xref: /PHP-5.4/ext/snmp/tests/snmp-object.phpt (revision 8c3b8f39)
1--TEST--
2OO API
3--CREDITS--
4Boris Lytochkin
5--SKIPIF--
6<?php
7require_once(dirname(__FILE__).'/skipif.inc');
8?>
9--FILE--
10<?php
11require_once(dirname(__FILE__).'/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 "SNMPv1\n";
20$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
21$session->valueretrieval = SNMP_VALUE_LIBRARY;
22var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
23var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0')));
24var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
25var_dump($session->close());
26
27echo "SNMPv2\n";
28$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
29var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
30var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
31var_dump($session->close());
32
33echo "GET with preserving original OID names\n";
34$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
35$orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0');
36$result = $session->get($orig, TRUE);
37foreach($orig as $oid){
38	var_dump($result[$oid]);
39}
40var_dump($session->close());
41
42echo "WALK multiple on single OID\n";
43$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
44$z = $session->walk('.1.3.6.1.2.1.1');
45var_dump(gettype($z));
46var_dump(count($z));
47var_dump(key($z));
48var_dump(array_shift($z));
49var_dump($session->close());
50
51echo "WALK multiple on single OID, max_repetitions set to 30\n";
52$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
53$z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30);
54var_dump(gettype($z));
55var_dump(count($z));
56var_dump(key($z));
57var_dump(array_shift($z));
58var_dump($session->close());
59
60echo "WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0\n";
61$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
62$z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30, 0);
63var_dump(gettype($z));
64var_dump(count($z));
65var_dump(key($z));
66var_dump(array_shift($z));
67var_dump($session->close());
68
69echo "WALK multiple on single OID, max_oids set to 30\n";
70$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
71$session->max_oids = 30;
72$z = $session->walk('.1.3.6.1.2.1.1');
73var_dump(gettype($z));
74var_dump(count($z));
75var_dump(key($z));
76var_dump(array_shift($z));
77var_dump($session->close());
78
79echo "WALK multiple on single OID with OID suffix as keys\n";
80$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
81$z = $session->walk('.1.3.6.1.2.1.1', TRUE);
82var_dump(gettype($z));
83var_dump(count($z));
84var_dump(key($z));
85var_dump(array_shift($z));
86var_dump(key($z));
87array_shift($z);
88var_dump(key($z));
89array_shift($z);
90var_dump(key($z));
91array_shift($z);
92var_dump(key($z));
93var_dump($session->close());
94
95echo "SNMPv3 (default security settings)\n";
96$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
97#$session->setSecurity($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
98var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
99var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
100var_dump($session->close());
101
102echo "SNMPv3 (noAuthNoPriv)\n";
103$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
104$session->setSecurity('noAuthNoPriv');
105var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
106var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
107var_dump($session->close());
108
109echo "SNMPv3 (authPriv)\n";
110$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
111$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
112var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
113var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
114var_dump($session->walk('.1.3.6.1.2.1.1.1.0'));
115var_dump($session->close());
116
117echo "SET single OID\n";
118$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
119$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
120$oid1 = 'SNMPv2-MIB::sysContact.0';
121$oldvalue1 = $session->get($oid1);
122$newvalue1 = $oldvalue1 . '0';
123
124$z = $session->set($oid1, 's', $newvalue1);
125var_dump($z);
126var_dump(($session->get($oid1) === $newvalue1));
127$z = $session->set($oid1, 's', $oldvalue1);
128var_dump($z);
129var_dump(($session->get($oid1) === $oldvalue1));
130var_dump($session->close());
131
132echo "Multiple OID with max_oids = 1\n";
133$oid2 = 'SNMPv2-MIB::sysLocation.0';
134$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
135$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
136$session->max_oids = 1;
137$oldvalue2 = $session->get($oid2);
138$newvalue2 = $oldvalue2 . '0';
139$z = $session->set(array($oid1, $oid2), array('s','s'), array($newvalue1, $newvalue2));
140var_dump($z);
141var_dump(($session->get($oid1) === $newvalue1));
142var_dump(($session->get($oid2) === $newvalue2));
143$z = $session->set(array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2));
144var_dump($z);
145var_dump(($session->get($oid1) === $oldvalue1));
146var_dump(($session->get($oid2) === $oldvalue2));
147var_dump($session->close());
148
149echo "SNMPv3, setting contextEngineID (authPriv)\n";
150$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
151$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
152var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
153var_dump($session->close());
154
155?>
156--EXPECTF--
157SNMPv1
158string(%d) "%S"
159array(2) {
160  ["%s"]=>
161  string(%d) "%S"
162  ["%s"]=>
163  string(%d) "%S"
164}
165string(%d) "%S"
166bool(true)
167SNMPv2
168string(%d) "%S"
169string(%d) "%S"
170bool(true)
171GET with preserving original OID names
172string(%d) "%s"
173string(%d) "%s"
174bool(true)
175WALK multiple on single OID
176string(5) "array"
177int(%d)
178string(%d) "%S"
179string(%d) "%S"
180bool(true)
181WALK multiple on single OID, max_repetitions set to 30
182string(5) "array"
183int(%d)
184string(%d) "%S"
185string(%d) "%S"
186bool(true)
187WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0
188string(5) "array"
189int(%d)
190string(%d) "%S"
191string(%d) "%S"
192bool(true)
193WALK multiple on single OID, max_oids set to 30
194string(5) "array"
195int(%d)
196string(%d) "%S"
197string(%d) "%S"
198bool(true)
199WALK multiple on single OID with OID suffix as keys
200string(5) "array"
201int(%d)
202string(3) "1.0"
203string(%d) "%s"
204string(3) "2.0"
205string(3) "3.0"
206string(3) "4.0"
207string(3) "5.0"
208bool(true)
209SNMPv3 (default security settings)
210string(%d) "%S"
211string(%d) "%S"
212bool(true)
213SNMPv3 (noAuthNoPriv)
214string(%d) "%S"
215string(%d) "%S"
216bool(true)
217SNMPv3 (authPriv)
218string(%d) "%S"
219string(%d) "%S"
220array(1) {
221  [%s]=>
222  string(%d) "%S"
223}
224bool(true)
225SET single OID
226bool(true)
227bool(true)
228bool(true)
229bool(true)
230bool(true)
231Multiple OID with max_oids = 1
232
233Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
234bool(true)
235bool(true)
236bool(true)
237
238Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
239bool(true)
240bool(true)
241bool(true)
242bool(true)
243SNMPv3, setting contextEngineID (authPriv)
244string(%d) "%S"
245bool(true)
246