A class for performing SNMP V2 queries and processing the results.

copyright | Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
author | Barry O'Donovan

### Methods

## Magic method for generic function calls

    __call(string $method, array $args)

### Parameters

#### $method

`string`

#### $args

`array`

### Exceptions

`\OSS_SNMP\Exception` |

## The constructor.

    __construct(string $host = '127.0.0.1', string $community = 'public') : \OSS_SNMP\OSS_SNMP

### Parameters

#### $host

`string`

The target host for SNMP queries.

#### $community

`string`

The community to use for SNMP queries.

### Returns

`\OSS_SNMP\OSS_SNMP`An instance of $this (for fluent interfaces)

## Query whether we are using the cache or not

    cache() : boolean

### Returns

`boolean`True of the local lookup cache is enabled. Otherwise false.

## Disable lookups of the local cache

    disableCache() : \OSS_SNMP\SNMP

### Returns

`\OSS_SNMP\SNMP`An instance of this for fluent interfaces

## Enable lookups of the local cache

    enableCache() : \OSS_SNMP\SNMP

### Returns

`\OSS_SNMP\SNMP`An instance of this for fluent interfaces

## Get a single SNMP value

    get(string $oid) : mixed

### Parameters

#### $oid

`string`

The OID to get

### Exceptions

`\OSS_SNMP\Exception` | On *any* SNMP error, warnings are supressed and a generic exception is thrown

### Returns

`mixed`The resultant value

## Get the cache in use (or create a Cache\Basic instance

    getCache() : \OSS_SNMP\Cache

We kind of mandate the use of a cache as the code is written with a cache in mind. You are free to disable it via disableCache() but your machines may be hammered! We would suggest disableCache() / enableCache() used in pairs only when really needed.

### Returns

`\OSS_SNMP\Cache`The cache object

## Returns the community string currently in use.

    getCommunity() : string

### Returns

`string`The community string currently in use.

## Returns the target host as currently configured for SNMP queries

    getHost() : string

### Returns

`string`The target host as currently configured for SNMP queries

## Returns the unaltered original last SNMP result

    getLastResult() : mixed

### Returns

`mixed`The unaltered original last SNMP result

## getPlatform()

    getPlatform()

## Returns the internal result cache

    getResultCache() : array

### Returns

`array`The internal result cache

## Returns the SNMP query retry count

    getRetry() : string

### Returns

`string`The SNMP query retry count

## Returns the SNMP query timeout (microseconds).

    getTimeout() : int

### Returns

`int`The the SNMP query timeout (microseconds)

## Parse the result of an SNMP query into a PHP type

    parseSnmpValue(string $v) : mixed

For example, [STRING: "blah"] is parsed to a PHP string containing: blah

### Parameters

#### $v

`string`

The value to parse

### Exceptions

`\OSS_SNMP\Exception` |

### Returns

`mixed`The parsed value

## Takes a HEX-String of true / false - on / off - set / unset flags and converts it to an indexed (from 1) array of true / false values.

    ppHexStringFlags(string $str) : array

Static
For example, passing it ``500040`` will result in an array: [ [1] => false, [2] => true, [3] => false, [4] => true, [5] => false, [6] => false, [7] => false, [8] => false, ... [17] => false, [18] => true, [19] => false, [20] => false, [21] => false, [22] => true, [23] => false, [24] => false ]

### Parameters

#### $str

`string`

The hex string to parse

### Returns

`array`The array of true / false flags indexed from 1

## Utility function to convert TruthValue SNMP responses to true / false

    ppTruthValue(integer $value) : boolean

Static

### Parameters

#### $value

`integer`

The TruthValue ( 1 => true, 2 => false) to convert

### Returns

`boolean`

## Proxy to the snmp2_real_walk command

    realWalk(string $oid) : array

### Parameters

#### $oid

`string`

The OID to walk

### Returns

`array`The results of the walk

## Set the cache to use

    setCache(\OSS_SNMP\Cache $c) : \OSS_SNMP\SNMP

