Remove a defined service from all instances?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
guht
Posts: 4
Joined: Mon Jun 08, 2015 6:41 pm

Remove a defined service from all instances?

Post by guht »

I inherited a Nagios Core 3.3.1 box that is responsible for monitoring customers Amazon instances in the cloud.

I am trying to remove a defined service for ALL customers, but I cant find out how to do it through the website GUI. I feel like there may be some missing menus or options in my GUI, but I am logged in as an admin. So...

I was hoping there is a way to do it from the command line, but unsure.


Here is a little more info about my setup:
Located under "/usr/local/nagios/etc/objects" I have 5 files related to a customer.

contact_customerid.cfg
customer_customerid.cfg
instance_instaceid.cfg
service_instanceid_BASIC.cfg
service_instanceid_GROUP.cfg


In EVERY SINGLE service_instanceid_BASIC.cfg I have the following service defined:

Code: Select all

define service{
        use                             generic-service
        host_name                       <hostname>
        service_description             Antivirus
        check_command                   check_antivirus
        normal_check_interval           30
}
Here is the GUI:
Image
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Remove a defined service from all instances?

Post by jdalrymple »

Nagios Core is entirely managed from the CLI re: host and service (etc) configuration. There is no way to remove it from those things from the GUI. You can disable notifications for services and other like realtime commands, but the services themselves will remain.

NagiosXI (our commercial product) is what you'd need to manage from the GUI.

Here is the handbook for Core - lots of valuable reading there for an individual unfamiliar with Nagios Core:

http://nagios.sourceforge.net/docs/nagi ... n/toc.html
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: Remove a defined service from all instances?

Post by jolson »

It's difficult to approach what you're trying to do because of the way the configuration files have been designed on your end. I highly recommend looking into hostgroups so that situations like this one are easier in the future: http://nagios.sourceforge.net/docs/3_0/ ... #hostgroup

With that said, you could do this with a one-liner. Please cd into your /usr/local/nagios/etc/objects directory. Please note that the below command will remove *all* blocks of text with 'Antivirus' anywhere in them, so ensure that 'Antivirus' does not appear anywhere else in the file.

Code: Select all

for i in `find -iname '*.cfg'`; do awk -v RS= '!/Antivirus/{printf $0""RT}' $i > /tmp/$i; done
After the above command is done running, take a look at your /tmp directory - you should see a copy of each of your configuration files. Note that any block containing 'Antivirus' has been removed. Now all that you should need to do is copy those /tmp/*.cfg files to /usr/local/nagios/objects and overwrite your old files.

Verify that the files in /tmp look correct before running the below commands.

Code: Select all

cp /tmp/*.cfg /usr/local/nagios/objects/
service nagios restart
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
guht
Posts: 4
Joined: Mon Jun 08, 2015 6:41 pm

Re: Remove a defined service from all instances?

Post by guht »

Thank you for the responses and information! I am going to try that this weekend when I have a moment to breathe... On call 24/7/7 this week, and it sucks! Lol... Thanks for the help though, much appreciated!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Remove a defined service from all instances?

Post by ssax »

Make sure to take a backup and have good VM snapshots and try it on a test machine first just in case something goes wrong.
guht
Posts: 4
Joined: Mon Jun 08, 2015 6:41 pm

Re: Remove a defined service from all instances?

Post by guht »

Thanks ssax! I made backups and tested it on a couple small batches, and then ran it against the all of them.

It worked beautifully! Now to go study up on hostgroups! it looks like some of the services have hostgroups assigned to them.

I also need to look into how these are getting created initially. Our Nagios is tied into another system, that seems to pass some info through HTTP POST method, that gets parsed by some java calls to Nagios. Always fun learning new stuff! ;)
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: Remove a defined service from all instances?

Post by jolson »

I'm glad it worked for you! Are we good to lock this thread as resolved?
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
guht
Posts: 4
Joined: Mon Jun 08, 2015 6:41 pm

Re: Remove a defined service from all instances?

Post by guht »

Whoops sorry gave cred to ssax, when it was your answer that solved it jolson! Appreciate the responses, and yes please mark as resolved! Thanks again!
jolson
Attack Rabbit
Posts: 2560
Joined: Thu Feb 12, 2015 12:40 pm

Re: Remove a defined service from all instances?

Post by jolson »

No problem. Feel free to open further threads if you have more questions/issues. Thanks!
Twits Blog
Show me a man who lives alone and has a perpetually clean kitchen, and 8 times out of 9 I'll show you a man with detestable spiritual qualities.
Locked