Community:Sending SNMP Traps On Windows

From Splunk Wiki

Jump to: navigation, search

Install the Net-SNMP package for Windows.

Enter the following into a new file, named sendsnmptrap.cmd in %SPLUNK_HOME%\bin\scripts. Edit the agent host, port, community, and snmptrap.exe command path appropriately.

When configuring a saved search, provide the script name (sendsnmptrap.cmd) as the script to be run when an alert is triggered.

You may also wish to provide a MIB to your SNMP monitoring system.

setlocal

set SNMPAGENTHOST=127.0.0.1
set SNMPAGENTPORT=162
set TRAPOID=1.3.6.1.4.1.27389.1.2
set OID=1.3.6.1.4.1.27389.1.1
set SNMPCOMMUNITY=public
set SNMPTRAPCMD=C:\usr\bin\snmptrap.exe
for /f "usebackq" %%h in (`hostname`) do @set myhost=%%h
set num=%~1
set num=%num:'=%
set terms=%2
set query=%3
set sname=%4
set reason=%5
set permalink=%6
if "%8" == "" (
    set resultspath=%7
) else (
    set tags=%7
    set resultspath=%8
)

if "%8" == "" (
    "%SNMPTRAPCMD%" -v 2c -c %SNMPCOMMUNITY% %SNMPAGENTHOST%:%SNMPAGENTPORT% "" %TRAPOID% %OID%.1 i %num%  %OID%.2 s %terms%  %OID%.3 s %query%  %OID%.4 s %sname%  %OID%.5 s %reason% %OID%.6 s %permalink% %OID%.8 s %resultspath%
) ELSE (
    "%SNMPTRAPCMD%" -v 2c -c %SNMPCOMMUNITY% %SNMPAGENTHOST%:%SNMPAGENTPORT% "" %TRAPOID% %OID%.1 i %num%  %OID%.2 s %terms%  %OID%.3 s %query%  %OID%.4 s %sname%  %OID%.5 s %reason% %OID%.6 s %permalink% %OID%.8 s %resultspath% %OID%.7 s %tags%
)



endlocal 
Personal tools
Hot Wiki Topics


About Splunk >
  • Search and navigate IT data from applications, servers and network devices in real-time.
  • Download Splunk