snmp2_set
(PHP >= 5.2.0, PHP 7, PHP 8)
snmp2_set — Set the value of an SNMP object
Descrizione
snmp2_set() is used to set the value of an SNMP object
specified by the object_id.
Elenco dei parametri
hostname
-
The hostname of the SNMP agent (server).
community
-
The write community.
object_id
-
The SNMP object id.
type
-
Il MIB definisce il tipo di ciascun object id. Deve essere specificato come un singolo carattere della lista seguente.
tipi
| = | Il tipo viene preso dal MIB |
| i | INTEGER |
| u | INTEGER |
| s | STRING |
| x | HEX STRING |
| d | DECIMAL STRING |
| n | NULLOBJ |
| o | OBJID |
| t | TIMETICKS |
| a | IPADDRESS |
| b | BITS |
Se OPAQUE_SPECIAL_TYPES è stato definito durante la compilazione della libreria SNMP, sono validi anche i seguenti:
tipi
| U | unsigned int64 |
| I | signed int64 |
| F | float |
| D | double |
La maggior parte di questi userà l'ovvio tipo ASN.1 corrispondente. 's', 'x', 'd' e 'b' sono tutti modi diversi di specificare un valore OCTET STRING, e
il tipo unsigned 'u' è usato anche per gestire i valori Gauge32.
Se i file MIB sono caricati nell'albero MIB con "snmp_read_mib" o specificandoli nella configurazione di libsnmp, '=' può essere usato come
parametro type per tutti gli object id, poiché il tipo può allora essere letto automaticamente dal MIB.
Si noti che ci sono due modi per impostare una variabile di tipo BITS come ad es.
"SYNTAX BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}":
-
Usando il tipo "b" e una lista di numeri di bit. Questo metodo non è raccomandato poiché una query GET per lo stesso OID restituirebbe ad es. 0xF8.
-
Usando il tipo "x" e un numero esadecimale ma senza(!) il consueto prefisso "0x".
Vedere la sezione degli esempi per maggiori dettagli.
value
-
The new value.
timeout
-
The number of microseconds until the first timeout.
retries
-
The number of times to retry if timeouts occur.
Valori restituiti
Restituisce true in caso di successo o false in caso di fallimento.
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".
Errori/Eccezioni
Throws a ValueError if
object_id is an empty array.
Throws a TypeError if
object_id is a string and
type or value is an
array.
Throws a ValueError if
object_id is a string and
type is not a single character, or if
type is an array and the type of an
object ID is not a single character.
As of PHP 8.5.0, throws a ValueError if
hostname or community
contains null bytes, if hostname is 128 bytes or
longer or contains a port that is not between 0 and 65535, if
community is empty, or if
timeout or retries is lower
than -1 or too large.
Esempi
Example #1 Using snmp2_set()
<?php
snmp2_set("localhost", "public", "IF-MIB::ifAlias.3", "s", "foo");
?>
Example #2 Using snmp2_set() for setting BITS SNMP object id
<?php
snmp2_set("localhost", "public", 'FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
snmp2_set("localhost", "public", 'FOO-MIB::bar.42', 'x', 'F0');
?>