Page 1 of 1

API for host and service templates

Posted: Fri Oct 30, 2020 12:34 pm
by dh0125e
I don't see an API for listing, getting, creating, and updating host and service templates. Does one exist?

Re: API for host and service templates

Posted: Fri Oct 30, 2020 5:32 pm
by ssax
There isn't currently an endpoint for these, I have created a feature request on your behalf:

Code: Select all

FR: XI - API - Add host/service templates endpoints
Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.

Actually, now that I'm testing this out you can submit a standard API post to the config/services and config/hosts endpoints with these changed/added:

For hosts:

Code: Select all

host_name=&address=&service_description=YOURTEMPLATEDESCRIPTION&name=YOURTEMPLATENAME&register=0
For services:

Code: Select all

host_name=&service_description=YOURTEMPLATEDESCRIPTION&name=YOURTEMPLATENAME&register=0
For example:
- Note: You may need to URLEncode the TEMPLATEDESC and/or YOURTEMPLATENAME if they have special characters/spaces in them:

https://meyerweb.com/eric/tools/dencoder/

For host templates:

Code: Select all

curl -k -L -XPOST "http://YOURXISERVER/nagiosxi/api/v1/config/host?apikey=XXXXXXXX&pretty=1" -d "host_name=&address=&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&name=YOURTEMPLATENAME&register=0&applyconfig=1"
For service templates:

Code: Select all

curl -k -L -XPOST "http://YOURXISERVER/nagiosxi/api/v1/config/service?apikey=XXXXXXXX&pretty=1" -d "host_name=&service_description=TEMPLATEDESC&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&name=YOURTEMPLATENAME&register=0&applyconfig=1"

Re: API for host and service templates

Posted: Mon Nov 02, 2020 11:28 am
by dh0125e
I'm trying an API call against config/host with the filter of register=0 and I'm not getting back the host templates. So it looks like this only supports creating host templates but not retrieving them?

Re: API for host and service templates

Posted: Mon Nov 02, 2020 4:57 pm
by ssax
You are correct, development will need to implement that functionality as it doesn't currently support it for the GET, I have updated the feature request again to let them know it's still needed.