Page 1 of 1

API call for Service as a member of a Hostgroup

Posted: Thu Jan 16, 2025 5:05 am
by optionstechnology
I have an issue where I have two different services with the same name running under two different config names

So for example service_description "Disk D:" under config_name "Windows2000" and "Disk D:" under config_name "Windows2016"

The checks are assigned to hostgroups only, no hosts - so there is a hostgroup called Windows2000 which has all of the Windows 2000 servers in it and the same for Windows2016

This works fine but my issue is that I am trying to detect if "Disk D:" exists as a service for "Windows2016" via the API

Unfortunatly the API for /objects/services only returns the hosts that the service is attached to - it doesnt return the config name or any hostgroups that may also be a member

I've tried using "config_name" as a filter for services - i.e.

Code: Select all

https://SERVER/nagiosxi/api/v1/objects/service?apikey=APIKEY&service_description=Disk%20D:&config_name=Windows2016
But it appears you can only specify config_name when adding a service and not when searching for an existing one annoyingly

Currently the only way around it is to collate a list of members of the two hostgroups and then check if at least one name from each appears in the list of hosts the service is attached to..... obvisouly a rediculously overcomplex way of doing this....

Has anyone had this issue and came up with a better solution?

Re: API call for Service as a member of a Hostgroup

Posted: Thu Jan 16, 2025 11:05 am
by jsimon
Hi @optionstechnology,

I've made a feature request to add the config_name field to the /objects/services API, for output as well as queries. When this enhancement is released, it'll be tagged in the CHANGELOG file with [GL:XI#1193].

Re: API call for Service as a member of a Hostgroup

Posted: Thu Jan 16, 2025 3:00 pm
by jsimon
Actually after some more time looking into this, I believe the Config API is what you're looking for, as opposed to the Objects API. I was able to query my own system for services with a specified config_name with a request formatted like this:

Code: Select all

curl -XGET "https://[ip_address]/nagiosxi/api/v1/config/service?config_name="[config_name]"&apikey=[apikey]pretty=1"
I'm going to leave the feature request as-is, in case we determine there is value in also providing this data on the objects API, but hopefully this addresses your needs. Let us know if you have any other questions!

Re: API call for Service as a member of a Hostgroup

Posted: Wed Feb 12, 2025 11:08 am
by optionstechnology
yip you're right - that got it working

thanks