Ah, I get you.
Without removing the association that provides the inheritance of the 1:XX service object I don't think you would be able to accomplish what you're after.
Wonder if throwing something like this on the service object would work, even if group membership says otherwise?
Hostgroup windows includes a box named angryserver.
Windows inherits CPU checks with warn at 75 and crit at 85, this box is angry and I don't want it on that server.
So in the post to the service in the API it would be something like this.
hostgroups=windows
hosts=!angryserver
It's kind of cumbersome and I haven't tested if this would prevent the config from being written for that object.
AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire service?
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
What you've posted technically works because it creates a correct Nagios Core configuration file. However, it's....cumbersome. 
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
I just test the above scenario and it does work preventing the config from being written when done via the UI so in theory you could do same via the API, I think.
Hostgroup with two members Check applied via hostgroup Localhost excluded Only deployed to the one host
Hostgroup with two members Check applied via hostgroup Localhost excluded Only deployed to the one host
You do not have the required permissions to view the files attached to this post.
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
Yes. For us, that's quite easy, because we've written an API pre-processor script. So it would be:

Code: Select all
# napi --api --config -t hostgroupmembers -hg <hostgroup> -o h -o C
host1,host2,host3,host4
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
-
danderson
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
I think I get what you're saying, you want an API call that will basically add the host=!SOMEHOST line to the service config file and/or you want to preexisting delete command for a service to be able to handle that.
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
Yeah, I just did it in Pythoneloyd wrote: ↑Thu Oct 03, 2024 2:31 pm Yes. For us, that's quite easy, because we've written an API pre-processor script. So it would be:
Code: Select all
# napi --api --config -t hostgroupmembers -hg <hostgroup> -o h -o C host1,host2,host3,host4![]()
I have a function named nagiosxiGenericAPI that does the http interaction with the API and returns data.
Then I just take what I need from there
Code: Select all
##GET THE HOSTGROUPMEMBERS FOR THE TARGET GROUP
modhg = "&hostgroup_name={}".format(meta.hostgroup)
hostgm = nagiosxiGenericAPI("objects","hostgroupmembers",modhg,"get",auth["url"],auth["apikey"])
hd = hostgm.json()
##BUILD THE LIST
memlst = list()
hostlistcnt = 0
members = hd["hostgroup"][0]["members"]['host']
for i in members:
memlst.append(i["host_name"])
hostlistcnt += 1
print(",".join(memlist))
Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv
Yes!
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!