AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire service?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

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

Post by snapier3 »

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.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post by eloyd »

What you've posted technically works because it creates a correct Nagios Core configuration file. However, it's....cumbersome. :-)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

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

Post by snapier3 »

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
hg-linux.PNG
hg-memers.PNG
Check applied via hostgroup
hostgroup-apply.PNG
Localhost excluded
excludedhost.PNG
Only deployed to the one host :)
deployed-service.PNG
You do not have the required permissions to view the files attached to this post.
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

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

Post by snapier3 »

eloyd wrote: Thu Oct 03, 2024 1:41 pm What you've posted technically works because it creates a correct Nagios Core configuration file. However, it's....cumbersome. :-)
Most Definitely True!

Have you tried getting a csv list of hostgroup members though?
:lol:

--SN
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post by eloyd »

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

Post by danderson »

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.
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

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

Post by snapier3 »

eloyd 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
:-)
Yeah, I just did it in Python
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 8-)

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))
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post by eloyd »

danderson wrote: Fri Oct 04, 2024 10:44 am 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.
Yes!
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Post Reply