surrealcristian / snmp-extension
Wrapper over the SNMP extension.
1.0.0
2016-11-09 19:59 UTC
Requires
- php: >=5.4.0
- surrealcristian/simple-snmp: ~1.0
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2025-02-01 22:03:01 UTC
README
Wrapper over the SNMP extension.
Install
Via Composer
$ composer require surrealcristian/snmp-extension
Requirements
- PHP 5.4+
- SNMP extension
Usage
SimpleSnmpV2c
setup
<?php require __DIR__ . '/../vendor/autoload.php'; use SurrealCristian\SnmpExtension\Builder; use SurrealCristian\SimpleSnmp\Exception\SimpleSnmpException; use SurrealCristian\SimpleSnmp\Exception\TimeoutException; $host = '127.0.0.1'; $community = 'private'; $timeout = 1000000; // microseconds $retries = 3; $snmp = (new Builder)->getSimpleSnmpV2c();
get
<?php try { $oid = '1.2.3.4.5.0'; $res = $snmp->get($host, $community, $oid, $timeout, $retries); var_export($res); } catch (TimeoutException $e) { // handle exception } catch (SimpleSnmpException $e) { // handle exception } // array ( // 'oid' => '1.2.3.4.5.0', // 'type' => 'STRING', // 'value' => '"foo 0"', // )
getNext
<?php try { $oid = '1.2.3.4.5.0'; $res = $snmp->getNext($host, $community, $oid, $timeout, $retries); var_export($res); } catch (TimeoutException $e) { // handle exception } catch (SimpleSnmpException $e) { // handle exception } // array ( // 'oid' => null, // 'type' => 'STRING', // 'value' => '"foo 1"', // )
walk
<?php try { $oid = '1.2.3.4.5'; $res = $snmp->walk($host, $community, $oid, $timeout, $retries); var_export($res); } catch (TimeoutException $e) { // handle exception } catch (SimpleSnmpException $e) { // handle exception } // array ( // 0 => array ( // 'oid' => '1.2.3.4.5.0', // 'type' => 'STRING', // 'value' => '"foo 0"', // ), // 1 => array ( // 'oid' => '1.2.3.4.5.1', // 'type' => 'STRING', // 'value' => '"foo 1"', // ), // )
bulkWalk
<?php try { $oid = '1.2.3.4.5'; $res = $snmp->bulkWalk($host, $community, $oid, $timeout, $retries); var_export($res); } catch (TimeoutException $e) { // handle exception } catch (SimpleSnmpException $e) { // handle exception } // array ( // 0 => array ( // 'oid' => '1.2.3.4.5.0', // 'type' => 'STRING', // 'value' => '"foo 0"', // ), // 1 => array ( // 'oid' => '1.2.3.4.5.1', // 'type' => 'STRING', // 'value' => '"foo 1"', // ), // )
set
<?php try { $oid = '1.2.3.4.6.0'; $snmp->set($host, $community, $oid, 's', 'test', $timeout, $retries); } catch (TimeoutException $e) { // handle exception } catch (SimpleSnmpException $e) { // handle exception }
API
namespace SurrealCristian\SnmpExtension
class Builder
public SimpleSnmpV2c getSimpleSnmpV2c ()
class SimpleSnmpV2c implements SnmpV2cInterface
public array get ( string $host, string $community, string $oid, int $timeout, int $retries )
public array getNext ( string $host, string $community, string $oid, int $timeout, int $retries )
public array walk ( string $host, string $community, string $oid, int $timeout, int $retries )
public array bulkWalk ( string $host, string $community, string $oid, int $timeout, int $retries )
public set ( string $host, string $community, string $oid, string $type, string $value, int $timeout, int $retries )
Change log
Please see CHANGELOG for more information
Testing
$ cd /path/to/repo
$ phpunit
License
The MIT License (MIT). Please see License File for more information.