Skip to content

Commit

Permalink
allow disabling removing from sensu (#19)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
majormoses authored and eheydrick committed Mar 28, 2018
1 parent 35648d9 commit c67ad3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions bin/aws_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c67ad3e

Please sign in to comment.