changelog-chef-reporter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/changelog-chef-reporter.gemspec +16 -0
- data/lib/changelog-reporter.rb +83 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f53ba7b3ff2054685a37f24481e07714ade5e5f1
|
4
|
+
data.tar.gz: bd57b47e9badc7243498614a086eb21916e195e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65c9658ac151f9f8918696565426e1bd135add1c60f9835710956f593fa0054f31c5a3f6ea342c346c0cada3fecdf02ef9b51bdd83022a933377011e119b77f5
|
7
|
+
data.tar.gz: 5db5aee84ccc409648b36356220b61aa56b688f720d32ec65fd9eb1422585cd9b9d566b7a4e7f01b444dee65bf4a7fadd426b3b1ce52dffef3dbc7f76e8ae162
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
copies of this license document, and changing it is allowed as long
|
8
|
+
as the name is changed.
|
9
|
+
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Changelog-Chef-reporter
|
2
|
+
|
3
|
+
Changelog-Chef reporter is a Chef handler for
|
4
|
+
reporting the list of updated resources to changelog. The resource list can be
|
5
|
+
filtered by resource type (template, cookbook_file, etc), all types
|
6
|
+
are outputted by default.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install changelog-chef-reporter
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Append the following to your Chef client configs, usually at
|
15
|
+
`/etc/chef/client.rb`
|
16
|
+
|
17
|
+
require "changelog-chef-reporter"
|
18
|
+
report_handlers << ChangelogReporter.new({
|
19
|
+
:host_name => "http://your.changelog.host"
|
20
|
+
:port => "80"
|
21
|
+
})
|
22
|
+
|
23
|
+
Alternatively, you can use the LWRP (available @
|
24
|
+
http://community.opscode.com/cookbooks/chef_handler)
|
25
|
+
|
26
|
+
You can provide an array of resource types to be included in the
|
27
|
+
report, default is all. You can also filter by name
|
28
|
+
|
29
|
+
report_handlers << ChefangelogReporter.new({
|
30
|
+
:resource_types => %w[template cookbook_file package service],
|
31
|
+
:filters => %w[motd]
|
32
|
+
:host_name => "https://your.changelog.host"
|
33
|
+
:port => "443"
|
34
|
+
:ssl => true
|
35
|
+
})
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "changelog-chef-reporter"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.authors = ["Csergo Balint", "Szelcsanyi Gabor"]
|
5
|
+
s.email = ["csergo.balint@ustream.tv"]
|
6
|
+
s.homepage = "https://github.com/ustream/changelog-chef-reporter"
|
7
|
+
s.summary = "A Chef reporter, which reports to changelog"
|
8
|
+
s.description = "A Chef reporter, which reports to changelog"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.license = "WTFPL"
|
11
|
+
|
12
|
+
s.rubyforge_project = "changelog-chef-reporter"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Author:
|
2
|
+
# Balint Csergo <csergo.balint@ustream.tv>
|
3
|
+
# Gabor Szelcsanyi <szelcsanyi.gabor@ustream.tv>
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'chef/handler'
|
7
|
+
require 'net/https'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
SEVERITY = {
|
11
|
+
'INFO' => 1,
|
12
|
+
'NOTIFICATION' => 2,
|
13
|
+
'WARNING' => 3,
|
14
|
+
'ERROR' => 4,
|
15
|
+
'CRITICAL' => 5 }
|
16
|
+
|
17
|
+
module Handlers
|
18
|
+
class ChangelogReporter < Chef::Handler
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
@resource_types = options.delete(:resource_types) || %w[]
|
22
|
+
@filters = options.delete(:filters) || %w[]
|
23
|
+
@host = options.delete(:host) || ""
|
24
|
+
@port = options.delete(:port) || 443
|
25
|
+
@ssl = options.delete(:ssl) || true
|
26
|
+
end
|
27
|
+
|
28
|
+
def deflate_severity(severity)
|
29
|
+
return severity if severity.is_a? Integer
|
30
|
+
SEVERITY[severity]
|
31
|
+
end
|
32
|
+
|
33
|
+
def sendreport(message, severity, category = 'misc')
|
34
|
+
httptrans = Net::HTTP.new @host, @port
|
35
|
+
httptrans.use_ssl = @ssl
|
36
|
+
httptrans.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
37
|
+
httptrans.open_timeout = 7 # seconds
|
38
|
+
httptrans.read_timeout = 5 # seconds
|
39
|
+
|
40
|
+
headers = {
|
41
|
+
'User-Agent' => "chef/changelog-reporter",
|
42
|
+
'Content-Type' => 'application/json'
|
43
|
+
}
|
44
|
+
|
45
|
+
data = {
|
46
|
+
'criticality' => deflate_severity(severity),
|
47
|
+
'unix_timestamp' => ::Time.now.to_i,
|
48
|
+
'category' => category,
|
49
|
+
'description' => message
|
50
|
+
}
|
51
|
+
|
52
|
+
begin
|
53
|
+
response = httptrans.post('/api/events', JSON.generate(data), headers)
|
54
|
+
unless response.body.include? '"OK"'
|
55
|
+
Chef::Log.warn 'Failed to send changelog message to server'
|
56
|
+
end
|
57
|
+
rescue Exception => e
|
58
|
+
Chef::Log.warn "Failed to send changelog message to server: #{e.message}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def report
|
64
|
+
Chef::Log.info "Sending list of changed resources to Changelog"
|
65
|
+
run_status.updated_resources.each do |r|
|
66
|
+
if @resource_types.empty? or @resource_types.include? r.resource_name
|
67
|
+
matches = false
|
68
|
+
unless @filters.empty?
|
69
|
+
@filters.each do |flt|
|
70
|
+
if /#{flt}/.match(r.to_s)
|
71
|
+
matches = true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
unless matches
|
76
|
+
self.sendreport("#{r} was updated on node : #{node['hostname']}", 'INFO', 'chef-run')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: changelog-chef-reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Csergo Balint
|
8
|
+
- Szelcsanyi Gabor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Chef reporter, which reports to changelog
|
15
|
+
email:
|
16
|
+
- csergo.balint@ustream.tv
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- changelog-chef-reporter.gemspec
|
27
|
+
- lib/changelog-reporter.rb
|
28
|
+
homepage: https://github.com/ustream/changelog-chef-reporter
|
29
|
+
licenses:
|
30
|
+
- WTFPL
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: changelog-chef-reporter
|
48
|
+
rubygems_version: 2.0.14
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: A Chef reporter, which reports to changelog
|
52
|
+
test_files: []
|