Ad Widget

Collapse

Monitoring SNMP Over Active Checks (Windows Agent Only)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • richb
    Junior Member
    • Jul 2007
    • 7

    #1

    Monitoring SNMP Over Active Checks (Windows Agent Only)

    I'm unsure if there is a better way to do this, though this works fine for me...

    We needed a way to check whether a Leased Line private circuit was up or not. The obvious way was to read the SNMP values out of the router, then chuck this into Zabbix. As per my earlier posts, we have active-only checks since everything is behind NAT.

    Out came my (admittedly poor) VB skills and here's my solution:

    Firstly you need to install the net-snmp package from Sourceforge (http://net-snmp.sourceforge.net/download.html ). You only need the base components, you don't need to install any of the agents or support files. Really all you need is snmpget.exe, though it doesn't seem to work properly unless you run the installer. I've installed this to c:\zabbix\netsnmp.

    Save this script into your zabbix folder as snmp.vbs (or whatever)

    Code:
    '
    ' Zabbix SNMP query script
    '
    ' Copyright Richard Bishop July 2007
    ' [email protected]
    ' Permission granted for commercial / non-commercial
    ' usage, provided that this message is left intact
    '
    
    
    function getSnmpResult(snmp_command)
    
    	' Get a shell object
    	Set wshShell = WScript.CreateObject ("WSCript.shell")
    
    	' Execute the command
    	Set objScriptExec = wshShell.Exec(snmp_command)
    
    	' Keep looping until that returns
    	Do While objScriptExec.Status = 0
    		'  Sleep 100
    	Loop
    
    '	msgbox "Execute complete"
    
    
    	' How did that exit?
    	If objScriptExec.ExitCode = 0 Then
    
    '	   msgbox "Execute successful"
    	   return_data = objScriptExec.StdOut.ReadAll ' this should work
    
    	  else
    
    '	    msgbox "Execute failed"
    	    return_data = "Failed " & objScriptExec.ExitCode
    
    	End If
    
    	' Return the result
    	getSnmpResult=return_data
    
    end function
    
    
    ' Call the function here with your parameters
    Wscript.echo getSnmpResult("c:\zabbix\netsnmp\bin\snmpget -c public -v 1 192.168.1.1 .1.3.6.1.2.1.2.2.1.8.3")
    Now here comes in the interesting bit. You need to work out which SNMP values you are interested in. I found a great program called MIB browser (http://www.snmp-browser.com/ ) which allows you to drill-down through the device and work out what the MIB string is for the values required.

    Plug this MIB string into the last line of the script, together with the IP of the device, and the SNMP community read string. Here I'm using SNMP version 1, though you may wish to use version 2c or 3 if you're interested in security - this is a small LAN so I don't really care. The MIB string above produces 'UP' or 'DOWN' for the serial interface on our 3COM router.

    If you double-click the VB script you should get a popup dialog with the SNMP value returned, if not the double-check the IP and community string and the path of snmpget.

    If all goes well here you need to add this into Zabbix:

    Open up zabbix_agentd.conf and add a new custom item at the end of the file, give it a unique key name and set the correct path to your VB script:

    Code:
    UserParameter=uLeasedLineDown,cscript.exe /nologo "c:\Zabbix\snmp.vbs"
    Within Zabbix, add a new item on this machine using the same key value and set the type to 'Character'. You may wish to up the update interval from 30 seconds, though mine is currently at the default. Save this config and restart the zabbix agent on the Windows box. With any luck you'll see the SNMP status appearing in Zabbix. It's then a simple matter to add a new trigger and action that looks for special words in the string - 'down' is my trigger, with alerts being fired off if this word is detected.

    Within my action message I have the following, in order that I know what machine threw the error (this script is on a server at each end of the line), together with what the port status is:

    Code:
    {TRIGGER.NAME}: {STATUS}
    {HOSTNAME}
    {{HOSTNAME}:{TRIGGER.KEY}.last(0)}
    Monitoring multiple snmp values is a matter of:

    1) Adding another script and calling this from zabbix_agentd.conf
    2) Adding another call to the getSnmpResult function with different values


    Hope this helps somebody.
    Last edited by richb; 06-07-2007, 14:01.
  • adg
    Junior Member
    • Sep 2012
    • 17

    #2
    Has this been updated?

    Has this been updated to use snmpget[<OID>] as per http://www.zabbix.com/wiki/howto/mon...nmpget-win32?s[]=net&s[]=snmp?

    Any pointers on converting templates with SNMPv1 type to use the above active method?

    Comment

    Working...