(PHP 4, PHP 5, PHP 7)
snmpset — Setzt den Wert eines SNMP-Objekts
$host
, string $community
, string $object_id
, string $type
, mixed $value
[, int $timeout = 1000000
[, int $retries = 5
]] ) : bool
Die Funktion snmpset() wird benutzt, um den Wert eines
SNMP Objekts zu setzen, das mit
object_id angegeben wird.
hostDer Hostname des SNMP-Agent (Server).
communityDie "write community".
object_idDie SNMP-Objektkennung.
typeThe MIB defines the type of each object id. It has to be specified as a single character from the below list.
| = | The type is taken from the MIB |
| i | INTEGER |
| u | INTEGER |
| s | STRING |
| x | HEX STRING |
| d | DECIMAL STRING |
| n | NULLOBJ |
| o | OBJID |
| t | TIMETICKS |
| a | IPADDRESS |
| b | BITS |
If OPAQUE_SPECIAL_TYPES was defined while compiling the SNMP library, the following are also valid:
| U | unsigned int64 |
| I | signed int64 |
| F | float |
| D | double |
Most of these will use the obvious corresponding ASN.1 type. 's', 'x', 'd' and 'b' are all different ways of specifying an OCTET STRING value, and the 'u' unsigned type is also used for handling Gauge32 values.
If the MIB-Files are loaded by into the MIB Tree with "snmp_read_mib" or by specifying it in the libsnmp config, '=' may be used as
the type parameter for all object ids as the type can then be automatically read from the MIB.
Note that there are two ways to set a variable of the type BITS like e.g. "SYNTAX BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}":
See examples section for more details.
valueDer neue Wert.
timeoutDie Zahl der Mikrosekunden bis zum ersten Timeout.
retriesDie Anzahl der Wiederholungsversuche, wenn Timeouts auftreten.
Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.
Wenn der SNMP-Host den Datentyp zurückweist, wird eine E_WARNING Meldung in der Art "Warning: Error in packet. Reason: (badValue) The value given has the wrong type or length." erzeugt. Wenn eine unbekannte oder ungültige OID angegeben wird, wird die Warnung wohl "Could not add variable" lauten.
Beispiel #1 Verwendung von snmpset()
<?php
snmpset("localhost", "public", "IF-MIB::ifAlias.3", "s", "foo");
?>
Beispiel #2 Verwendung von snmpset() zum Setzen von BITS SNMP Objektkennungen
<?php
snmpset("localhost", "public", 'FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
snmpset("localhost", "public", 'FOO-MIB::bar.42', 'x', 'F0');
?>