### Parameters

#### $c

`\OSS_SNMP\Cache`

The cache to use

### Returns

`\OSS_SNMP\SNMP`For fluent interfaces

## Sets the community string to use for SNMP queries.

    setCommunity(string $c) : \OSS_SNMP\OSS_SNMP

### Parameters

#### $c

`string`

The community to use for SNMP queries.

### Returns

`\OSS_SNMP\OSS_SNMP`An instance of $this (for fluent interfaces)

## Sets the target host for SNMP queries.

    setHost(string $h) : \OSS_SNMP\SNMP

### Parameters

#### $h

`string`

The target host for SNMP queries.

### Returns

`\OSS_SNMP\SNMP`An instance of $this (for fluent interfaces)

## Sets the output format for SNMP queries.

    setOidOutputFormat(int $f) : \OSS_SNMP\OSS_SNMP\SNMP

Should be one of the class OID_OUTPUT_* constants

### Parameters

#### $f

`int`

The fomat to use

### Returns

`\OSS_SNMP\OSS_SNMP\SNMP`An instance of $this (for fluent interfaces)

## Sets the SNMP query retry count.

    setRetry(int $r) : \OSS_SNMP\OSS_SNMP

### Parameters

#### $r

`int`

The SNMP query retry count

### Returns

`\OSS_SNMP\OSS_SNMP`An instance of $this (for fluent interfaces)

## Sets the timeout to use for SNMP queries (microseconds).

    setTimeout(int $t) : \OSS_SNMP\OSS_SNMP

### Parameters

#### $t

`int`

The timeout to use for SNMP queries (microseconds).

### Returns

`\OSS_SNMP\OSS_SNMP`An instance of $this (for fluent interfaces)

## Get indexed SNMP values where the array key is the given position of the OID

    subOidWalk(string $oid, int $position) : array

I.e. the following query with sample results: subOidWalk( '.1.3.6.1.4.1.9.9.23.1.2.1.1.9', 15 ) .1.3.6.1.4.1.9.9.23.1.2.1.1.9.10101.5 = Hex-STRING: 00 00 00 01 .1.3.6.1.4.1.9.9.23.1.2.1.1.9.10105.2 = Hex-STRING: 00 00 00 01 .1.3.6.1.4.1.9.9.23.1.2.1.1.9.10108.4 = Hex-STRING: 00 00 00 01 would yield an array: 10101 => Hex-STRING: 00 00 00 01 10105 => Hex-STRING: 00 00 00 01 10108 => Hex-STRING: 00 00 00 01

### Parameters

#### $oid

`string`

The OID to walk

#### $position

`int`

The position of the OID to use as the key

### Exceptions

`\OSS_SNMP\Exception` | On *any* SNMP error, warnings are supressed and a generic exception is thrown

### Returns

`array`The resultant values

## Utility function to translate one value(s) to another via an associated array

    translate(mixed $values, array $translator) : mixed

Static
I.e. all elements '$value' will be replaced with $translator( $value ) where $translator is an associated array. Huh? Just read the code below!

### Parameters

#### $values

`mixed`

A scalar or array or values to translate

#### $translator

`array`

An associated array to use to translate the values

### Returns

`mixed`The translated scalar or array

## This is the MIB Extension magic

    useExtension(string $mib, array $args) : \OSS_SNMP\MIBS

Calling $this->useXXX_YYY_ZZZ()->fn() will instantiate an extension MIB class is the given name and this $this SNMP instance and then call fn(). See the examples for more information.

### Parameters

#### $mib

`string`

The extension class to use

#### $args

`array`

### Returns

`\OSS_SNMP\MIBS`

## Get indexed SNMP values (first degree)

    walk1d(string $oid) : array

