dumblog-chef 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +17 -0
- data/.ruby-version.example +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +11 -0
- data/LICENSE +20 -0
- data/README.md +38 -0
- data/Rakefile.rb +0 -0
- data/dumblog-chef.gemspec +32 -0
- data/lib/dumblog-chef.rb +4 -0
- data/lib/dumblog-chef/handler.rb +37 -0
- data/lib/dumblog-chef/version.rb +5 -0
- data/test/test_helper.rb +0 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMjU2":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Mzk0OTc3ODA0YTJmNGM4NzFiNmI2NDM0MDEwODE1NDdlMzg0MzY1NDg2Yzg2
|
5
|
+
OTlhMDczYmMxYzVmNDk3ZmQ2Ng==
|
6
|
+
data.tar.gz: !binary |-
|
7
|
+
NWUzZjQ2NGRiN2MxNWNhY2Q4ZjRlOWU5ZmYzNTliMDkwNmYwMjAzYTc1ZDNj
|
8
|
+
MzhjMDk2NzM0M2UwZGRjZjk1NQ==
|
9
|
+
SHA512:
|
10
|
+
metadata.gz: !binary |-
|
11
|
+
N2U2Y2E3YjgwZjllNzAzNDkwYTc4OGEyOGM3MTNlMWU0MTQ5YWI1MTk3OGI1
|
12
|
+
OTFlNTM3NWNlNjQyOTRiZGY4Njk1MDY1M2E5ZmY5NzkzNGM3ZGRiMDdmYzRk
|
13
|
+
NmFmOTMxNmMxYjE3ODczMjc1MzQwZTg0MjMyZjY5ODdjZDgyZGM=
|
14
|
+
data.tar.gz: !binary |-
|
15
|
+
YTEzZjg4MjliMWQwMWI3MDIyZDFmMDc5M2FkYjYzNDkyNmZkMWIxYmVlNDA5
|
16
|
+
OGM5MzRlMjBiMWM0ODdjZmFiYTZjOTFiYjY2M2RkNDY5NjEyMmVmYjZhZGQ4
|
17
|
+
ODczZDVmZGRhMjJlY2IxNzVmODE2ODIwNDk2MTNiYWM3YmJlODQ=
|
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p547
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Will Drew
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
dumblog-chef
|
2
|
+
============
|
3
|
+
|
4
|
+
Rudimentary Chef::Handler for go-dumblog to publish failed chef-client runs to AWS CloudWatch Logs.
|
5
|
+
|
6
|
+
Credit [Brian Bianco](https://github.com/brianbianco) for the [go-dumblog](https://github.com/brianbianco/go-dumblog) utility.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Ability to customize AWS CloudWatch Logs group, default: '/chef'
|
11
|
+
|
12
|
+
### Install `dumblog-chef` gem
|
13
|
+
|
14
|
+
```shell
|
15
|
+
gem install dumblog
|
16
|
+
```
|
17
|
+
|
18
|
+
### Add to client.rb
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
["dumblog-chef"].each do |lib|
|
22
|
+
begin
|
23
|
+
require lib
|
24
|
+
rescue LoadError
|
25
|
+
Chef::Log.warn "Failed to load #{lib}. This should be resolved after a chef run."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
exception_handlers << DumblogChef::Handler.new('/AWS/CLOUDWATCH/LOGS/GROUP')
|
30
|
+
```
|
31
|
+
|
32
|
+
## Disclaimer
|
33
|
+
|
34
|
+
It may work for your use-case out-of-the-box, but it's much more likely you'll need to fork it and customize it for your needs.
|
35
|
+
|
36
|
+
NOTE: This handler was built to solve a pressing issue in a legacy system utilizing Chef.
|
37
|
+
|
38
|
+
It assumes the use of IAM roles on AWS Instances with proper policies to publish logs to AWS CloudWatch Logs via [go-dumblog](https://github.com/brianbianco/go-dumblog). It makes assumptions and contains only minimal flexibility with the ability to customize the group for AWS CloudWatch Logs.
|
data/Rakefile.rb
ADDED
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
$:.push File.expand_path('../lib', __FILE__)
|
4
|
+
require File.expand_path('../lib/dumblog-chef/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'dumblog-chef'
|
8
|
+
gem.version = DumblogChef::VERSION
|
9
|
+
gem.platform = Gem::Platform::RUBY
|
10
|
+
gem.authors = ['Will Drew']
|
11
|
+
gem.email = ['willdrew@gmail.com']
|
12
|
+
gem.summary = %q{}
|
13
|
+
gem.description = %q{}
|
14
|
+
gem.homepage = 'https://github.com/willdrew/dumblog-chef'
|
15
|
+
|
16
|
+
gem.required_rubygems_version = '>= 1.3.6'
|
17
|
+
gem.required_ruby_version = ::Gem::Requirement.new('>= 1.9.3')
|
18
|
+
|
19
|
+
gem.add_dependency('chef', '>= 11.12.4')
|
20
|
+
gem.add_dependency('aws-sdk', '>= 1.38.0')
|
21
|
+
gem.add_development_dependency('rake', '~> 10.4')
|
22
|
+
gem.add_development_dependency('bundler', '~> 1.7')
|
23
|
+
gem.add_development_dependency('pry', '~> 0.10')
|
24
|
+
gem.add_development_dependency('mocha', '~> 1.1')
|
25
|
+
gem.add_development_dependency('shoulda-context', '~> 1.2')
|
26
|
+
|
27
|
+
gem.files = `git ls-files`.split($\)
|
28
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
29
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
30
|
+
|
31
|
+
gem.require_paths = %w(lib)
|
32
|
+
end
|
data/lib/dumblog-chef.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module DumblogChef
|
4
|
+
class Handler < Chef::Handler
|
5
|
+
attr_reader :group
|
6
|
+
|
7
|
+
def initialize(group='/chef')
|
8
|
+
@group = group
|
9
|
+
end
|
10
|
+
|
11
|
+
def report
|
12
|
+
if run_status.failed?
|
13
|
+
time = Time.now.utc
|
14
|
+
instance_id = `wget -qO- http://169.254.169.254/latest/meta-data/instance-id`
|
15
|
+
stream = "#{time.strftime("%Y/%m/%d")}/#{instance_id}"
|
16
|
+
|
17
|
+
message = {}
|
18
|
+
message[:subject] = "chef-client Run Failed"
|
19
|
+
message[:time] = time.iso8601
|
20
|
+
message[:node] = "Chef run failed on #{node.name}"
|
21
|
+
message[:instance_id] = instance_id
|
22
|
+
message[:exception] = run_status.formatted_exception
|
23
|
+
message[:backtrace] = Array(backtrace).join('\n')
|
24
|
+
|
25
|
+
file = Tempfile.new('dumblog-chef')
|
26
|
+
begin
|
27
|
+
file.write message.to_json
|
28
|
+
file.flush
|
29
|
+
`for i in {1..5}; do dumblog -group #{group} -stream #{stream} $(cat #{file.path}) && break || sleep 15; done`
|
30
|
+
ensure
|
31
|
+
file.close
|
32
|
+
file.unlink
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dumblog-chef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Drew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 11.12.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 11.12.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.38.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.38.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: shoulda-context
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.2'
|
111
|
+
description: ''
|
112
|
+
email:
|
113
|
+
- willdrew@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .ruby-version.example
|
119
|
+
- CHANGELOG.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile.rb
|
124
|
+
- dumblog-chef.gemspec
|
125
|
+
- lib/dumblog-chef.rb
|
126
|
+
- lib/dumblog-chef/handler.rb
|
127
|
+
- lib/dumblog-chef/version.rb
|
128
|
+
- test/test_helper.rb
|
129
|
+
homepage: https://github.com/willdrew/dumblog-chef
|
130
|
+
licenses: []
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.9.3
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.3.6
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.7.7
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: ''
|
152
|
+
test_files:
|
153
|
+
- test/test_helper.rb
|