SNMP::set

(PHP 5 >= 5.4.0, PHP 7)

SNMP::setSet the value of an SNMP object

说锟斤拷

public SNMP::set ( mixed $object_id , mixed $type , mixed $value ) : bool

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

锟斤拷锟斤拷

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.

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 锟斤拷锟斤拷锟剿革拷锟斤拷锟斤拷锟斤拷 id 锟斤拷锟斤拷锟酵★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫筹拷锟侥碉拷锟斤拷锟街凤拷之一锟斤拷

锟斤拷锟斤拷
=MIB锟斤拷锟斤拷
iINTEGER
uINTEGER
sSTRING
xHEX STRING
dDECIMAL STRING
nNULLOBJ
oOBJID
tTIMETICKS
aIPADDRESS
bBITS

锟斤拷锟斤拷诒锟斤拷锟� SNMP 锟斤拷时锟斤拷锟斤拷锟斤拷 OPAQUE_SPECIAL_TYPES锟斤拷锟斤拷么锟斤拷锟斤拷值锟角合凤拷锟侥o拷

types
Uunsigned int64
Isigned int64
Ffloat
Ddouble

锟斤拷些值锟襟都伙拷使锟斤拷锟斤拷 ASN.1 锟斤拷锟斤拷锟斤拷锟斤拷汀锟�'s'锟斤拷'x'锟斤拷'd' 锟皆硷拷 'b' 锟斤拷锟斤拷指锟斤拷一锟斤拷锟斤拷锟街斤拷锟街凤拷锟斤拷值锟侥凤拷式锟斤拷锟斤拷锟斤拷 'u' 锟睫凤拷锟斤拷锟斤拷锟斤拷也锟斤拷锟斤拷锟节达拷锟斤拷 Gauge32 值锟斤拷

锟斤拷锟� MIB 锟侥硷拷锟斤拷锟斤拷 "snmp_read_mib" 锟斤拷锟斤拷通锟斤拷锟斤拷 libsnmp config 锟斤拷指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 MIB 锟斤拷时锟斤拷 '=' 锟斤拷锟皆憋拷锟斤拷锟斤拷为锟斤拷锟叫讹拷锟斤拷锟� type 锟斤拷锟斤拷锟斤拷锟斤拷为 type 锟斤拷锟皆憋拷锟皆讹拷锟斤拷 MIB 锟叫讹拷取锟斤拷

注锟斤拷锟斤拷锟斤拷锟街凤拷式锟斤拷锟斤拷锟借定 BITS 锟斤拷锟酵的憋拷锟斤拷锟斤拷锟斤拷锟斤拷 "SYNTAX BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}":

  • 使锟斤拷 "b" 锟斤拷锟斤拷锟皆硷拷一锟斤拷位锟斤拷锟斤拷锟叫憋拷锟斤拷锟狡硷拷使锟矫此凤拷锟斤拷锟斤拷锟斤拷为 GET 锟斤拷询锟斤拷同一锟斤拷 OID 锟斤拷锟结返锟斤拷锟斤拷锟斤拷 0xF8锟斤拷
  • 使锟斤拷 "x" 锟斤拷锟斤拷锟皆硷拷一锟斤拷十锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角诧拷锟斤拷要通锟斤拷锟斤拷 "0x" 前缀锟斤拷

锟斤拷锟斤拷细锟节硷拷锟斤拷锟斤拷锟斤拷锟街★拷

value

The new value.

锟斤拷锟斤拷值

锟缴癸拷时锟斤拷锟斤拷 TRUE锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

锟斤拷锟斤拷锟届常

锟斤拷锟斤拷锟斤拷默锟较诧拷锟阶筹拷锟轿猴拷锟届常锟斤拷锟斤拷锟揭拷锟侥承╋拷锟斤拷锟斤拷时锟阶筹拷 SNMPException 锟届常锟斤拷锟矫伙拷锟斤拷要锟斤拷 SNMP 锟斤拷锟斤拷锟� exceptions_enabled 锟借定为锟斤拷应锟斤拷值锟斤拷锟斤拷锟斤拷细锟节硷拷 SNMP::$exceptions_enabled 锟侥斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

Example #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");
?>

Example #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"));
?>

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

锟轿硷拷