(PHP 4, PHP 5, PHP 7)
snmp3_set — Set the value of an SNMP object
$host
, string $sec_name
, string $sec_level
, string $auth_protocol
, string $auth_passphrase
, string $priv_protocol
, string $priv_passphrase
, string $object_id
, string $type
, string $value
[, int $timeout
= 1000000
[, int $retries
= 5
]] ) : bool
snmp3_set() is used to set the value of an SNMP object
specified by the object_id
.
Even if the security level does not use an auth or priv protocol/password valid values have to be specified.
host
The hostname of the SNMP agent (server).
sec_name
the security name, usually some kind of username
sec_level
the security level (noAuthNoPriv|authNoPriv|authPriv)
auth_protocol
the authentication protocol (MD5 or SHA)
auth_passphrase
the authentication pass phrase
priv_protocol
the privacy protocol (DES or AES)
priv_passphrase
the privacy pass phrase
object_id
The SNMP object id.
type
MIB definiuje typ każdego id obiektu. Musi być podany jako pojedynczy znak z poniższej listy
= | Typ pobrany z MIB |
i | INTEGER |
u | INTEGER |
s | STRING |
x | HEX STRING |
d | DECIMAL STRING |
n | NULLOBJ |
o | OBJID |
t | TIMETICKS |
a | IPADDRESS |
b | BITS |
Jeśli przy kompilacji biblioteki SNMP zdefiniowana została stała OPAQUE_SPECIAL_TYPES
, dostępne są także poniższe wartości:
U | unsigned int64 |
I | signed int64 |
F | float |
D | double |
Większość z nich będzie w sposób oczywisty odpowiadać typowi ASN.1 's', 'x', 'd' i 'b' są różnymi sposobami na określenie wartości OCTET STRING, a typ 'u' - bez określania znaku - stosowany jest także dla obsługi wartości Gauge32.
Jeśli pliki MIB są ładowane do drzewa MIB poprzez "snmp_read_mib" lub przez podanie ich w konfiguracji libsnmp, '=' może być stosowane
jako wartość parametru type
dla wszystkich id obiektów, jako że typ może być automatycznie odczytany z MIB.
Istnieją dwa sposoby aby ustawić wartość zmiennej typu BITS, przykładowo "SYNTAX BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}":
Zobacz też sekcję z przykładami.
value
The new value
timeout
The number of microseconds until the first timeout.
retries
The number of times to retry if timeouts occur.
Zwraca TRUE
w przypadku powodzenia, FALSE
w
przypadku błędu.
If the SNMP host rejects the data type, an E_WARNING message like "Warning: Error in packet. Reason: (badValue) The value given has the wrong type or length." is shown. If an unknown or invalid OID is specified the warning probably reads "Could not add variable".
Przykład #1 Using snmp3_set()
<?php
snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'IF-MIB::ifAlias.3', 's', "foo");
?>
Przykład #2 Using snmp3_set() for setting BITS SNMP object id
<?php
snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'FOO-MIB::bar.42', 'x', 'F0');
?>