From c67ad3e071c18dde19d050b393dec02e381e4211 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Wed, 28 Mar 2018 14:25:45 -0700 Subject: [PATCH] allow disabling removing from sensu (#19) It defaults to the old behavior (not set will equal true) while allowing it to be disabled. At some point in the future we can change that default if that makes sense. Signed-off-by: Ben Abrams --- README.md | 20 ++++++++++++++++++-- bin/aws_cleaner.rb | 8 ++++++++ config.yml.sample | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09c7b14..bf1c6bf 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ [![Dependency Status](https://gemnasium.com/badges/github.com/eheydrick/aws-cleaner.svg)](https://gemnasium.com/github.com/eheydrick/aws-cleaner) AWS Cleaner listens for EC2 termination events produced by AWS [CloudWatch Events](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchEvents.html) -and removes the instances from Chef and Sensu monitoring. Optionally -sends messages to Hipchat or Slack when actions occur. +and removes the instances from Chef. It can optionally remove the node from Sensu Monitoring (defaults true), fire off webhooks, and send notifications via Hipchat & Slack when actions occur. ![aws-cleaner](https://raw.github.com/eheydrick/aws-cleaner/master/aws-cleaner.png) @@ -88,6 +87,23 @@ To enable webhooks, add a `:webhooks:` section to the config: Chat notifications can be sent when the webhook successfully executes. See config.yml.sample for an example of the config. +### Sensu + +By default aws-cleaner assumes that removing from sensu is desired as this was one of its core intentions. To allow people to leverage this without sensu you can disable it via config: +``` +:sensu: + :enable: false +``` + +When wanting to use sensu you will want the following config: +``` +:sensu: + :url: 'http://sensu.example.com:4567' + :enable: true +``` + +While we currently assume sensu removal being desired is considered the default it may not always be so you should set `enable` to true to avoid a breaking change later. + ### Limitations - Currently only supports a single AWS region. diff --git a/bin/aws_cleaner.rb b/bin/aws_cleaner.rb index 23d7466..a29290e 100755 --- a/bin/aws_cleaner.rb +++ b/bin/aws_cleaner.rb @@ -89,6 +89,7 @@ def chef(id, instance_id, chef_node) end def sensu(id, instance_id, chef_node) + return unless @config[:sensu][:enable] if AwsCleaner::Sensu.in_sensu?(chef_node, @config) if AwsCleaner::Sensu.remove_from_sensu(chef_node, @config) @logger.info("Removed #{chef_node} from Sensu") @@ -114,6 +115,13 @@ def closelog(message) @sqs_client = AwsCleaner::SQS.client(@config) @chef_client = AwsCleaner::Chef.client(@config) +# to provide backwards compatibility as this key did not exist previously +@config[:sensu][:enable] = if @config[:sensu][:enable].nil? + true + else + @config[:sensu][:enable] + end + # main loop loop do begin diff --git a/config.yml.sample b/config.yml.sample index 7fe25c2..9b42a01 100644 --- a/config.yml.sample +++ b/config.yml.sample @@ -7,6 +7,7 @@ :queue: 'https://sqs.us-west-2.amazonaws.com/1234/cloudwatch-events' :sensu: :url: 'http://sensu.example.com:4567' + :enable: true :chef: :url: 'https://chef.example.com/organizations/example' :client: 'somebody'