SAMMessage::header
Introduction
Other Services
PHP Manual

# SNMP

Table of Contents

- Introduction
- Installing/Configuring
  - Requirements
  - Installation
  - Runtime Configuration
  - Resource Types
- Predefined Constants
- SNMP Functions
  - snmp_get_quick_print — Fetches the current value of the UCD library's quick_print setting
  - snmp_get_valueretrieval — Return the method how the SNMP values will be returned
  - snmp_read_mib — Reads and parses a MIB file into the active MIB tree
  - snmp_set_enum_print — Return all values that are enums with their enum value instead of the raw integer
  - snmp_set_oid_numeric_print — Return all objects including their respective object id within the specified one
  - snmp_set_oid_output_format — Set the OID output format
  - snmp_set_quick_print — Set the value of quick_print within the UCD SNMP library
  - snmp_set_valueretrieval — Specify the method how the SNMP values will be returned
  - snmp2_get — Fetch an SNMP object
  - snmp2_getnext — Fetch the SNMP object which follows the given object id
  - snmp2_real_walk — Return all objects including their respective object ID within the specified one
  - snmp2_set — Set the value of an SNMP object
  - snmp2_walk — Fetch all the SNMP objects from an agent
  - snmp3_get — Fetch an SNMP object
  - snmp3_getnext — Fetch the SNMP object which follows the given object id
  - snmp3_real_walk — Return all objects including their respective object ID within the specified one
  - snmp3_set — Set the value of an SNMP object
  - snmp3_walk — Fetch all the SNMP objects from an agent
  - snmpget — Fetch an SNMP object
  - snmpgetnext — Fetch the SNMP object which follows the given object id
  - snmprealwalk — Return all objects including their respective object ID within the specified one
  - snmpset — Set the value of an SNMP object
  - snmpwalk — Fetch all the SNMP objects from an agent
  - snmpwalkoid — Query for a tree of information about a network entity
- SNMP — The SNMP class
  - SNMP::close — Close SNMP session
  - SNMP::__construct — Creates SNMP instance representing session to remote SNMP agent
  - SNMP::get — Fetch an SNMP object
  - SNMP::getErrno — Get last error code
  - SNMP::getError — Get last error message
  - SNMP::getnext — Fetch an SNMP object which follows the given object id
  - SNMP::set — Set the value of an SNMP object
  - SNMP::setSecurity — Configures security-related SNMPv3 session parameters
  - SNMP::walk — Fetch SNMP object subtree
- SNMPException — The SNMPException class

# The SNMP class

## Introduction

Represents SNMP session.

## Class synopsis

SNMP
class SNMP {
/* Properties */
public int $max_oids ;
public int $valueretrieval ;
public bool $quick_print ;
public bool $enum_print ;
public int $oid_output_format ;
public bool $oid_increasing_check ;
public int $exceptions_enabled ;
public array $info ;
/* Methods */
public __construct ( int `$version` , string `$hostname` , string `$community` [, int `$timeout` = 1000000 [, int `$retries` = 5 ]] )
public bool close ( void )
public mixed get ( mixed `$object_id` [, bool `$preserve_keys` = false ] )
public int getErrno ( void )
public string getError ( void )
public mixed getnext ( mixed `$object_id` )
public bool set ( mixed `$object_id` , mixed `$type` , mixed `$value` )
public bool setSecurity ( string `$sec_level` [, string `$auth_protocol` = [, string `$auth_passphrase` = [, string `$priv_protocol` = [, string `$priv_passphrase` = [, string `$contextName` = [, string `$contextEngineID` = ]]]]]] )
public array walk ( string `$object_id` [, bool `$suffix_as_key` = `FALSE` [, int `$max_repetitions` [, int `$non_repeaters` ]]] )
/* Constants */
const integer SNMP::ERRNO_NOERROR = 0 ;
const integer SNMP::ERRNO_GENERIC = 2 ;
const integer SNMP::ERRNO_TIMEOUT = 4 ;
const integer SNMP::ERRNO_ERROR_IN_REPLY = 8 ;
const integer SNMP::ERRNO_OID_NOT_INCREASING = 16 ;
const integer SNMP::ERRNO_OID_PARSING_ERROR = 32 ;
const integer SNMP::ERRNO_MULTIPLE_SET_QUERIES = 64 ;
const integer SNMP::ERRNO_ANY = 126 ;
const integer SNMP::VERSION_1 = 0 ;
const integer SNMP::VERSION_2C = 1 ;
const integer SNMP::VERSION_2c = 1 ;
const integer SNMP::VERSION_3 = 3 ;
}

