0

I am able to add ec2 instances in nagios using puppet but how can I delete the instances from nagios configuration after instances get terminated.

I am looking for something, whenever any node gets terminated manually or via ASG, those, wait for 10 mins or so, if node is still down, delete it from nagios and restart nagios.

1
  • When you add the data via Puppet, you should be able to also purge the config file where you are writing to, so Puppet maintains only stuff that is in your catalog.
    – lazyfrosch
    Nov 16, 2015 at 12:11

2 Answers 2

0

For long-running hosts, use your config management tool to update your Nagios config when changes are made.

For ASG hosts, I'd just write up a simple script that uses the EC2 API to get a list of hosts for each ASG and then have the script modify the Nagios config.

2
  • nrpe is installed on each host by default. Its baked into AMI, and puppet agent as well. So even ASG is spawning new instances, it export its services and host definition to nagios server. Hence getting automatically added. I have already wrote a script which can create the config file for nagios, but as puppet is also creating the config for newely spawned instances and if script is also doing that, then its gonna conflict. I am looking for a solution which i can integrate with puppet so that i can leverage the puppet as well. Nov 16, 2015 at 13:37
  • If I can get the list of Down hosts from nagios with some API, then I can write a script to clean those hosts and run puppet, restart nagios service. I think that would solve the issue. But not able to find anything, from where I can get the list of Down hosts from nagios. Nov 16, 2015 at 13:39
0

If you have added instance in monitoring then your nagios already maintain status for your EC2. Nagios also exposes API to query down hosts along with details on since how long they are in DOWN state. You can query nagios API to get list of down hosts and write a script to delete it if it is down for more than X mins.

Check cleanup script section of this blog. Scheduled cron job on nagios instance will periodically query down hosts and delete it from host file. Code is written in PHP and REST API is exposed so that it can be called from anywhere.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .