REST API to Modify Host Config that use Template Inheritance

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
onegative
Posts: 175
Joined: Tue Feb 17, 2015 12:06 pm

REST API to Modify Host Config that use Template Inheritance

Post by onegative »

G 'Day Nagios Support,

So I am wanting to write an automation to modify hosts that use host templates to assign multiple aspects of inherited configurations. But I can't seem to get the POST correct. Perhaps this isn't possible???

Regardless I appreciate your help in advance,
Danny

The error is complaining about "Missing required variables" but those specific variables are to be inherited from the templates.
{
"error": "Missing required variables",
"missing": [
"max_check_attempts",
"check_period",
"notification_interval",
"notification_period",
"contacts OR contact_groups"
]
}


I've highlighted the specific template I want to change.
Can anyone provide an example to modify the following host config that I pulled from the API?

Original API GET config result:
[
{
"host_name": "dcom-nms-p1",
"use": [
"TSO-UNIX_NAGIOS_NCPA",
"TSO-UNIX_LVL-01",
"DATA-CENTER-TDC"
],
"alias": "dcom-nms-p1.mcis.washington.edu",
"address": "172.16.97.17",
"icon_image": "redhat.png",
"statusmap_image": "redhat.png",
"register": "1"
}
]

Expected POST replaced config:
[
{
"host_name": "dcom-nms-p1",
"use": [
"TSO-UNIX_NAGIOS_NCPA",
"TSO-UNIX_LVL-03",
"DATA-CENTER-TDC"
],
"alias": "dcom-nms-p1.mcis.washington.edu",
"address": "172.16.97.17",
"icon_image": "redhat.png",
"statusmap_image": "redhat.png",
"register": "1"
}
]
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: REST API to Modify Host Config that use Template Inherit

Post by gsmith »

Hello there,

I am going to need to "lab this up" but it's the end of our day here and I won't be able to
get to it until tomorrow.

What might be helpful would be for you to try to create a new host using your "Expected POST replaced config",
changing the hostname and IP of course.

Code: Select all

[
{
"host_name": "dcom-nms-p1",
"use": [
"TSO-UNIX_NAGIOS_NCPA",
"TSO-UNIX_LVL-03",
"DATA-CENTER-TDC"
],
"alias": "dcom-nms-p1.mcis.washington.edu",
"address": "172.16.97.17",
"icon_image": "redhat.png",
"statusmap_image": "redhat.png",
"register": "1"
}
]
Let me know if that helps in anyway, or if you just see the same thing as when you try to modify a host.

Also, please send me a System Profile.
To send us your system profile.
1. Login to the Nagios XI GUI using a web browser.
2. Click the "Admin" > "System Profile" Menu
3. Click the "Download Profile" button
4. Save the profile.zip file and share this in a private message and then reply to this post to bring it up in the queue.
Thanks!
onegative
Posts: 175
Joined: Tue Feb 17, 2015 12:06 pm

Re: REST API to Modify Host Config that use Template Inherit

Post by onegative »

@gsmith

So I guess my description wasn't clear as I can see now that I wasn't precise.

From the Help documentation it describes the required parameters as follows:
requiredParams.png
There doesn't appear to be a parameter describing the use of a Host Template which is where my parameters are defined.
max_check_attempts
check_period
notification_interval
notification_period
contacts OR contact_groups

If I define them at this host level, the inheritance from the host template would be overrode and defeat the purpose of managing my environment using them.

So I guess what I am really asking is how would the curl command be formatted to utilize multiple Host Templates...and whether or not if it is even possible...seems like the API is insisting on these values be defined in the host.cfg as opposed to the use: Host Template

I am still on Nagios XI 5.6.1 and don't know if the current or latest release has options to pass a Host Template in the api call.
If the ability is not available, then I am just spinning my wheels because I need/want/require to manage hosts using templates as it eases the overall management burden immensely.

If you could just find out from the developers whether the latest or current version of the api supports the use templates in the call that would let us know whether to continue trying to fulfill my request.

Thanks for your time as appreciate your help,
Danny
You do not have the required permissions to view the files attached to this post.
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: REST API to Modify Host Config that use Template Inherit

Post by gsmith »

Hi,

I talked with the Dev team and that capability is not available in any version
of Nagios XI.

How is your scripting? You could write a script would generate the api command based on the template you
would want to use. You would have to include the other parameter values as well (hostname, ip, etc) as
input. The script would need to extract the values from /usr/local/nagios/etc/hosttemplates.cfg as all
the host templates are defined there. The potential "gotcha" would be when one template references
another, your script would have to be able to follow those links.

Thanks
onegative
Posts: 175
Joined: Tue Feb 17, 2015 12:06 pm

Re: REST API to Modify Host Config that use Template Inherit

Post by onegative »

@gsmith

Yea after seeing the required parameter list I figured the "use" parameter was not available.
Yes I could easily extract the template values and populate to each host.cfg but that means I would have to then manage yet another one-off or convert everything to use the local parameter for each host.cfg...instead I'll stick with Host Templates...if I need to modify any global parameter it's just one change, in one place...and the added benefit is that if I need to override a specific host I can at the host.cfg level. Templates make managing large environment much easier.

Thanks for your help and query to the Dev team...
You can Lock the Thread...
Appreciate y'all,
Danny
Locked