API for host and service templates

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

API for host and service templates

Post by dh0125e »

I don't see an API for listing, getting, creating, and updating host and service templates. Does one exist?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API for host and service templates

Post 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"
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: API for host and service templates

Post 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?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API for host and service templates

Post 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.
Locked