File: snmp-object-error.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (111 lines) | stat: -rw-r--r-- 3,005 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
--TEST--
OO API: Generic errors
--CREDITS--
Boris Lytochkin
--EXTENSIONS--
snmp
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN');
?>
--FILE--
<?php
require_once(__DIR__.'/snmp_include.inc');

//EXPECTF format is quickprint OFF
snmp_set_quick_print(false);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);

try {
    var_dump(new SNMP(SNMP::VERSION_1, $hostname));
} catch (TypeError $e) {
    print $e->getMessage() . "\n";
}
try {
    var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, ''));
} catch (TypeError $e) {
    print $e->getMessage() . "\n";
}
try {
    var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, ''));
} catch (TypeError $e) {
    print $e->getMessage() . "\n";
}
try {
    var_dump(new SNMP(7, $hostname, $community));
} catch (ValueError $e) {
    print $e->getMessage() . "\n";
}

echo "Exception handling\n";
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
try {
    var_dump($session->get('.1.3.6.1.2.1.1.1..0'));
} catch (SNMPException $e) {
    var_dump($e->getCode());
    var_dump($e->getMessage());
}
$session->exceptions_enabled = SNMP::ERRNO_ANY;
try {
    var_dump($session->get('.1.3.6.1.2.1.1.1..0'));
} catch (SNMPException $e) {
    var_dump($e->getCode());
    var_dump($e->getMessage());
}
var_dump($session->close());

echo "Open normal session\n";
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
try {
    $session->valueretrieval = 67;
    var_dump($session->valueretrieval);
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
echo "Closing session\n";
var_dump($session->close());

try {
    var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
    var_dump($session->close());
} catch (\Error $e) {
    echo $e->getMessage() . \PHP_EOL;
}

$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);

var_dump($session->max_oids);
try {
    $session->max_oids = "ttt";
} catch (TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    $session->max_oids = 0;
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
var_dump($session->max_oids);
?>
--EXPECTF--
SNMP::__construct() expects at least 3 arguments, 2 given
SNMP::__construct(): Argument #4 ($timeout) must be of type int, string given
SNMP::__construct(): Argument #5 ($retries) must be of type int, string given
SNMP::__construct(): Argument #1 ($version) must be a valid SNMP protocol version
Exception handling

Warning: SNMP::get(): Invalid object identifier: .1.3.6.1.2.1.1.1..0 in %s on line %d
bool(false)
int(32)
string(46) "Invalid object identifier: .1.3.6.1.2.1.1.1..0"
bool(true)
Open normal session
SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
Closing session
bool(true)
Invalid or uninitialized SNMP object
NULL
Cannot assign string to property SNMP::$max_oids of type ?int
SNMP::$max_oids must be greater than 0 or null
NULL