xref: /PHP-8.2/ext/snmp/tests/snmpget.phpt (revision b5a14e6c)
1--TEST--
2Function snmpget
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 working\n";
20echo "Single OID, default timeout and retries\n";
21var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0'));
22echo "Single OID, default retries\n";
23var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout));
24echo "Single OID\n";
25var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
26echo "Single OID in array\n";
27var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.0'), $timeout, $retries));
28echo "Multiple OID\n";
29var_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));
30
31echo "More error handling\n";
32echo "Single OID\n";
33var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1..1.1.0', $timeout, $retries));
34echo "Single OID in array\n";
35var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1...1.1.0'), $timeout, $retries));
36echo "Multiple OID\n";
37var_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));
38
39echo "noSuchName checks\n";
40echo "Single OID\n";
41var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.110', $timeout, $retries));
42echo "Single OID in array\n";
43var_dump(snmpget($hostname, $community, array('.1.3.6.1.2.1.1.1.110'), $timeout, $retries));
44echo "Multiple OID\n";
45var_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));
46
47
48?>
49--EXPECTF--
50Checking working
51Single OID, default timeout and retries
52string(%d) "%s"
53Single OID, default retries
54string(%d) "%s"
55Single OID
56string(%d) "%s"
57Single OID in array
58array(1) {
59  ["%s"]=>
60  string(%d) "%s"
61}
62Multiple OID
63array(2) {
64  ["%s"]=>
65  string(%d) "%s"
66  ["%s"]=>
67  string(%d) "%d"
68}
69More error handling
70Single OID
71
72Warning: snmpget(): Invalid object identifier: .1.3.6.1.2.1..1.1.0 in %s on line %d
73bool(false)
74Single OID in array
75
76Warning: snmpget(): Invalid object identifier: .1.3.6.1.2.1...1.1.0 in %s on line %d
77bool(false)
78Multiple OID
79
80Warning: snmpget(): Invalid object identifier: .1.3.6.1.2.1...1.1.0 in %s on line %d
81bool(false)
82noSuchName checks
83Single OID
84
85Warning: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
86bool(false)
87Single OID in array
88
89Warning: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
90bool(false)
91Multiple OID
92
93Warning: snmpget(): Error in packet at '%s': (noSuchName) There is no such variable name in this MIB. in %s on line %d
94array(1) {
95  ["%s"]=>
96  string(%d) "%s"
97}
98