Looking for a way to delete and reconfigure services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
CFT6Server
Posts: 506
Joined: Wed Apr 15, 2015 4:21 pm

Looking for a way to delete and reconfigure services

Post by CFT6Server »

I am looking for a easy method to mass remove a particular server from a group of servers of about 300 hosts. They all have a common service check name. Is there any way to accomplish this while not remove the other services?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Looking for a way to delete and reconfigure services

Post by rkennedy »

Can you navigate toe Configure -> Core Config Manager -> click 'Services' -> search by the 'Config Name' that is relevant to the server.

From there, select all the services for that server, and select 'Delete' next to the With Checked.

Does that answer your question?
Former Nagios Employee
CFT6Server
Posts: 506
Joined: Wed Apr 15, 2015 4:21 pm

Re: Looking for a way to delete and reconfigure services

Post by CFT6Server »

Sorry that doesn't help as we have hundreds of servers to go through. I am looking for an automated way to remove a single common service from a big list of servers.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Looking for a way to delete and reconfigure services

Post by rkennedy »

Do they all have a common service description?
Former Nagios Employee
CFT6Server
Posts: 506
Joined: Wed Apr 15, 2015 4:21 pm

Re: Looking for a way to delete and reconfigure services

Post by CFT6Server »

That could work. In the search, can it do Exact match? quotes doesn't seem to work.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Looking for a way to delete and reconfigure services

Post by rkennedy »

It should work without quotes - do you have a quote in the service description?

I just tested on my machine here and see that it appends the \'s, but doesn't return a result when using a " in the search.
Former Nagios Employee
CFT6Server
Posts: 506
Joined: Wed Apr 15, 2015 4:21 pm

Re: Looking for a way to delete and reconfigure services

Post by CFT6Server »

I couldn't get exact match as it just returns everything containing the search string.
Is there any methods of modifying without the use of the GUI? I ended up have to click through after doing the initial filtering, but very time consuming.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Looking for a way to delete and reconfigure services

Post by lmiltchev »

I was hoping this could be done via the REST API but it seems like it is not possible yet. You could remove a service from a host, but if your service is added to many hosts, this wouldn't work. There is another way (workaround), where you could remove services from the CLI. Copy your config to the "imports" directory:

Code: Select all

cp /usr/local/nagios/etc/services/<your config>.cfg /usr/local/nagios/etc/import/
Open the config in a text editor:

Code: Select all

vi /usr/local/nagios/etc/import/<your config>.cfg
and remove the "unwanted" services, i.e.

change this:

Code: Select all

define service {
        host_name                       HostA,HostB,HostC,HostD
        service_description             Service1
		...
		}
to this:

Code: Select all

define service {
        host_name                       HostA
        service_description             Service1
		...
		}
or this:

Code: Select all

define service {
        host_name                       HostA,HostB,HostC,HostD
        service_description             Service1
		...
		}
		
define service {
        host_name                       HostA,HostB,HostC,HostD
        service_description             Service2
		...
		}
		
define service {
        host_name                       HostA,HostB,HostC,HostD
        service_description             Service3
		...
		}
to this:

Code: Select all

define service {
        host_name                       HostA,HostB,HostC,HostD
        service_description             Service3
		...
		}
depending on how your services were configured on the first place.

Then all you need to do is run "reconfigure".

Code: Select all

cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
CFT6Server
Posts: 506
Joined: Wed Apr 15, 2015 4:21 pm

Re: Looking for a way to delete and reconfigure services

Post by CFT6Server »

With Nagios XI, the services file is set to individual hosts. So for example hostname.cfg will only contain services from hostname. So this method wouldn't work as I would have to go through each file manually. I was hoping there could be some ways to do this bulk but doesn't seem like there's any options?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Looking for a way to delete and reconfigure services

Post by lmiltchev »

With Nagios XI, the services file is set to individual hosts. So for example hostname.cfg will only contain services from hostname.
I see. I thought you had one service added to multiple hosts because of what you said in your first post.

It is possible to remove these services via mysql query but this is not recommended (nor supported). Removing 300+ services in the CCM could be a tedious task but it is not awfully difficult. All you need to do is go to CCM->Services, select "None" from the "Limit Results To" drop-down menu, type the service name in the "Search" bar, and hit "Enter" (Don't select any configs from the "Filter by Config Name" drop-down menu). Select "Toggle All Checkboxes". De-select the ones that you don't want to be deleted, then click on "Go" ("With Checked" = "Delete"). Apply Configuration.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked