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