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