API Question

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
J.A.K
Posts: 103
Joined: Wed Aug 05, 2020 11:39 am

API Question

Post by J.A.K »

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?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: API Question

Post by benjaminsmith »

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):

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')
Let us know if you have any other questions.
--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!
J.A.K
Posts: 103
Joined: Wed Aug 05, 2020 11:39 am

Re: API Question

Post by J.A.K »

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

Post by benjaminsmith »

Hi,

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!
jweijters
Posts: 63
Joined: Thu Feb 06, 2020 3:50 am

Re: API Question

Post by jweijters »

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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: API Question

Post by benjaminsmith »

Hi Joris,
I apologize for breaking in into this thread,
Is there a place where we can share custom API endpoints?
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.

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!
Locked