xref: /PHP-8.3/ext/snmp/tests/snmpget.phpt (revision ba1d9d0a)
1--TEST--
2Function snmpget
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 working\n";
21echo "Single OID, default timeout and retries\n";
22var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0'));
23echo "Single OID, default retries\n";
24var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout));
25echo "Single OID\n";
26var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
27echo "Single OID in array\n";
28var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.0'), $timeout, $retries));
29echo "Multiple OID\n";
30var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
31
32echo "More error handling\n";
33echo "Single OID\n";
34var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1..1.1.0', $timeout, $retries));
35echo "Single OID in array\n";
36var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1...1.1.0'), $timeout, $retries));
37echo "Multiple OID\n";
38var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1...1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
39
40echo "noSuchName checks\n";
41echo "Single OID\n";
42var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.110', $timeout, $retries));
43echo "Single OID in array\n";
44var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.110'), $timeout, $retries));
45echo "Multiple OID\n";
46var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.220'), $timeout, $retries));
47
48
49?>
50--EXPECTF--
51Checking working
52Single OID, default timeout and retries
53string(%d) "%s"
54Single OID, default retries
55string(%d) "%s"
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: snmpget(): 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: snmpget(): Invalid object identifier: .1.3.6.1.2.1...1.1.0 in %s on line %d
78bool(false)
79Multiple OID
80
81Warning: snmpget(): 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: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
87bool(false)
88Single OID in array
89
90Warning: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
91bool(false)
92Multiple OID
93
94Warning: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
95array(1) {
96  ["%s"]=>
97  string(%d) "%s"
98}
99