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