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

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

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

Post 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.
Last edited by MrWoodward on Wed Apr 26, 2017 6:04 pm, edited 1 time in total.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

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

Post 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?
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post by cdienger »

That is correct.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

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

Post by MrWoodward »

Great. Thanks. You can close this post.
Locked