xref: /PHP-8.4/ext/snmp/tests/snmp_getvalue.phpt (revision ba1d9d0a)
1--TEST--
2Function snmp_getvalue
3--CREDITS--
4Boris Lytochkin
5--EXTENSIONS--
6snmp
7--SKIPIF--
8<?php
9require_once(__DIR__.'/skipif.inc');
10if (PHP_OS_FAMILY === "Windows") die("xfail fails on Windows for unknown reasons");
11if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN');
12?>
13--FILE--
14<?php
15require_once(__DIR__.'/snmp_include.inc');
16
17//EXPECTF format is quickprint OFF
18snmp_set_quick_print(false);
19
20echo "Get with SNMP_VALUE_LIBRARY\n";
21snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
22var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
23
24echo "Get with SNMP_VALUE_PLAIN\n";
25snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
26var_dump(snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
27
28echo "Get with SNMP_VALUE_OBJECT\n";
29snmp_set_valueretrieval(SNMP_VALUE_OBJECT);
30$z = snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
31echo gettype($z)."\n";
32var_dump($z->type);
33var_dump($z->value);
34
35echo "Get with SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN\n";
36snmp_set_valueretrieval(SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN);
37$z = snmpget($hostname, $community, '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
38echo gettype($z)."\n";
39var_dump($z->type);
40var_dump($z->value);
41
42echo "Get with SNMP_VALUE_OBJECT for BITS OID\n";
43snmp_set_valueretrieval(SNMP_VALUE_OBJECT);
44$z = snmpget($hostname, $community, '.1.3.6.1.2.1.88.1.4.2.1.3.6.95.115.110.109.112.100.95.108.105.110.107.68.111.119.110', $timeout, $retries);
45echo gettype($z)."\n";
46var_dump($z->type);
47var_dump($z->value);
48
49echo "Get with SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN for BITS OID\n";
50snmp_set_valueretrieval(SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN);
51$z = snmpget($hostname, $community, '.1.3.6.1.2.1.88.1.4.2.1.3.6.95.115.110.109.112.100.95.108.105.110.107.68.111.119.110', $timeout, $retries);
52echo gettype($z)."\n";
53var_dump($z->type);
54var_dump(is_numeric($z->value));
55var_dump(is_string($z->value));
56var_dump(bin2hex($z->value));
57
58echo "Check parsing of different OID types\n";
59snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
60var_dump(count(snmp2_walk($hostname, $community, '.', $timeout, $retries)));
61
62?>
63--EXPECTF--
64Get with SNMP_VALUE_LIBRARY
65string(%d) "STRING: %s"
66Get with SNMP_VALUE_PLAIN
67string(%d) "%s"
68Get with SNMP_VALUE_OBJECT
69object
70int(4)
71string(%d) "STRING: %s"
72Get with SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN
73object
74int(4)
75string(%d) "%s"
76Get with SNMP_VALUE_OBJECT for BITS OID
77object
78int(4)
79string(%d) "%s: %d %S"
80Get with SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN for BITS OID
81object
82int(4)
83bool(false)
84bool(true)
85string(2) "%d"
86Check parsing of different OID types
87int(%d)
88