## Properties

max_oids

  Maximum OID per GET/SET/GETBULK request

valueretrieval

  Controls the method how the SNMP values will be returned

  `SNMP_VALUE_LIBRARY` | The return values will be as returned by the Net-SNMP library.
  `SNMP_VALUE_PLAIN` | The return values will be the plain value without the SNMP type hint.
  `SNMP_VALUE_OBJECT` | The return values will be objects with the properties "value" and "type", where the latter is one of the SNMP_OCTET_STR, SNMP_COUNTER etc. constants. The way "value" is returned is based on which one of `SNMP_VALUE_LIBRARY`, `SNMP_VALUE_PLAIN` is set

quick_print

  Value of `quick_print` within the NET-SNMP library

  Sets the value of `quick_print` within the NET-SNMP library. When this is set (1), the SNMP library will return 'quick printed' values. This means that just the value will be printed. When `quick_print` is not enabled (default) the UCD SNMP library prints extra information including the type of the value (i.e. IpAddress or OID). Additionally, if quick_print is not enabled, the library prints additional hex values for all strings of three characters or less.

enum_print

  Controls the way enum values are printed

  Parameter toggles if walk/get etc. should automatically lookup enum values in the MIB and return them together with their human readable string.

oid_output_format

  Controls OID output format

  OID .1.3.6.1.2.1.1.3.0 representation for various oid_output_format values
  `SNMP_OID_OUTPUT_FULL` | .iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.sysUpTimeInstance
  `SNMP_OID_OUTPUT_NUMERIC` | .1.3.6.1.2.1.1.3.0
  `SNMP_OID_OUTPUT_MODULE` | DISMAN-EVENT-MIB::sysUpTimeInstance
  `SNMP_OID_OUTPUT_SUFFIX` | sysUpTimeInstance
  `SNMP_OID_OUTPUT_UCD` | system.sysUpTime.sysUpTimeInstance
  `SNMP_OID_OUTPUT_NONE` | Undefined

oid_increasing_check

  Controls disabling check for increasing OID while walking OID tree

  Some SNMP agents are known for returning OIDs out of order but can complete the walk anyway. Other agents return OIDs that are out of order and can cause SNMP::walk to loop indefinitely until memory limit will be reached. PHP SNMP library by default performs OID increasing check and stops walking on OID tree when it detects possible loop with issuing warning about non-increasing OID faced. Set oid_increasing_check to `FALSE` to disable this check.

exceptions_enabled

  Controls which failures will raise SNMPException instead of warning. Use bitwise OR'ed `SNMP::ERRNO_*` constants. By default all SNMP exceptions are disabled.

info

  Read-only property with remote agent configuration: hostname, port, default timeout, default retries count

## Predefined Constants

## SNMP Error Types

`SNMP::ERRNO_NOERROR`

  No SNMP-specific error occurred.

`SNMP::ERRNO_GENERIC`

  A generic SNMP error occurred.

`SNMP::ERRNO_TIMEOUT`

  Request to SNMP agent timed out.

`SNMP::ERRNO_ERROR_IN_REPLY`

  SNMP agent returned an error in reply.

`SNMP::ERRNO_OID_NOT_INCREASING`

  SNMP agent faced OID cycling reporning non-increasing OID while executing (BULK)WALK command. This indicates bogus remote SNMP agent.

`SNMP::ERRNO_OID_PARSING_ERROR`

  Library failed while parsing OID (and/or type for SET command). No queries has been made.

`SNMP::ERRNO_MULTIPLE_SET_QUERIES`

  Library will use multiple queries for SET operation requested. That means that operation will be performed in a non-transaction manner and second or subsequent chunks may fail if a type or value failure will be faced.

`SNMP::ERRNO_ANY`

  All SNMP::ERRNO_* codes bitwise OR'ed.

## SNMP Protocol Versions

`SNMP::VERSION_1`

`SNMP::VERSION_2C`, `SNMP::VERSION_2c`

`SNMP::VERSION_3`

# The SNMPException class

## Introduction

Represents an error raised by SNMP. You should not throw a SNMPException from your own code. See Exceptions for more information about Exceptions in PHP.

## Class synopsis

SNMPException
class SNMPException extends RuntimeException {
/* Properties */
protected string $code ;
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Inherited methods */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}

## Properties

code

  SNMPlibrary error code. Use Exception::getCode to access it.