Page 1 of 1

How to get the host template for a host??

Posted: Tue Jan 17, 2017 6:34 am
by WillemDH
While trying to solve this with a script: https://support.nagios.com/forum/viewto ... 16&t=41981

I'm getting the detailed host object in ps with:

Code: Select all

$InvStruct.Web.Downloadstring("$($InvStruct.Nagurl)/nagios/cgi-bin/objectjson.cgi?query=host&hostname=$NagHostName"
This in order to retrieve the configured template. But the template doesn't seem to be in the result of the JSON API. I also tried the new API:

curl -XGET "https://nagiosserver/nagiosxi/api/v1/ob ... testserver"

But this also doesn't contain the host template??

How can I do get the host template, so I can compare the configured contacts with the host template in order to see the impact of the bulk modiification wizard issue... Why si the template not in the result of neither of the above 2 api's? Please make a feature request for this.

Tx

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 12:07 pm
by avandemore
You are correct, this information isn't available current through the API's.

I have create FR 10722 on this issue.

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 12:50 pm
by gormank
No help from the API perspective, but the template is in the use line of the host config file at /usr/local/nagios/etc/hosts/.

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 1:06 pm
by WillemDH
@gormank Know that, but I'm automating through Powershell. Got a big script which is able to list, compare and update os, infrastructure, role and location based hostgroups, free variables, and export to Excel.. Wanted to add a feature which could check for hosts having a specific template and not the additive notification option.. But it needs to get the info from some api thing.

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 2:09 pm
by SteveBeauchemin
Willem,

Reading what you are attempting. For today until there is an actual solution, could you expose that directory to your web browser maybe? Add a file to /etc/httpd/conf.d/
Name it something temporary like temp.conf and fill it with something like this

Code: Select all

# Copy this to /etc/httpd/conf.d
# Delete this when there is an API that allows me to see this data
Alias /hiddenhosts "/usr/local/nagios/etc/hosts"

<Directory "/usr/local/nagios/etc/hosts">
   Options +Indexes
</Directory>
Or something like this that works. It can be an unpublished link only you know about. Then your Powershell can grab the specific host file data using http:// and grep for the template.

Consider this a brainstorming session, like we are at a conference, if they had another one.

Steve B

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 2:31 pm
by WillemDH
I have a workaround atm. Just pasted the output of the relations for the hostgroup in the generated Excell. I know the problem hosts now. And received the missing code for the bulk tool by pm, so I can mass fix now.
It should still be possible to get the template of a host with the api though in the future, so leaving this open.
Thanks all for the advices!

Re: How to get the host template for a host??

Posted: Tue Jan 17, 2017 3:30 pm
by avandemore
For the record, leaving this thread open or closed with have no impact on the FR.