Walks the SNMP tree returning an array of key => value pairs. This is a first degree walk and it will throw an exception if there is more that one degree of values. I.e. the following query with sample results: walk1d( '.1.0.8802.1.1.2.1.3.7.1.4' ) .1.0.8802.1.1.2.1.3.7.1.4.1 = STRING: "GigabitEthernet1/0/1" .1.0.8802.1.1.2.1.3.7.1.4.2 = STRING: "GigabitEthernet1/0/2" .1.0.8802.1.1.2.1.3.7.1.4.3 = STRING: "GigabitEthernet1/0/3" ..... would yield an array: 1 => GigabitEthernet1/0/1 2 => GigabitEthernet1/0/2 3 => GigabitEthernet1/0/3

### Parameters

#### $oid

`string`

The OID to walk

### Exceptions

`\OSS_SNMPException` | On *any* SNMP error, warnings are supressed and a generic exception is thrown

### Returns

`array`The resultant values

## Get indexed SNMP values where they are indexed by IPv4 addresses

    walkIPv4(string $oid) : array

I.e. the following query with sample results: subOidWalk( '.1.3.6.1.2.1.15.3.1.1. ) .1.3.6.1.2.1.15.3.1.1.10.20.30.4 = IpAddress: 192.168.10.10 ... would yield an array: [10.20.30.4] => "192.168.10.10" ....

### Parameters

#### $oid

`string`

The OID to walk

### Exceptions

`\OSS_SNMP\Exception` | On *any* SNMP error, warnings are supressed and a generic exception is thrown

### Returns

`array`The resultant values

### Properties

## An array of arrays where each array element represents true / false values for a given hex digit.

    $HEX_STRING_WORDS_AS_ARRAY

### Default

`array('0' => array(false, false, false, false), '1' => array(false, false, false, true), '2' => array(false, false, true, false), '3' => array(false, false, true, true), '4' => array(false, true, false, false), '5' => array(false, true, false, true), '6' => array(false, true, true, false), '7' => array(false, true, true, true), '8' => array(true, false, false, false), '9' => array(true, false, false, true), 'a' => array(true, false, true, false), 'b' => array(true, false, true, true), 'c' => array(true, true, false, false), 'd' => array(true, true, false, true), 'e' => array(true, true, true, false), 'f' => array(true, true, true, true))`
Static

see |

## PHP equivalents of SNMP return type TruthValue

    $SNMP_TRUTHVALUES : array

### Default

`array(self::SNMP_TRUTHVALUE_TRUE => true, self::SNMP_TRUTHVALUE_FALSE => false)`
Static

## The cache object to use as the cache

    $_cache : \OSS_SNMP\Cache

### Default

`null`

## The SNMP community to use when polling SNMP services. Defaults to 'public' by the constructor.

    $_community : string

### Default

## Set to true to disable local cache lookup and force SNMP queries

    $_disableCache

### Default

`false`
Results are still stored. If you need to force a SNMP query, you can: $snmp = new OSS_SNMP( ... )' ... $snmp->disableCache(); $snmp->get( ... ); $snmp->enableCache();

## The SNMP host to query. Defaults to '127.0.0.1'

    $_host : string

### Default

## A variable to hold the last unaltered result of an SNMP query

    $_lastResult : mixed

### Default

`null`

## A variable to hold the platform object

    $_platform : mixed

### Default

`null`

## The SNMP query retry count. Default: 5

    $_retry : int

### Default

`5`

## The SNMP query timeout value (microseconds). Default: 1000000

    $_timeout : int

### Default

`1000000`

### Constants

## SNMP output constants to mirror those of PHP

    OID_OUTPUT_FULL = SNMP_OID_OUTPUT_FULL : \OSS_SNMP\SNMP

## SNMP output constants to mirror those of PHP

    OID_OUTPUT_NUMERIC = SNMP_OID_OUTPUT_NUMERIC : \OSS_SNMP\SNMP

## Definition of an SNMP return type 'TruthValue'

    SNMP_TRUTHVALUE_FALSE = 2 : \OSS_SNMP\Definition

## Definition of an SNMP return type 'TruthValue'

    SNMP_TRUTHVALUE_TRUE = 1 : \OSS_SNMP\Definition