chef-handler-logdna 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 +4 -0
- data/CONTRIBUTORS.md +3 -0
- data/LICENSE +21 -0
- data/README.md +35 -0
- data/chef_handler_logdna.gemspec +29 -0
- data/lib/chef/handler/logdna.rb +64 -0
- metadata +234 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36a7c14f6a56f3fead89d5b76f032c95f035e6ed
|
4
|
+
data.tar.gz: 7a831e00bd55bb06bd709feb722826e008734e57
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b1aebc418cdcc0f7fd13af74a91a675e3d54f19a7091b6c210366d01a9acd0ecebe9bbcb41c653380996399657a7cf72861c4299a219b0765aba8710a38fed9
|
7
|
+
data.tar.gz: 29d028d9db50ac8f17e6c0b4d9981e5e8e705073782f4e349ff3bba06b5c835a7ec4ef81d333fc90ae17b6734f27e3e1b7c73f4eaf3b3a7051c979f63ed8da70
|
data/.gitignore
ADDED
data/CONTRIBUTORS.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 LogDNA, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# LogDNA Chef Handler
|
2
|
+
|
3
|
+
## Description
|
4
|
+
A Chef Handler that sends logs from each client run to LogDNA.
|
5
|
+
|
6
|
+
## Installation and Usage
|
7
|
+
|
8
|
+
* Using `chef-gem`: `chef_gem chef-handler-logdna`;
|
9
|
+
* **Recommended**: Create and run a recipe using [chef_handler cookbook by OpsCode](http://community.opscode.com/cookbooks/chef_handler):
|
10
|
+
```ruby
|
11
|
+
include_recipe "chef_handler"
|
12
|
+
|
13
|
+
# Install LogDNA Chef Handler:
|
14
|
+
chef_gem "chef-handler-logdna"
|
15
|
+
|
16
|
+
# Load the gem here:
|
17
|
+
require 'chef/handler/logdna'
|
18
|
+
|
19
|
+
# Activate the handler:
|
20
|
+
chef_handler "Chef::Handler::LogDNA" do
|
21
|
+
source "chef/handler/logdna"
|
22
|
+
action :nothing
|
23
|
+
arguments :logdna_key => "<LOGDNA_INGESTION_KEY>"
|
24
|
+
end.run_action(:enable)
|
25
|
+
```
|
26
|
+
* Or you can use this in your recipe by adding the following snippet of code to your recipe:
|
27
|
+
```ruby
|
28
|
+
chef_handler "Chef::Handler::LogDNA" do
|
29
|
+
source "<PATH TO LOGDNA CHEF HANDLER>"
|
30
|
+
action :nothing
|
31
|
+
arguments :logdna_key => "<LOGDNA_INGESTION_KEY>"
|
32
|
+
end.run_action(:enable)
|
33
|
+
```
|
34
|
+
|
35
|
+
## Happy Logging!
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = 'chef-handler-logdna'
|
4
|
+
gem.summary = 'Chef Handler streams logs to LogDNA'
|
5
|
+
gem.description = 'This Handler will collect logs from a chef-client run to LogDNA.'
|
6
|
+
gem.version = '0.0.1'
|
7
|
+
|
8
|
+
gem.files = `git ls-files`.split($\) # rubocop:disable SpecialGlobalVars
|
9
|
+
gem.require_paths = ['lib']
|
10
|
+
gem.extra_rdoc_files = ['README.md', 'LICENSE', 'CONTRIBUTORS.md']
|
11
|
+
|
12
|
+
gem.add_development_dependency 'logdna'
|
13
|
+
gem.add_development_dependency 'appraisal'
|
14
|
+
gem.add_development_dependency 'bundler'
|
15
|
+
gem.add_development_dependency 'chef', '>= 10.14'
|
16
|
+
gem.add_development_dependency 'dotenv'
|
17
|
+
gem.add_development_dependency 'rake'
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'rubocop'
|
20
|
+
gem.add_development_dependency 'simplecov'
|
21
|
+
gem.add_development_dependency 'vcr'
|
22
|
+
gem.add_development_dependency 'webmock'
|
23
|
+
gem.add_development_dependency 'systemu'
|
24
|
+
gem.add_development_dependency 'macaddr'
|
25
|
+
|
26
|
+
gem.authors = ['Samir Musali']
|
27
|
+
gem.email = ['samir.musali@logdna.com']
|
28
|
+
gem.homepage = 'https://www.github.com/logdna/chef'
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'chef/handler'
|
3
|
+
require 'chef/mash'
|
4
|
+
require 'logdna'
|
5
|
+
require 'macaddr'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
class Handler
|
10
|
+
class LogDNA < Chef::Handler
|
11
|
+
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def initialize(config={})
|
15
|
+
@config = Mash.new(config)
|
16
|
+
@ldna = prepare_logdna
|
17
|
+
end
|
18
|
+
|
19
|
+
def report
|
20
|
+
if run_status.success?
|
21
|
+
status = "SUCCESS"
|
22
|
+
else
|
23
|
+
status = "FAILURE"
|
24
|
+
end
|
25
|
+
line = run_status
|
26
|
+
sendLog status line
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_hostname
|
30
|
+
node = run_status.node
|
31
|
+
use_ec2_instance_id = !config.key?(:use_ec2_instance_id) || (config.key?(:use_ec2_instance_id) && config[:use_ec2_instance_id])
|
32
|
+
if config[:hostname]
|
33
|
+
config[:hostname]
|
34
|
+
elsif use_ec2_instance_id && node.attribute?('ec2') && node.ec2.attribute?('instance_id')
|
35
|
+
node.ec2.instance_id
|
36
|
+
else
|
37
|
+
node.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def prepare_logdna
|
42
|
+
options = {:hostname => get_hostname, :index_meta => true, :mac => Mac.addr}
|
43
|
+
logdna_key = config[:logdna_key]
|
44
|
+
if !config.key?(:logdna_key)
|
45
|
+
Chef::Log.warn("You need LogDNA Ingestion Key in order to stream logs")
|
46
|
+
fail ArgumentError, 'Missing LogDNA Ingestion Key'
|
47
|
+
return false
|
48
|
+
else
|
49
|
+
Logdna::Ruby.new(config[:logdna_key], options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def sendLog(status, line)
|
54
|
+
unless @ldna.nil?
|
55
|
+
@ldna.log(line, {:app => "chef", :level => status})
|
56
|
+
else
|
57
|
+
Chef::Log.warn("LogDNA Handler has not been set properly")
|
58
|
+
end
|
59
|
+
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
|
60
|
+
Chef::Log.error("Connection error:\n"+e)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-handler-logdna
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samir Musali
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logdna
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chef
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: systemu
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: macaddr
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: This Handler will collect logs from a chef-client run to LogDNA.
|
196
|
+
email:
|
197
|
+
- samir.musali@logdna.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files:
|
201
|
+
- README.md
|
202
|
+
- LICENSE
|
203
|
+
- CONTRIBUTORS.md
|
204
|
+
files:
|
205
|
+
- ".gitignore"
|
206
|
+
- CONTRIBUTORS.md
|
207
|
+
- LICENSE
|
208
|
+
- README.md
|
209
|
+
- chef_handler_logdna.gemspec
|
210
|
+
- lib/chef/handler/logdna.rb
|
211
|
+
homepage: https://www.github.com/logdna/chef
|
212
|
+
licenses: []
|
213
|
+
metadata: {}
|
214
|
+
post_install_message:
|
215
|
+
rdoc_options: []
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
requirements: []
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 2.5.2
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: Chef Handler streams logs to LogDNA
|
234
|
+
test_files: []
|