Wrapper over the Net-SNMP CLI client. Serves as an alternative to the PHP SNMP extension.
Via Composer
$ composer require surrealcristian/snmp-netsnmpclient
- PHP 5.4+
- Net-SNMP CLI client (
sudo apt-get install snmp
)
<?php
require __DIR__ . '/../vendor/autoload.php';
use SurrealCristian\SnmpNetSnmpClient\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();
<?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"',
// )
<?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' => '1.2.3.4.5.1',
// 'type' => 'STRING',
// 'value' => '"foo 1"',
// )
<?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"',
// ),
// )
<?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"',
// ),
// )
<?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
}
namespace SurrealCristian\SnmpNetSnmpClient
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 )
Please see CHANGELOG for more information
$ cd /path/to/repo
$ phpunit
The MIT License (MIT). Please see License File for more information.