CakeFest 2024: The Official CakePHP Conference

SNMP::set

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

SNMP::setSet the value of an SNMP object

Descripción

public SNMP::set(array|string $objectId, array|string $type, array|string $value): bool

Requests remote SNMP agent setting the value of one or more SNMP objects specified by the objectId.

Parámetros

If objectId is string, both type and value must be string too. If objectId is array value must be equal-sized array containing corresponding values, type may be either string (it's value will be used for all objectId-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.

objectId

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
iINTEGER
uINTEGER
sSTRING
xHEX STRING
dDECIMAL STRING
nNULLOBJ
oOBJID
tTIMETICKS
aIPADDRESS
bBITS

Si se definió OPAQUE_SPECIAL_TYPES al compilar la biblioteca SNMP, los siguientes valores serán también válidos:

tipos
Uint64 sin signo
Iint64 con signo
Ffloat
Ddouble

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 type para 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.

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');
?>

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top