The SNMP class

Introduction

Represents SNMP session.

Class synopsis

SNMP
/* Constants */
public const int SNMP::VERSION_1;
public const int SNMP::VERSION_2c;
public const int SNMP::VERSION_2C;
public const int SNMP::VERSION_3;
public const int SNMP::ERRNO_NOERROR;
public const int SNMP::ERRNO_ANY;
public const int SNMP::ERRNO_GENERIC;
public const int SNMP::ERRNO_TIMEOUT;
public const int SNMP::ERRNO_ERROR_IN_REPLY;
public const int SNMP::ERRNO_OID_NOT_INCREASING;
public const int SNMP::ERRNO_OID_PARSING_ERROR;
public const int SNMP::ERRNO_MULTIPLE_SET_QUERIES;
/* Properties */
public readonly array $info;
public intnull $max_oids;
public int $valueretrieval;
public bool $quick_print;
public bool $enum_print;
public bool $numeric_index;
public bool $numeric_timeticks;
public bool $extended_index;
public bool $dont_print_units;
public bool $escape_quotes;
public bool $print_hex_text;
public int $oid_output_format;
public bool $oid_increasing_check;
public int $exceptions_enabled;
/* Methods */
public __construct(
    int $version,
    string $hostname,
    string $community,
    int $timeout = -1,
    int $retries = -1
)
public bool close()
public mixed get(arraystring $objectId, bool $preserveKeys = false)
public int getErrno()
public string getError()
public mixed getnext(arraystring $objectId)
public bool set(arraystring $objectId, arraystring $type, arraystring $value)
public bool setOidOutputFormat(Snmp\OidOutput $format)
public bool setSecurity(
    string $securityLevel,
    string $authProtocol = "",
    string $authPassphrase = "",
    string $privacyProtocol = "",
    string $privacyPassphrase = "",
    string $contextName = "",
    string $contextEngineId = ""
)
public bool setStringOutputFormat(Snmp\StringOutput $format)
public arrayfalse walk(
    arraystring $objectId,
    bool $suffixAsKey = false,
    int $maxRepetitions = -1,
    int $nonRepeaters = -1
)

Properties

The properties that control the output format take their initial values from the settings in effect when the object is created, as set by functions such as snmp_set_output_option and snmp_set_oid_output_format. Changing them only affects the requests of this session.

max_oids
Maximum OID per GET/SET/GETBULK request
valueretrieval
Controls the method how the SNMP values will be returned
SNMP_VALUE_LIBRARYThe return values will be as returned by the Net-SNMP library.
SNMP_VALUE_PLAINThe return values will be the plain value without the SNMP type information.
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 NET-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.
numeric_index
Controls whether table indexes are printed numerically When enabled, table indexes are printed numerically, instead of being interpreted as strings or OIDs. See Snmp\Output::NumericIndex.
numeric_timeticks
Controls whether TimeTicks values are printed as raw numbers When enabled, TimeTicks values are printed as raw numbers, such as 14096763, instead of Timeticks: (14096763) 1 day, 15:09:27.63. See Snmp\Output::NumericTimeticks.
extended_index
Controls whether table indexes are printed in square brackets When enabled, table indexes are printed in square brackets, like array indexes, such as IF-MIB::ifDescr[1]. See Snmp\Output::ExtendedIndex.
dont_print_units
Controls whether the units of the values are omitted When enabled, the UNITS defined in the MIB are not appended to the values. See Snmp\Output::DontPrintUnits.
escape_quotes
Controls whether quotes in string table indexes are escaped When enabled, the quote characters in string table indexes are escaped with a backslash. See Snmp\Output::EscapeQuotes.
print_hex_text
Controls whether the printable characters of hexadecimal strings are printed too When enabled, the values that are printed as hexadecimal strings are followed by their printable characters. See Snmp\Output::HexText.
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_MODULEDISMAN-EVENT-MIB::sysUpTimeInstance
SNMP_OID_OUTPUT_SUFFIXsysUpTimeInstance
SNMP_OID_OUTPUT_UCDsystem.sysUpTime.sysUpTimeInstance
SNMP_OID_OUTPUT_NONEUndefined
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
Table of Contents