Page 1 of 1

Bulk Change "config name"

Posted: Wed Apr 30, 2014 9:26 am
by BanditBBS
I want to rename a bunch of services that are currently named "_multiple_hosts" from when I imported them, Bulk renaming tool doesn't cover the config name change, only the service name. Is there a way to do this in bulk, like a mysql update command, will that hurt anything? If that will work, anyone want to write the command out for me so I don't have to spend an hour figuring out the proper context :)

Re: Bulk Change "config name"

Posted: Wed Apr 30, 2014 10:10 am
by lmiltchev
When you rename a host via the Bulk Renaming Tools, it would rename the config file name for the services as well. All configs will be renamed in "/usr/local/nagios/etc/hosts" and "/usr/local/nagios/etc/services".

Re: Bulk Change "config name"

Posted: Wed Apr 30, 2014 10:16 am
by BanditBBS
This isn't for any host. This is the "config name" field on a bunch of services that have hostgroups assigned to them. I want to change "_multiple_hosts" to something that describes the services better.
Capture.JPG

Re: Bulk Change "config name"

Posted: Wed Apr 30, 2014 3:59 pm
by tmcdonald
Well, the table tbl_service in the nagiosql database has a field called "config_name" which stores the flat file name. You would probably need to match the config name to the host name, or pick an arbitrary name as long as it is consistent. Observe:

Grab id, flat file name, and service description

Code: Select all

mysql> select id,config_name,service_description from tbl_service;
+----+---------------+-------------------------+
| id | config_name   | service_description     |
+----+---------------+-------------------------+
|  1 | localhost     | PING                    |
|  2 | localhost     | Root Partition          |
|  3 | localhost     | Current Users           |
|  4 | localhost     | Total Processes         |
|  5 | localhost     | Current Load            |
|  6 | localhost     | Swap Usage              |
|  7 | localhost     | SSH                     |
|  8 | localhost     | HTTP                    |
| 10 | localhost     | Always Fails            |
| 14 | 192.168.4.163 | Ping                    |
| 15 | 192.168.4.163 | Weblogic Heap           |
| 16 | 192.168.4.163 | Weblogic Thread Pool    |
| 17 | 192.168.4.163 | Weblogic Transactions   |
| 18 | 192.168.4.163 | Weblogic Connections    |
| 19 | 192.168.4.163 | Weblogic Queue          |
| 71 | Arduino       | Security Alert - Window |
+----+---------------+-------------------------+
16 rows in set (0.00 sec)
Layout of table matching services to hosts

Code: Select all

mysql> describe tbl_lnkServiceToHost;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| idMaster | int(11) | NO   | PRI | NULL    |       |
| idSlave  | int(11) | NO   | PRI | NULL    |       |
+----------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Grab all service<->host associations (service is Master, host is Slave)

Code: Select all

mysql> select * from tbl_lnkServiceToHost;
+----------+---------+
| idMaster | idSlave |
+----------+---------+
|        1 |       1 |
|        2 |       1 |
|        3 |       1 |
|        4 |       1 |
|        5 |       1 |
|        6 |       1 |
|        7 |       1 |
|        8 |       1 |
|       10 |       1 |
|       14 |       4 |
|       15 |       4 |
|       16 |       4 |
|       17 |       4 |
|       18 |       4 |
|       19 |       4 |
|       71 |       6 |
+----------+---------+
16 rows in set (0.00 sec)
Grab all host ids and names

Code: Select all

mysql> select id,host_name from tbl_host;
+----+-----------+
| id | host_name |
+----+-----------+
|  1 | localhost |
|  4 | WebLogic  |
|  6 | Arduino   |
+----+-----------+
3 rows in set (0.00 sec)
Now you can see which services match to which hosts, and start coming up with names. There is a better way to do this with joins but that is a bit more tricky and I'd like to save those big guns for if you can't script this out.