Page 1 of 1

Use the API to change threshold one or more services

Posted: Mon Apr 26, 2021 10:30 am
by nms
Hi all,

We currently run NagiosXI v5.7.3.

with the API backend it seems you can do lots of interesting things.
At present we sometimes use to apply config, for example:

Code: Select all

curl -XPOST "http://<NagiosxiIP>/nagiosxi/api/v1/system/applyconfig?apikey=XXXXXXXXXXXXX"

{"success":"Apply config command has been sent to the backend."}
Was wondering if the API method can be used to update a threshold for one service or services.

Is that possible and can you supply an example in order to achieve that?

Rgds,

Re: Use the API to change threshold one or more services

Posted: Mon Apr 26, 2021 5:36 pm
by benjaminsmith
Hi,

You can update the check command using the API. However, the string will be for the entire command, check command plus arguments. Each separate argument needs to be separated by an !.

So a command like this:
/usr/local/nagios/libexec/check_ncpa.py -H 192.168.23.142 -t 'welcome' -P 5693 -M 'disk/logical/|' -w '70' -c '90'
Would look like this using an API call. The exclamation point needs to be escaped and %20 is used for spaces.

Code: Select all

 curl -XPUT "https://192.168.23.113/nagiosxi/api/v1/config/service/192.168.23.142/Disk?apikey=sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6&pretty=1&check_command=check_xi_ncpa\!-t%20'welcome'%20-P%205693%20-M%20'disk/logical/|'%20-w%20'70'%20-c%20'90'&applyconfig=1" 
If you do not need to do this programmatically, the Bulk Mods Tool is very good at updating individual arguments.

Let us know if you have more questions.
Benjamin