API call for Service as a member of a Hostgroup
Posted: Thu Jan 16, 2025 5:05 am
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.
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?
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=Windows2016Currently 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?