Page 1 of 1
Remove a defined service from all instances?
Posted: Tue Jul 14, 2015 10:56 pm
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:

Re: Remove a defined service from all instances?
Posted: Wed Jul 15, 2015 9:49 am
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
Re: Remove a defined service from all instances?
Posted: Wed Jul 15, 2015 10:12 am
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
Re: Remove a defined service from all instances?
Posted: Thu Jul 16, 2015 4:40 pm
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!
Re: Remove a defined service from all instances?
Posted: Thu Jul 16, 2015 4:46 pm
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.
Re: Remove a defined service from all instances?
Posted: Fri Jul 17, 2015 10:04 am
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!

Re: Remove a defined service from all instances?
Posted: Fri Jul 17, 2015 10:12 am
by jolson
I'm glad it worked for you! Are we good to lock this thread as resolved?
Re: Remove a defined service from all instances?
Posted: Fri Jul 17, 2015 11:00 am
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!
Re: Remove a defined service from all instances?
Posted: Fri Jul 17, 2015 11:07 am
by jolson
No problem. Feel free to open further threads if you have more questions/issues. Thanks!