Download the PHP package ocolin/easysnmp without Composer
On this page you can find all versions of the php package ocolin/easysnmp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ocolin/easysnmp
More information about ocolin/easysnmp
Files in ocolin/easysnmp
Package easysnmp
Short Description PHP SNMP client providing formatted, DTO-backed access to standard MIB-II data without requiring SNMP knowledge
License MIT
Informations about the package easysnmp
[!WARNING] v3.0.0 is a complete rewrite and is not compatible with v1.x or v2.x. Requires PHP 8.4+ and FreeDSx SNMP.
![]()
![]()
![]()
ocolin/easysnmp
A PHP SNMP client that provides formatted, DTO-backed access to standard MIB-II data without requiring SNMP knowledge. Pass in your authentication credentials, call a method, get structured data back.
Built on top of FreeDSx SNMP.
Requirements
- PHP 8.4+
- FreeDSx SNMP
^0.5.1 - ocolin/global-type
^2.0
Installation
Configuration
Configuration is handled by the Config class. Credentials can be passed
explicitly or read automatically from environment variables.
Explicit configuration
Environment variables
If no explicit values are passed, Config falls back to environment variables
using the EASY_SNMP_ prefix by default:
Multiple devices with prefixes
When monitoring multiple devices, use the $prefix parameter to namespace
your environment variables:
Prefix values are case-insensitive — 'juniper' and 'JUNIPER' both resolve
to JUNIPER_SNMP_*.
Configuration reference
The EASY prefix in all ENV variable names is replaced by your custom prefix
when using the $prefix parameter. For example, with prefix: 'JUNIPER' the
variable EASY_SNMP_HOST becomes JUNIPER_SNMP_HOST.
| ENV Variable | Constructor Argument | Type | Default | Description |
|---|---|---|---|---|
EASY_SNMP_HOST |
$host |
?string |
null |
Hostname or IP of device |
EASY_SNMP_COMMUNITY |
$community |
?string |
null |
SNMP v1/v2c community string |
EASY_SNMP_PORT |
$options['port'] |
?int |
161 |
SNMP port |
EASY_SNMP_VERSION |
$options['version'] |
?int |
2 |
SNMP version (1, 2, 3) |
EASY_SNMP_TIMEOUT_CONNECT |
$options['timeout_connect'] |
?int |
5 |
Connection timeout in seconds |
EASY_SNMP_TIMEOUT_READ |
$options['timeout_read'] |
?int |
10 |
Read timeout in seconds |
EASY_SNMP_USER |
$options['user'] |
?string |
null |
SNMPv3 username |
EASY_SNMP_AUTH_PWD |
$options['auth_pwd'] |
?string |
null |
SNMPv3 auth password |
EASY_SNMP_PRIV_PWD |
$options['priv_pwd'] |
?string |
null |
SNMPv3 privacy password |
EASY_SNMP_AUTH_MECH |
$options['auth_mech'] |
?string |
null |
SNMPv3 auth mechanism |
EASY_SNMP_PRIV_MECH |
$options['priv_mech'] |
?string |
null |
SNMPv3 privacy mechanism |
EASY_SNMP_ENGINE_ID |
$options['engine_id'] |
?string |
null |
SNMPv3 engine ID |
EASY_SNMP_CONTEXT_NAME |
$options['context_name'] |
?string |
null |
SNMPv3 context name |
EASY_SNMP_USE_AUTH |
$options['use_auth'] |
?bool |
null |
Enable SNMPv3 authentication |
EASY_SNMP_USE_PRIV |
$options['use_priv'] |
?bool |
null |
Enable SNMPv3 privacy |
Usage
System information
Interface table (ifTable)
Fetch only specific columns to reduce SNMP calls:
Extended interface table (ifXTable)
ARP table
LLDP remote table
IP address table
IpAddrTable properties
| Property | Type | Description |
|---|---|---|
$address |
?string |
IP address |
$interface |
?int |
Interface index — matches IfTable index |
$netmask |
?string |
Subnet mask |
$bcast |
?int |
Broadcast address bit |
$reasmMaxSize |
?int |
Maximum datagram size for reassembly |
MAC address table
MacTable properties
| Property | Type | Description |
|---|---|---|
$mac |
?string |
Raw MAC address. Use SnmpHelper::formatMacAddress() |
$bridge |
?int |
Bridge port number |
$interface |
?int |
Interface index — matches IfTable index. Null indicates the MAC is associated with the bridge interface itself rather than a physical port |
$status |
?int |
Entry status. Use SnmpHelper::formatMacStatus() |
IP forwarding table
IpForwardTable properties
| Property | Type | Description |
|---|---|---|
$destination |
?string |
Destination network address — always present |
$mask |
?string |
Destination subnet mask — always present |
$policy |
?int |
Route policy, typically 0 — always present |
$nextHop |
?string |
Next hop IP address — always present |
$interface |
?int |
Interface index — matches IfTable index |
$type |
?int |
Route type. Use SnmpHelper::formatIpForwardType() |
$protocol |
?int |
Routing protocol. Use SnmpHelper::formatIpForwardProto() |
$age |
?int |
Seconds since route was last updated |
$info |
?string |
Protocol specific info, rarely populated |
$nextHopAs |
?int |
Next hop autonomous system number |
$metric1 |
?int |
Primary routing metric |
$metric2 |
?int |
Secondary routing metric |
$metric3 |
?int |
Tertiary routing metric |
$metric4 |
?int |
Fourth routing metric |
$metric5 |
?int |
Fifth routing metric |
$status |
?int |
Row status. Use SnmpHelper::formatRowStatus() |
STP port table
StpPortEntry properties
| Property | Type | Description |
|---|---|---|
$bridge |
?int |
Bridge port number — matches $bridge in MacEntry |
$priority |
?int |
Port priority (0-255), default 128 |
$state |
?int |
STP port state. Use SnmpHelper::formatStpPortState() |
$enable |
?int |
Port enabled status. Use SnmpHelper::formatStpPortEnable() |
$pathCost |
?int |
STP path cost for this port |
$desRoot |
?string |
Designated root bridge ID (8 bytes). Use SnmpHelper::formatBridgeId() |
$desCost |
?int |
Designated path cost to root bridge |
$desBridge |
?string |
Designated bridge ID (8 bytes). Use SnmpHelper::formatBridgeId() |
$desPort |
?string |
Designated port ID (2 bytes). Use SnmpHelper::formatStpPortId() |
Formatting helpers
Raw integer values can be converted to human-readable labels using SnmpHelper:
All helper methods accept null and return null, so they are safe to call
directly on nullable DTO properties.
Extending for vendor-specific devices
EasySNMP is designed to be extended. Vendor-specific functionality can be
added by extending the base class and adding traits for proprietary OID trees:
The extending class inherits all standard MIB-II methods and gains access to
bulkWalk(), getColumn(), and getCompositeColumn() for building
vendor-specific trait methods.
PHP 8.4 compatibility
FreeDSx SNMP was written for PHP 7.4 and contains a nullable type deprecation
that triggers on PHP 8.4. This is handled internally within EasySNMP and does
not affect consuming code. A fix has been submitted upstream via pull request.
Property Lists
IfTable properties
| Property | Type | Description |
|---|---|---|
$index |
int |
Interface index |
$description |
?string |
Interface description string |
$type |
?int |
IANA interface type. Use SnmpHelper::formatIfType() |
$mtu |
?int |
Maximum transmission unit in bytes |
$speed |
?int |
Interface speed in bits per second |
$macAddress |
?string |
Raw MAC address. Use SnmpHelper::formatMacAddress() |
$adminStatus |
?int |
Administrative status. Use SnmpHelper::formatAdminStatus() |
$operStatus |
?int |
Operational status. Use SnmpHelper::formatOperStatus() |
$lastChange |
?int |
Time of last status change in TimeTicks |
$inOctets |
?int |
32-bit input byte counter |
$outOctets |
?int |
32-bit output byte counter |
$inErrors |
?int |
Input error counter |
$outErrors |
?int |
Output error counter |
IfXTable properties
| Property | Type | Description |
|---|---|---|
$index |
int |
Interface index — matches IfTable index |
$name |
?string |
Interface name |
$inMcast |
?int |
32-bit multicast inbound packets |
$outMcast |
?int |
32-bit multicast outbound packets |
$inBcast |
?int |
32-bit broadcast inbound packets |
$outBcast |
?int |
32-bit broadcast outbound packets |
$inHcOctets |
?int |
64-bit input byte counter, use instead of inOctets on fast interfaces |
$inHcUcast |
?int |
64-bit unicast inbound packets |
$inHcMcast |
?int |
64-bit multicast inbound packets |
$inHcBcast |
?int |
64-bit broadcast inbound packets |
$outHcOctets |
?int |
64-bit output byte counter, use instead of outOctets on fast interfaces |
$outHcUcast |
?int |
64-bit unicast outbound packets |
$outHcMcast |
?int |
64-bit multicast outbound packets |
$outHcBcast |
?int |
64-bit broadcast outbound packets |
$highSpeed |
?int |
Speed in Mbps, use instead of speed on fast interfaces |
$alias |
?string |
Administrator-set interface alias |
System properties
| Property | Type | Description |
|---|---|---|
$descr |
?string |
Full description of the device |
$upTime |
?int |
System uptime in TimeTicks |
$contact |
?string |
Contact information |
$name |
?string |
Device name |
$location |
?string |
Physical location |
$objectId |
?string |
Vendor enterprise OID |
ArpTable properties
| Property | Type | Description |
|---|---|---|
$interface |
?int |
Interface index — matches IfTable index |
$mac |
?string |
Raw MAC address. Use SnmpHelper::formatMacAddress() |
$ipAddress |
?string |
IP address of ARP entry |
$type |
?int |
Entry type. Use SnmpHelper::formatArpType() |
Direct SNMP access
For custom queries beyond the built-in methods, pass-through access to the underlying FreeDSx client is available:
These methods return raw FreeDSx objects. See the FreeDSx documentation for details on working with the returned values.
License
MIT