chef-sensu-handler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/chef-sensu-handler.gemspec +17 -0
- data/lib/chef-sensu-handler.rb +47 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: feb449d9eb66504a171b979f5cbc533b4bb5dedb
|
|
4
|
+
data.tar.gz: cd4ac14b006b336f8a4d3a08eb1d39a9e7d9f954
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: baa3f530750efc65b9f57c785b04cc0c067996426b8cca8ce30495cc5c4eb618caa67b23841b6301a81a0ce229ed71344933aedc77c5d0edc3feb3a57bfc2c62
|
|
7
|
+
data.tar.gz: 42b64954facf93db47a678a138a588f3a02377e1ea33d4c215dc20a0c5ed4b083c6febb7b93e9a7c05736616a7cb6625fdd5fa53a12ae9e3f744aabbe6ecbfbe
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2016 Christopher Powell
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Chef Sensu Handler
|
|
2
|
+
|
|
3
|
+
Chef Sensu Handler is an OpsCode Chef exception handler for notifying
|
|
4
|
+
people when a Chef run fails via Sensu. This will create and resolve Sensu
|
|
5
|
+
alerts for a node in which the chef-run fails. This leverages the Sensu
|
|
6
|
+
client's [socket input](https://sensuapp.org/docs/0.26/reference/clients.html#client-socket-input) to create/resolve checks.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
gem install chef-sensu-handler
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Append the following to your Chef client configs, usually at `/etc/chef/client.rb`. The default return status is a `warning`. You can change this to an `error` in the config if you prefer. If you would like the alerts to automatically resolve themselves on a successful run set the `report_handlers`.
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
# Notify Sensu when a Chef run fails
|
|
20
|
+
require "chef-sensu-handler"
|
|
21
|
+
|
|
22
|
+
report_handlers << SensuHandler.new # Auto-resolve alerts
|
|
23
|
+
exception_handlers << SensuHandler.new # Creates a warning
|
|
24
|
+
|
|
25
|
+
# or return status critical
|
|
26
|
+
# exception_handlers << SensuHandler.new(:critical) # Sets return status to critical
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Alternatively, you can use the LWRP (available @
|
|
30
|
+
http://community.opscode.com/cookbooks/chef_handler)
|
|
31
|
+
|
|
32
|
+
## Contributing
|
|
33
|
+
|
|
34
|
+
1. Fork it
|
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
36
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "chef-sensu-handler"
|
|
3
|
+
s.version = "0.0.1"
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.authors = ["Christopher Powell"]
|
|
6
|
+
s.email = ["powellchristoph@gmail.com"]
|
|
7
|
+
s.homepage = "https://github.com/powellchristoph/chef-sensu-handler"
|
|
8
|
+
s.summary = %q{An exception handler for OpsCode Chef which creates Sensu alerts}
|
|
9
|
+
s.description = %q{An exception handler for OpsCode Chef which creates Sensu alerts}
|
|
10
|
+
s.has_rdoc = false
|
|
11
|
+
s.license = "MIT"
|
|
12
|
+
|
|
13
|
+
s.rubyforge_project = "chef-sensu-handler"
|
|
14
|
+
|
|
15
|
+
s.files = `git ls-files`.split("\n")
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "chef/handler"
|
|
2
|
+
require "json"
|
|
3
|
+
require "socket"
|
|
4
|
+
|
|
5
|
+
SENSU_CLIENT_PORT = 3030
|
|
6
|
+
STATUS = {
|
|
7
|
+
:warning => 1,
|
|
8
|
+
:error => 2
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class SensuHandler < Chef::Handler
|
|
12
|
+
|
|
13
|
+
def initialize(status=:warning)
|
|
14
|
+
@return_status = STATUS[status]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def send_to_sensu(msg)
|
|
18
|
+
begin
|
|
19
|
+
Timeout.timeout(10) do
|
|
20
|
+
s = TCPSocket.new 'localhost', SENSU_CLIENT_PORT
|
|
21
|
+
s.puts msg.to_json
|
|
22
|
+
s.close
|
|
23
|
+
end
|
|
24
|
+
Chef::Log.info("Updated Sensu with #{msg}")
|
|
25
|
+
rescue Timeout::Error
|
|
26
|
+
Chef::Log.error("Timed out while attempting to update Sensu.")
|
|
27
|
+
rescue => error
|
|
28
|
+
Chef::Log.error("Unexpected error while attemping to update Sensu: #{error}")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def report
|
|
33
|
+
msg = { 'name' => 'check_chef_run' }
|
|
34
|
+
if run_status.success?
|
|
35
|
+
msg['status'] = 0
|
|
36
|
+
msg['output'] = 'OK: Chef-client ran successfully.'
|
|
37
|
+
elsif run_status.failed?
|
|
38
|
+
msg['status'] = @return_status
|
|
39
|
+
msg['output'] = 'WARNING: Chef-client run failed!'
|
|
40
|
+
else
|
|
41
|
+
msg['status'] = 3
|
|
42
|
+
msg['output'] = 'UNKNOWN: Not sure what happened.'
|
|
43
|
+
end
|
|
44
|
+
send_to_sensu msg
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chef-sensu-handler
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Christopher Powell
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: An exception handler for OpsCode Chef which creates Sensu alerts
|
|
14
|
+
email:
|
|
15
|
+
- powellchristoph@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- Gemfile
|
|
22
|
+
- LICENSE
|
|
23
|
+
- README.md
|
|
24
|
+
- Rakefile
|
|
25
|
+
- chef-sensu-handler.gemspec
|
|
26
|
+
- lib/chef-sensu-handler.rb
|
|
27
|
+
homepage: https://github.com/powellchristoph/chef-sensu-handler
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata: {}
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubyforge_project: chef-sensu-handler
|
|
47
|
+
rubygems_version: 2.4.5
|
|
48
|
+
signing_key:
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: An exception handler for OpsCode Chef which creates Sensu alerts
|
|
51
|
+
test_files: []
|