Page 1 of 2
Can I update Nagios active service status using Rest API
Posted: Thu Aug 19, 2021 10:25 am
by JosephH
Hi,
I am using Nagios XI 5.8.1.
I know that we can use rest API to add/update service configuration into Nagios XI. Just wonder is it possible to update defined active service status information using API?
Like set the current_state, output, perfdata etc. of the defined active check service in Nagios XI.
Thanks
Joseph
Re: Can I update Nagios active service status using Rest API
Posted: Fri Aug 20, 2021 9:26 am
by ssax
The only way you can change them would be to submit another result through the API, see here on your XI server:
Code: Select all
http://YOURXISERVER/nagiosxi/help/api-system-reference.php#system-core-command
With these commands:
https://assets.nagios.com/downloads/nag ... ernalcmds/
These specifically:
https://assets.nagios.com/downloads/nag ... and_id=114
https://assets.nagios.com/downloads/nag ... and_id=115
Re: Can I update Nagios active service status using Rest API
Posted: Mon Aug 23, 2021 9:54 am
by JosephH
Hi ssax,
Thank you so much for the info. It works.
One more thing, how do I pass the performance data (perfdata, format or position)?
PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output>
The "plugin_output" field contains text output from the service check, along with optional performance data.
Thank you,
Joseph
Re: Can I update Nagios active service status using Rest API
Posted: Mon Aug 23, 2021 5:48 pm
by ssax
Go view the service under Home > Service Status and click on the service, then click the + tab and look at the Performance Data column, that would be the perfdata format you would use after a pipe (|) character
Code: Select all
PROCESS_SERVICE_CHECK_RESULT;localhost;SSH;0;SSH OK - OpenSSH_7.3 (protocol 2.0) | time=0.006961s;;;0.100000;11.000000
Code: Select all
curl -k -L -XPOST "https://X.X.X.X/nagiosxi/api/v1/system/corecommand?apikey=YYYYY" -d 'cmd=PROCESS_SERVICE_CHECK_RESULT;localhost;SSH;0;SSH OK - OpenSSH_7.3 (protocol 2.0) | time=0.006961s;;;0.100000;11.000000'
Re: Can I update Nagios active service status using Rest API
Posted: Tue Aug 24, 2021 7:04 am
by JosephH
it worked. Thank you!
Re: Can I update Nagios active service status using Rest API
Posted: Wed Aug 25, 2021 9:29 am
by ssax
Great! Let us know when we're okay to lock this up and mark it as resolved.
Re: Can I update Nagios active service status using Rest API
Posted: Fri Aug 27, 2021 3:34 pm
by JosephH
Hi ssax,
One more question:
Is there a rate limit we should consider when posting commands to the the Core Command API?
I have about 10000 services to update using the core command API you mentioned, it took me about 20 minutes to get updated in Nagios. in the rate of 500 posting command per minutes.
Any suggestion to speed up these process? The faster the better.
Let me know if you need more info.
Thanks
Joseph
Re: Can I update Nagios active service status using Rest API
Posted: Mon Aug 30, 2021 11:50 am
by ssax
Edit: What specifically are you trying to do with this? Are you just submitting results or are you trying to reset the checks or something?
Re: Can I update Nagios active service status using Rest API
Posted: Mon Aug 30, 2021 11:56 am
by JosephH
No. I am not using the apply configuration at all for this API call. Looks like it is not needed.
Re: Can I update Nagios active service status using Rest API
Posted: Tue Aug 31, 2021 9:55 am
by ssax
Sorry, I edited the post after I sent it, this was my next question after realizing you're not applying configuration when submitting results:
What specifically are you trying to do with this? Are you just submitting results or are you trying to reset the checks or something?
I'm trying to see if there's a better way to handle what you're trying to do.