Page 1 of 1
Deleting Hosts
Posted: Wed Jul 08, 2015 2:26 pm
by peter.zanetti
I was curious about what goes on behind the scenes when deleting a host from the GUI. Does a script get called and delete the host or is it strictly deleting a row from the database?
Re: Deleting Hosts
Posted: Wed Jul 08, 2015 2:36 pm
by jolson
When you delete a host from the Web GUI, you are removing it from the database on the backend. This database is used to write out the configuration files, which are actually used by Nagios. What this means is that the next time you run an 'Apply Configuration' from the Web GUI, the flat configuration file will be removed from your Nagios server.
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 6:52 am
by peter.zanetti
So if I wanted to delete a host through the command line is that doable or does it need to be through the database?
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 9:17 am
by tmcdonald
It is doable but not something we can recommend doing.
When you delete a host, you are essentially deleting a row from the database. However, in the web interface when you delete a host there are a few checks that go on to ensure proper deletion is possible. If you try to delete a host that has services attached to it, or is a parent, or is a master in a dependency somewhere, or there are any other connections that the host is a part of, you will need to sever those connections first and the web interface will not allow deletion. This is to prevent your configs from becoming invalid, such as having a service for a host that no longer exists.
Though to answer your question directly, anything that can be done in the database can essentially be done through the CLI, you just use an echo statement to pipe your SQL commands into the mysql command, instead of logging in to mysql and using their frontend to run commands.
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 10:10 am
by peter.zanetti
So assuming a host has no dependencies of any kind besides being a member of a host group, is it as simple as deleting a row from the nagios_hosts table in the database?
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 10:22 am
by lmiltchev
We don't recommend modifying database directly. If you want to add/remove hosts/services from the command like, you can review the following document:
https://assets.nagios.com/downloads/nag ... gement.pdf
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 10:26 am
by peter.zanetti
thank you! I'll do some testing and let you know if I have any questions.
Re: Deleting Hosts
Posted: Thu Jul 09, 2015 10:31 am
by tmcdonald
And one thing to keep in mind, any tables that start with "nagios_" are part of the ndoutils database (named "nagios"), and will not reflect what files actually get written to disk and used. That's the CCM database (named "nagiosql"), and tables there begin with "tbl_". Big difference, and this is another part of why we cannot suggest direct manipulation. All too often we see people work with the wrong database and lose information they didn't want to.