Page 1 of 1

How to add SNMP Traps programmatically (via REST API)?

Posted: Wed Apr 26, 2017 1:53 pm
by MrWoodward
My company has a bunch of network devices which have SNMP Events (Traps) and we would like to monitor these in NagiosXI.

I see there is an SNMP Trap wizard which is great.

How would I go about adding SNMP Traps to monitor via the REST API?

I could not find it in this document: https://assets.nagios.com/downloads/nag ... tions.html

Thanks.

Re: How to add SNMP Traps programmatically (via REST API)?

Posted: Wed Apr 26, 2017 2:24 pm
by cdienger
You can do this via the API. Help > REST API Docs > Config Reference show an example on adding a host and service via the api.

On my test machine it came down to two commands:

curl -XPOST "http://192.168.3.120/nagiosxi/api/v1/co ... F&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

curl -XPOST "http://192.168.3.120/nagiosxi/api/v1/co ... F&pretty=1" -d "host_name=testapihostapply&service_description=SNMPTRAP&check_command=check_dummy\!0\!\"TRAP RESET\",100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"


The first creates the host and the second creates a service to listen for snmp traps from that host.

https://assets.nagios.com/downloads/nag ... ios_XI.pdf covers installing and configuring Nagios to accept traps. Step through this first in case you haven't already.

Re: How to add SNMP Traps programmatically (via REST API)?

Posted: Wed Apr 26, 2017 3:00 pm
by MrWoodward
If I'm understanding you correctly, it looks like the magic string that I was looking for in the 'Service Add' command is:

Code: Select all

&check_command=check_dummy\!0\!\"TRAP RESET\",100%
And I imagine that

Code: Select all

&check_interval=5&retry_interval=5&max_check_attempts=2

values don't actually matter since it is receiving an event and not actually actively checking because it is a 'check_dummy'. Right?

Re: How to add SNMP Traps programmatically (via REST API)?

Posted: Wed Apr 26, 2017 3:03 pm
by cdienger
That is correct.

Re: How to add SNMP Traps programmatically (via REST API)?

Posted: Wed Apr 26, 2017 6:03 pm
by MrWoodward
Great. Thanks. You can close this post.