The LB4M switches can be monitored with the standard snmp sensors of prtg. In case you do not want single sensors for each channel, the following script provides a dense sensor that combines all channels into one sensor. Output filtering allows graphical monitoring of single channels.
The script also was tested with a D-link DGS-1210 switch and should work with other similar devices that allow access to their interface table via snmp. Feel free to optimize my code and post it as a reply.
# Script for reading out traffic data from LB4M switch
# 'set placeholders as environment values' needs to be actived in sensor settings.
# SNMP must be activated in the switch settings.
# script needs net-snmp tools installed, download from here: http://www.net-snmp.org/download.html
# Result is a sensor that contains in and out data rates for all used switch ports.
#
# Adopted to accommodate different switches, DLINK DGS-1210-24 works too.
# 2016-09-20 MRO
#function to call snmptable, snmptools need to be installed, modify install path as necessary
function Get-SnmpTable {
param (
[Parameter( Position = 0, Mandatory = $true )] $Agent,
[Parameter( Position = 1, Mandatory = $true )] $OID,
$Port = 161,
$Community = "public",
$Version = "2c",
$MIBPath = "C:\programdata\Temp\net-snmp\share\snmp\mibs"
)
(&"C:\ProgramData\TEMP\net-snmp\bin\snmptable.exe" "-M$MIBPath" -m RFC1213-MIB -Cbf `; "-v$Version" "-c$Community" "${Agent}:$Port" "$OID")
}
#Init variables
$csvData=""
[string]$prtgresult=""
$deviceAddr=$env:prtg_host
#use snmptable to read interface table from switch, skipping first two lines with headline
$csvdata = Get-SnmpTable $deviceAddr iftable | Select-Object -Skip 2| ConvertFrom-Csv -Delimiter ';'
#$csvData|out-file c:\temp\out1.txt
#use only switch ports that are operational
$csvdata = ($csvData|Select-Object * |where OperStatus -eq 'up')
#uncomment for debugging:
#$csvData|out-file c:\temp\out.txt
#build header for PRTG XML-file
$prtgresult+="<?xml version=""1.0"" encoding=""Windows-1252"" ?>`r`n"
$prtgresult+="<prtg>`r`n"
#build PRTG results data
foreach ($i in $csvData)
{
write-host " Processing Datapoint :" $i.index
$prtgresult+=" <result>`r`n"
$prtgresult+=" <channel>Port "+$i.index+" in </channel>`r`n"
$prtgresult+=" <value>"+$i.InOctets +"</value>`r`n"
$prtgresult+=" <float>0</float>`r`n"
$prtgresult+=" <mode>Difference</mode>`r`n"
$prtgresult+=" <unit>BytesBandwidth</unit>`r`n"
$prtgresult+=" </result>`r`n"
$prtgresult+=" <result>`r`n"
$prtgresult+=" <channel>Port "+$i.index+" out</channel>`r`n"
$prtgresult+=" <value>"+$i.outOctets +"</value>`r`n"
$prtgresult+=" <float>0</float>`r`n"
$prtgresult+=" <mode>Difference</mode>`r`n"
$prtgresult+=" <unit>BytesBandwidth</unit>`r`n"
$prtgresult+=" </result>`r`n"
}
$prtgresult+="</prtg>"
#send data to host
Write-Host $prtgresult
Add comment