chef-handler-opsmatic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +16 -0
- data/Rakefile +2 -0
- data/chef-handler-opsmatic.gemspec +23 -0
- data/lib/chef/handler/opsmatic.rb +93 -0
- data/lib/chef/handler/version.rb +7 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64eb12dc56908853517b1f1529109eccc2b05e2d
|
4
|
+
data.tar.gz: 90331dbc1e8186e558f0ca69c7337189deee26b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71481007f5d064ea9935e86edcaa8e53eae62f15aedd918510aefd64eb4cb88b2b9562c085c635fe3c568ab17c4fcf2153c9bcf43b2859ae5adaae586b183d49
|
7
|
+
data.tar.gz: 4df527a418c18ac419bb77e4b21f8af9b2b50ed09a610f87d6280d8d2c1929de7431d2843aaa9607c99e28cbe5d9dfdf1c3b11f199e1338cb8fa1a346ebb8eeb
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Opsmatic Inc.
|
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,16 @@
|
|
1
|
+
# Chef::Handler::Opsmatic
|
2
|
+
|
3
|
+
The chef-handler-opsmatic gem is a Chef report and exception handler
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
The easiest way to install this handler in your Chef environment is with the `handler`
|
8
|
+
recipe in the [chef-opsmatic](https://github.com/opsmatic/chef-opsmatic) cookbook.
|
9
|
+
|
10
|
+
## Contributing
|
11
|
+
|
12
|
+
1. Fork it ( https://github.com/[my-github-username]/chef-handler-opsmatic/fork )
|
13
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
14
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
15
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
16
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef/handler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chef-handler-opsmatic"
|
8
|
+
spec.version = Chef::Handler::Opsmatic::VERSION
|
9
|
+
spec.authors = ["Marcus Barczak"]
|
10
|
+
spec.email = ["support@opsmatic.com"]
|
11
|
+
spec.summary = %q{Chef report handler for sending run detail information to Opsmatic}
|
12
|
+
spec.description = %q{Chef report handler for sending run detail information to Opsmatic}
|
13
|
+
spec.homepage = "https://github.com/opsmatic/chef-handler-opsmatic"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'chef/handler'
|
2
|
+
require 'chef/resource/directory'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class Chef
|
8
|
+
class Handler
|
9
|
+
class Opsmatic < ::Chef::Handler
|
10
|
+
def initialize(config = {})
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def report
|
15
|
+
if @config[:integration_token].nil? || @config[:integration_token].empty?
|
16
|
+
Chef::Log.warn("Opsmatic integraton integration_token missing, report handler disabled")
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
if run_status.success?
|
21
|
+
resource_count = run_status.updated_resources.count
|
22
|
+
resource_word = (resource_count == 1) ? "resource" : "resources"
|
23
|
+
summary = "Chef updated #{resource_count} #{resource_word}"
|
24
|
+
else
|
25
|
+
summary = "Chef run failed"
|
26
|
+
end
|
27
|
+
|
28
|
+
opsmatic_event = {
|
29
|
+
:timestamp => run_status.end_time.to_i,
|
30
|
+
:source => 'chef_raw',
|
31
|
+
:subject_type => 'hostname',
|
32
|
+
:subject => node.fqdn,
|
33
|
+
:type => 'cm/chef',
|
34
|
+
:summary => summary,
|
35
|
+
:data => {
|
36
|
+
:status => run_status.success? ? "success" : "failure",
|
37
|
+
:start_time => run_status.start_time,
|
38
|
+
:end_time => run_status.end_time,
|
39
|
+
:duration => run_status.elapsed_time,
|
40
|
+
:updated_resources => []
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if not run_status.updated_resources.nil?
|
45
|
+
run_status.updated_resources.each do |resource|
|
46
|
+
detail = {
|
47
|
+
:cookbook_name => resource.cookbook_name,
|
48
|
+
:recipe_name => resource.recipe_name,
|
49
|
+
:action => resource.action,
|
50
|
+
:name => resource.name,
|
51
|
+
:resource_name => resource.resource_name
|
52
|
+
}
|
53
|
+
opsmatic_event[:data][:updated_resources] << detail
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# if there's an exception include details in event
|
58
|
+
if !run_status.exception.nil?
|
59
|
+
opsmatic_event[:data][:exception] = run_status.formatted_exception
|
60
|
+
end
|
61
|
+
|
62
|
+
submit opsmatic_event
|
63
|
+
end
|
64
|
+
|
65
|
+
def submit(event)
|
66
|
+
Chef::Log.info("Posting chef run report to Opsmatic")
|
67
|
+
|
68
|
+
url = URI.parse("#{@config[:collector_url]}?token=#{@config[:integration_token]}")
|
69
|
+
|
70
|
+
http = Net::HTTP.new(url.host, url.port)
|
71
|
+
http.open_timeout = 2
|
72
|
+
http.read_timeout = 2
|
73
|
+
http.use_ssl = (url.scheme == 'https')
|
74
|
+
|
75
|
+
request = Net::HTTP::Post.new(url.request_uri)
|
76
|
+
request["Content-Type"] = "application/json"
|
77
|
+
request.body = [event].to_json
|
78
|
+
|
79
|
+
begin
|
80
|
+
response = http.request(request)
|
81
|
+
if response.code != "202"
|
82
|
+
Chef::Log.warn("Got a #{response.code} from Opsmatic event service, chef run wasn't recorded")
|
83
|
+
Chef::Log.info(response.body)
|
84
|
+
end
|
85
|
+
rescue Timeout::Error
|
86
|
+
Chef::Log.warn("Timed out connecting to Opsmatic event service, chef run wasn't recorded")
|
87
|
+
rescue Exception => msg
|
88
|
+
Chef::Log.warn("An unhandled execption occured while posting event to Opsmatic event service: #{msg}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-handler-opsmatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcus Barczak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Chef report handler for sending run detail information to Opsmatic
|
42
|
+
email:
|
43
|
+
- support@opsmatic.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.md
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- chef-handler-opsmatic.gemspec
|
54
|
+
- lib/chef/handler/opsmatic.rb
|
55
|
+
- lib/chef/handler/version.rb
|
56
|
+
homepage: https://github.com/opsmatic/chef-handler-opsmatic
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Chef report handler for sending run detail information to Opsmatic
|
80
|
+
test_files: []
|