Hi Felix,
Thank you for the pointers. I managed to achieve what I wanted :)
I followed your advice.
I used NETSNMP to do the SNMP walk.
I modified the script using this template https://kb.paessler.com/en/topic/73131 Credits goes to Dariusz Gorka :)
What the script does:
- Does the snmpwalk of the OID of interest
- Retrieves the number of instances (in my case, the number of alarms)
- Outputs the string (in my case, the alarm description)
Since the script outputs the number of instances, I just enabled alerting based on limits, simply setting the upper error limit to 0. The moment that there is a device alarm, the sensor will go down :)
Also, since the script outputs the string, I am also able to see the alarm description on the 'Message' of PRTG. The message, however includes the OID and "STRING:" because of the output of the SNMP walk. I don't have any idea how to remove them and just retaining the string itself to make the message more neat. I tried several output options on the snmpwalk.exe command but I am not able to get it. Maybe others will have an idea on how to do this??? Here's a sample output of the string when I ran the PS script:
<text>Alarm Messages: .1.3.6.1.4.1.272.4.46.5.1.54 = STRING: "this is a test alarm"</text>
Below is the modified script. This is confirmed to be working based on my own tests.
Feedbacks are most welcome!
# ____ ____ ____________
# / __ \/ __ \/_ __/ ____/
# / /_/ / /_/ / / / / / __
# / ____/ _, _/ / / / /_/ /
#/_/ /_/ |_| /_/ \____/
# NETWORK MONITOR
#-------------------
#
# This script checks the current alarms of a target device with dynamic OID suffix using snmpwalk
#
# Parameter "-hostaddr" for the nCompass IP address
# Parameter "-community" for the SNMP v2c Community
# Parameter "-port" for the SNMP port of the device
# Parameter "-timeout" for the timeout of the request
# Parameter "-troubleshoot" for the troubleshooting of this script
param(
[string]$hostaddr = "localhost",
[string]$community = "public",
[string]$port = "161",
[string]$timeout = "5",
[int]$troubleshoot = 0
)
$regex_string = "(STRING:..)([a-zA-Z0-9- ])"
[string[]] $walkresult = @(C:\usr\bin\snmpwalk.exe -Cc -Ln -On -v 2c -c $community $hostaddr":"$port ".1.3.6.1.4.1.272.4.46.5.1.54" -t $timeout 2>&1)
if ($troubleshoot -eq 1){
$walkresult_trouble = $walkresult -join ''
}
if (!($walkresult -like "*= String: *")){
$alarms = 0
} else {
$alarms = $walkresult.count }
[string]$walkresult_result = $walkresult -join ''
write-host "<prtg>"
write-host "<result>"
write-host "<channel>Number of Current Alarms</channel>"
write-host "<value>$($alarms)</value>"
write-host "</result>"
if($troubleshoot -eq 0){
if (!($alarms -eq 0)){
write-host "<text>Alarm Messages: $($walkresult_result)</text>"
}
}
if ($troubleshoot -eq 1){
write-host "<text>$($walkresult_trouble)</text>"
}
write-host "</prtg>"
Add comment