SNMP::set
(PHP 5 >= 5.4.0)
SNMP::set — Set the value of an SNMP object
Descripción
Requests remote SNMP agent setting the value of
one or more SNMP objects specified by the object_id.
Parámetros
-
object_id -
The SNMP object id
When count of OIDs in object_id array is greater than max_oids object property set method will have to use multiple queries to perform requested value updates. In this case type and value checks are made per-chunk so second or subsequent requests may fail due to wrong type or value for OID requested. To mark this a warning is raised when count of OIDs in object_id array is greater than max_oids.
-
type -
MIB define el tipo de cada identificador de objeto. Debe indicarse con un único carácter de la siguiente lista.
tipos = Tipo adquirido a partir de MIB i INTEGER u INTEGER s STRING x HEX STRING d DECIMAL STRING n NULLOBJ o OBJID t TIMETICKS a IPADDRESS b BITS Si se definió
OPAQUE_SPECIAL_TYPESal compilar la biblioteca SNMP, los siguientes valores serán también válidos:tipos U int64 sin signo I int64 con signo F float D double La mayoría, utilizarán su correspondiente tipo ASN.1. 's', 'x', 'd' y 'b' son diferentes formas de especificar un valor de OCTET STRING, y el tipo sin signo 'u' se usa también para manejar valores Gauge32.
Si se cargan los ficheros MIB en el árbol MIB con "snmp_read_mib" o con la configuración de libsnmp, se puede usar '=' como parámetro
typepara todos los id de objetos, ya que se podrá leer automáticamente el tipo a partir del MIB.Tenga presente que hay dos formas de asigar a una variable los tipos BITS, como por ejemplo. "SYNTAX BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}":
- Usando el tipo "b" y una lista numérica de bits. No se recomienda usar este método, ya que una consulta GET para un mismo OID devolvería, por ejemplo 0xF8.
- Usando el tipo "x" y un número hexadecimal, pero si el prefijo "0x".
Revise el apartado de ejemplos para más detalles.
-
value -
The new value.
If object_id is string, both
type and value must be
string too. If object_id is array
value must be equal-sized array containing
corresponding values, type may be either
string (it's value will be used for all
object_id-value pairs) or
equal-sized array with per-OID value. When any other parameters' combinations are
used, a number of E_WARNING messages may be shown with detailed description.
Valores devueltos
Devuelve TRUE en caso de éxito o FALSE en caso de error.
Errores/Excepciones
Este método no lanza ninguna excepción de manera predeterminada.
Para poder lanzar una excepción SNMPException cuando ocurre alguno de los errores de la biblioteca
el parámetro exceptions_enabled de la clase SNMP
se debería establecer al valor correspondiente. Véase
la explicación de SNMP::$exceptions_enabled para más detalles.
Ejemplos
Ejemplo #1 Set single SNMP object id
<?php
$session = new SNMP(SNMP::VERSION_2C, "127.0.0.1", "private");
$session->set('SNMPv2-MIB::sysContact.0', 's', "Nobody");
?>
Ejemplo #2 Set multiple values using single SNMP::set() call
<?php
$session = new SNMP(SNMP::VERSION_2C, "127.0.0.1", "private");
$session->set(array('SNMPv2-MIB::sysContact.0', 'SNMPv2-MIB::sysLocation.0'), array('s', 's'), array("Nobody", "Nowhere"));
// or
$session->set(array('SNMPv2-MIB::sysContact.0', 'SNMPv2-MIB::sysLocation.0'), 's', array("Nobody", "Nowhere"));
?>
Ejemplo #3 Using SNMP::set() for setting BITS SNMP object id
<?php
$session = new SNMP(SNMP::VERSION_2C, "127.0.0.1", "private");
$session->set('FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
$session->set('FOO-MIB::bar.42', 'x', 'F0');
?>