Page 1 of 1

API on service update

Posted: Mon Aug 26, 2019 9:05 am
by mon-team
Dear all,
i'm using the Nagios XI API on a Nagios XI 5.5.1.
I'm focusing on services creation and update: i've noticed that using the "config/service" endpoint i cannot specify an optional Service Template.
I've workarounded this limitation using the raw import ("config/import").

However now i've a problem: if i want to change the service's Service Template i can't do it: the "config/import" doesn't allow me to update this field, and if i use the raw import Nagios creates a second services (with the service template updated).

What would you suggest?
Why the ""config/service" endpoint doesn't allow to specify such a fundamental object like the service template?
Do you know if, in the future releases, this will be allowed?

Regards
Francesco

Re: API on service update

Posted: Mon Aug 26, 2019 10:28 am
by mbellerue
You can use the PUT commands to update parameters using the API. For example,

Code: Select all

curl -XPUT "http://<MyXIAddress>/nagiosxi/api/v1/config/service/localhost/PING?apikey=<MyAPIKey>&pretty=1&use=<NewServiceTemplate>&display_name=PINGTEST&applyconfig=1""
The name use doesn't make a lot of sense from a pure API standpoint. But the reason that parameter is named that way is because use is the field in the configuration files to define templates, for hosts and services.

You can also specify use when creating your services and hosts with POST.

Re: API on service update

Posted: Wed Aug 28, 2019 2:38 am
by mon-team
Thanks for the reply,
you are right.. i read again the 'Help' section about API, and it's written exactly this...even if in a very small font :(

All normal service directives are able to be used like normal core config definition files.

I'm now able to create services with a service template!

Re: API on service update

Posted: Wed Aug 28, 2019 7:39 am
by scottwilkerson
mon-team wrote:Thanks for the reply,
you are right.. i read again the 'Help' section about API, and it's written exactly this...even if in a very small font :(

All normal service directives are able to be used like normal core config definition files.

I'm now able to create services with a service template!
Great!

Locking thread