I've been digging through the API documentation, but I can seem to find a call\filter for seeing what hosts have a host template applied. I was thinking maybe:
https://nagiosxi.windstream.com/nagiosx ... onfig/host?
with use=templatename as a filter, but that pulls back all hosts. Is there any good API method to see what hosts have a host template applied?
API Question
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: API Question
Hi @J.A.K,
That would be the best endpoint to pull this from. You can filter this down using a script to pull just the host name and corresponding template files.
While we do not provide customer programming in support, here's a sample script (using python 3):
Let us know if you have any other questions.
--Benjamin
That would be the best endpoint to pull this from. You can filter this down using a script to pull just the host name and corresponding template files.
While we do not provide customer programming in support, here's a sample script (using python 3):
Code: Select all
import requests
import json
# Update IP Address / API key with your server information
api = {'baseurl':'http://192.168.23.113/nagiosxi',
'key':'?apikey=sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6',
'config_hosts': '/api/v1/config/host'
}
def get_api_data(url,endpoint,key):
data = requests.get(url + endpoint + key, verify=False )
return data
r = get_api_data(api['baseurl'],api['config_hosts'],api['key'])
hosts = r.json()
# Print out host name and templates
i = 0
while i < len(hosts):
print( hosts[i]['host_name'], end=",")
try:
for template in hosts[i]['use']:
print(template, end=',')
except:
print("No Template Assigned", end=",")
i = i + 1
print('\n')
--Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API Question
Sounds good thank you! I just wanted to make sure there wasn't a filter already before I reinvented the wheel.
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: API Question
Hi,
Your welcome.
Let us know if you have any other questions or if it's okay to close this topic.
Regards,
Benjamin
Your welcome.
Let us know if you have any other questions or if it's okay to close this topic.
Regards,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API Question
I apologize for breaking in into this thread,
Is there a place where we can share custom API endpoints?
I've written an custom API endpoint for retrieving free variables from hosttemplates.
I would like to share my custom API endpoint, and would like to see what others have written
Kind regards,
Joris Weijters
Is there a place where we can share custom API endpoints?
I've written an custom API endpoint for retrieving free variables from hosttemplates.
I would like to share my custom API endpoint, and would like to see what others have written
Kind regards,
Joris Weijters
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: API Question
Hi Joris,
Best Regards,
Benjamin
Not a problem. That would be great. Right now, the best place would be on the Nagios Exchange in the Utilities category. You can upload a file or post a link to your GitHub or other code sharing site.I apologize for breaking in into this thread,
Is there a place where we can share custom API endpoints?
Best Regards,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!