Page 1 of 2
HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 8:43 am
by haile711
Hey everyone,
I am currently working on auto-discovery and auto deletion of new hosts/vms created. I have my hosts automated already, but I'm having trouble writing up a script to delete hosts that are no longer active or needed. A scenario, I have at least 20-50 new hosts get created a day, and maybe 2 weeks down the road, another team to expired or released this hosts or environment. I dun want Nagios to keep sending out alerts, and as to clean up, I want to schedule a task to delete hosts that are already expired and/or released. I was thinking of pulling the information from the DBs, with the "Released or Expired" hosts/VMs and compare with the hosts under nagios/etc/hosts" if they exist then delete. That is the logic I got, but I just dunno how to implement it. If anyone got any idea or suggestion that would be great help, and If anyone here is really good with scripting, please share me some thoughts, or give me a head starting place. Thank you very much for your time!!!
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 9:18 am
by tmcdonald
Deleting the files will only work as a temporary measure, since every time you click "Apply Config" they will get written from the Core Config Manager database out to files again.
So your next question is probably "How can I automate deleting from the CCM DB then?"
And this is where I have to give the answer you will not like.
We cannot officially recommend or support direct database manipulation. The database schema is fairly relational, and it is not as simple as "Delete a host" and be done with it. Just as in Core, you cannot have a service without an associated host, so deleting a host directly in XI will cause a failed configuration if the associated services are not also deleted. Not only that, but if that host was defined as a hostgroup member, or a parent of another host, or a dependency, etc. then deleting it will cause a failed configuration unless *all* of those associations are first deleted. This holds true for multiple levels of association (child -> parent -> grandparent).
The silver lining is that you are of course free to modify the database directly if you so choose, but doing so is not something for which we can provide support.
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 9:56 am
by haile711
Thanks for the fast reply tmcdonald, this is of course sad new tho

, but thxs!!
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 10:17 am
by tmcdonald
We have had our eye on automation for a while, but it's a complex topic and will take some time to implement.
If I may suggest a workaround?
If you are comfortable working with the config files, we do have a "static" folder located under /usr/local/nagios/etc/static in which you can place config files. They will be picked up by Nagios and monitored, and will be visible in the interface still (status, graphing, etc), but they are not visible in the CCM for modification. They live and die by the command line. If you are fine with that, it's an excellent way to do automation without touching the database.
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 10:35 am
by haile711
That is a great suggestion tmcdonald, I have worked with the config files for quite sometimes now. I'm 100% efficient on it, but it is a great place to start playing with it. Thnxs
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 11:56 am
by haile711
to tmcdonald,
I've moved a host to the nagios/etc/static directory, I just want to know how does Nagios pick up this cfg file? Do I have to rerun the ./reconfigure_nagios.sh or anything like that? or does Nagios has it own cron job for this? I have added for a while now, but it still hasn't showed up in the Nagios interface yet.
Re: HostGroup and Hosts Auto Deleting
Posted: Tue Jul 14, 2015 4:21 pm
by tmcdonald
Any time you make a change to the configuration, you need to restart the nagios process. This is done automatically when you make changes in the CCM in XI and click "Apply Configuration". For the static directory, you will need to make sure to run service nagios restart or similar to get it to pick up the changes.
Re: HostGroup and Hosts Auto Deleting
Posted: Wed Jul 15, 2015 7:34 am
by haile711
good morning tmcdonald,
I had place a xxxxx.cfg in the /nagios/etc/static with the following content, but Nagios is not picking it up. What kind of a permission does the file need? 644 is enough? Or is there something wrong with the content of the file? Thanks for helping out!!! Also, I have ran "service nagios restart" as well as "Apply Config" in the CCM.
Code: Select all
define host {
name xxxx
alias ShopApp_JBOSS
address xxxx
hostgroups zzzz
check_command check-host-alive!!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24x7
event_handler xi_host_notification_handler
contact_groups ifs_ecom_cloud_support
notification_interval 5
notification_period 24x7
notification_options d,u,r,f,
notifications_enabled 1
register 1
}
Re: HostGroup and Hosts Auto Deleting
Posted: Wed Jul 15, 2015 11:14 am
by tmcdonald
Needs to be
host_name, not just
name:
http://nagios.sourceforge.net/docs/3_0/ ... .html#host
Though it is odd that nagios did not log that as an error...
Re: HostGroup and Hosts Auto Deleting
Posted: Wed Jul 15, 2015 12:28 pm
by haile711
hey tmcdonald, I did "host_name" before but Nagios was complaining about that, so I changed it to "name". I've just changed it to "host_name" and it's showing up. Thnxs so much for your help.
Is this the proper way to define the hostgroup? and just place this in the /nagios/ect/static directory too?
Code: Select all
define hostgroup {
hostgroup_name DDDD
alias DDDD
members
}