\SwitchSonic
Live switch/routers SNMP bandwidth monitoring implementation
Synopsis
class SwitchSonic
{
- // constants
- const CACHE_KEY = 'SWITCHSONICDATA';
- const AUTH_KEY = 'SWITCHSONICAUTH';
- const OID_CHECK = '.1.3.6.1.2.1.1.1.0';
- const OID_IFINDEX = '.1.3.6.1.2.1.2.2.1.1';
- const OID_IFDESCR = '.1.3.6.1.2.1.31.1.1.1.18';
- const OID_OCTIN = '.1.3.6.1.2.1.31.1.1.1.6';
- const OID_OCTOUT = '.1.3.6.1.2.1.31.1.1.1.10';
- const OID_STATE = '.1.3.6.1.2.1.2.2.1.8';
- // members
- protected string $ip = '';
- protected string $community = '';
- protected $snmp = '';
- protected $cache = '';
- protected integer $cachingTimeout = 120;
- protected integer $timeWindow = 300;
- protected integer $offsetKilo = 1024;
- protected integer $offsetMega = 1024000;
- protected integer $offsetGiga = 1024000000;
- // methods
- public void __construct()
- protected void setOptions()
- protected void initCache()
- protected void initSnmp()
- protected array getIfaces()
- protected array getIfDescr()
- protected array getOctIn()
- protected array getOctOut()
- protected array getLinks()
- public bool checkAuth()
- protected string extractPortNum()
- protected array receiveOidData()
- public array getStats()
- protected string convertSpeed()
- protected float speedForCharts()
- protected string convertLinkState()
- public string renderSpeeds()
- public string renderCharts()
Constants
Name | Value |
---|---|
CACHE_KEY | 'SWITCHSONICDATA' |
AUTH_KEY | 'SWITCHSONICAUTH' |
OID_CHECK | '.1.3.6.1.2.1.1.1.0' |
OID_IFINDEX | '.1.3.6.1.2.1.2.2.1.1' |
OID_IFDESCR | '.1.3.6.1.2.1.31.1.1.1.18' |
OID_OCTIN | '.1.3.6.1.2.1.31.1.1.1.6' |
OID_OCTOUT | '.1.3.6.1.2.1.31.1.1.1.10' |
OID_STATE | '.1.3.6.1.2.1.2.2.1.8' |
Members
protected
- $cache
—
Caching engine object placeholder - $cachingTimeout
—
int
Default caching timeout to store switch/auth data in seconds - $community
—
string
Contains remote device SNMP read community - $ip
—
string
Contains remote device IP address - $offsetGiga
—
int
Contains default kilo-multiplier to convert bits in Giga - $offsetKilo
—
int
Contains default kilo-multiplier to convert bits in Kilo - $offsetMega
—
int
Contains default kilo-multiplier to convert bits in Mega - $snmp
—
SNMP helper object placeholder - $timeWindow
—
int
Time window to display on charts in seconds
Methods
protected
- convertLinkState() — Converts basic port infor into link state led
- convertSpeed() — Converts actual octet counters into human-readable speed value
- extractPortNum() — Returns port/interface ID extracted from left part of OID
- getIfDescr() — Returns available ports description as port=>desc
- getIfaces() — Returns array of available interfaces on device as port=>iface
- getLinks() — Returns array of interface activity states as port=>state up/down
- getOctIn() — Returns array of interfaces octets in as port=>octets
- getOctOut() — Returns array of interfaces octets out as port=>octets
- initCache() — Inits system caching engine
- initSnmp() — Inits SNMP helper instance for further usage
- receiveOidData() — Returns preprocessed data extracted from OID as port=>value
- setOptions() — Sets IP/community to current instance
- speedForCharts() — Converts octet speed values into Mbit/s
public
- __construct() — Cretes new Sonic instance
- checkAuth() — Checks can we auth on device and receive some data or not?
- getStats() — Rturns array of preprocessed device stats
- renderCharts() — Renders charts based on speedline of some ports
- renderSpeeds() — Renders device stats