xref: /PHP-8.0/ext/snmp/tests/snmp2_get.phpt (revision 62c20c66)
1--TEST--
2Function snmp2_get
3--CREDITS--
4Olivier Doucet & Boris 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_quick_print(false);
15snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
16
17echo "Checking error handling\n";
18echo "Empty OID array\n";
19try {
20    var_dump(snmp2_get($hostname, $community, array(), $timeout, $retries));
21} catch (\ValueError $e) {
22    echo $e->getMessage() . \PHP_EOL;
23}
24
25echo "Checking working\n";
26echo "Single OID\n";
27var_dump(snmp2_get($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
28echo "Single OID in array\n";
29var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1.1.1.0'), $timeout, $retries));
30echo "Multiple OID\n";
31var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
32
33echo "More error handling\n";
34echo "Single OID\n";
35var_dump(snmp2_get($hostname, $community, '.1.3.6.1.2..1.1.1.0', $timeout, $retries));
36echo "Single OID in array\n";
37var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1...1.1.0'), $timeout, $retries));
38echo "Multiple OID\n";
39var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1...1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
40
41echo "noSuchName checks\n";
42echo "Single OID\n";
43var_dump(snmp2_get($hostname, $community, '.1.3.6.1.2.1.1.1.110', $timeout, $retries));
44echo "Single OID in array\n";
45var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1.1.1.110'), $timeout, $retries));
46echo "Multiple OID\n";
47var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.220'), $timeout, $retries));
48
49
50?>
51--EXPECTF--
52Checking error handling
53Empty OID array
54Array of object IDs cannot be empty
55Checking working
56Single OID
57string(%d) "%s"
58Single OID in array
59array(1) {
60  ["%s"]=>
61  string(%d) "%s"
62}
63Multiple OID
64array(2) {
65  ["%s"]=>
66  string(%d) "%s"
67  ["%s"]=>
68  string(%d) "%d"
69}
70More error handling
71Single OID
72
73Warning: snmp2_get(): Invalid object identifier: .1.3.6.1.2..1.1.1.0 in %s on line %d
74bool(false)
75Single OID in array
76
77Warning: snmp2_get(): Invalid object identifier: .1.3.6.1.2.1...1.1.0 in %s on line %d
78bool(false)
79Multiple OID
80
81Warning: snmp2_get(): Invalid object identifier: .1.3.6.1.2.1...1.1.0 in %s on line %d
82bool(false)
83noSuchName checks
84Single OID
85
86Warning: snmp2_get(): Error in packet at '%s': No Such Instance currently exists at this OID in %s on line %d
87bool(false)
88Single OID in array
89
90Warning: snmp2_get(): Error in packet at '%s': No Such Instance currently exists at this OID in %s on line %d
91bool(false)
92Multiple OID
93
94Warning: snmp2_get(): Error in packet at '%s': No Such Instance currently exists at this OID in %s on line %d
95array(1) {
96  ["%s"]=>
97  string(%d) "%s"
98}
99