chef-handler-logstash 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/MIT-LICENSE +22 -0
- data/README.md +64 -0
- data/lib/chef/handler/chef_logstash.rb +85 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f79b874cd24605235c8a9245770df64467ca11f
|
4
|
+
data.tar.gz: 7af14eea0760d0234dd9261ec79be232f7bf359a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 186816d7d8356f8222d216b16438fc9d98e49c76cdc967f573ba0a7c3c31ca56df78994c3629e4d9e9973b88405d2292f6437694e6da93105eeac95c70648b99
|
7
|
+
data.tar.gz: a03fc1e943e0369120fa177ce1abc265d24b95d07917dc79f32461c6ab0900ac901769390745ea4903405a370d5d58117c78960b4f4c92cf3bcace2d27e8ea99
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Lostmy.name Ltd.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
6
|
+
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 included
|
14
|
+
in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
17
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Description
|
2
|
+
===========
|
3
|
+
|
4
|
+
This is a Chef report handler that exports a report in json format to the configured server/port
|
5
|
+
We are using it to report to logstash but probably you can hook it into anything that accepts a json :)
|
6
|
+
|
7
|
+
* http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
|
8
|
+
|
9
|
+
Requirements
|
10
|
+
============
|
11
|
+
|
12
|
+
Only works on Chef >= 10.14
|
13
|
+
|
14
|
+
Usage
|
15
|
+
=====
|
16
|
+
|
17
|
+
There are two ways to use Chef Handlers.
|
18
|
+
|
19
|
+
### Method 1 (recommended)
|
20
|
+
|
21
|
+
Use the
|
22
|
+
[chef_handler cookbook by Opscode](http://community.opscode.com/cookbooks/chef_handler).
|
23
|
+
Create a recipe with the following:
|
24
|
+
|
25
|
+
include_recipe "chef_handler"
|
26
|
+
|
27
|
+
# Install `chef-handler-logstash` gem during the compile phase
|
28
|
+
chef_gem "chef-handler-logstash"
|
29
|
+
|
30
|
+
# load the gem here so it gets added to the $LOAD_PATH, otherwise chef_handler
|
31
|
+
# will fail.
|
32
|
+
require 'chef/handler/chef_profiler'
|
33
|
+
|
34
|
+
# Activate the handler immediately during compile phase
|
35
|
+
chef_handler "Chef::Handler::Profiler" do
|
36
|
+
source "chef/handler/chef_profiler"
|
37
|
+
action :nothing
|
38
|
+
end.run_action(:enable)
|
39
|
+
|
40
|
+
|
41
|
+
### Method 2
|
42
|
+
|
43
|
+
Install the gem ahead of time, and configure Chef to use
|
44
|
+
them:
|
45
|
+
|
46
|
+
gem install chef-handler-logstash
|
47
|
+
|
48
|
+
Then add to the configuration (`/etc/chef/solo.rb` for chef-solo or
|
49
|
+
`/etc/chef/client.rb` for chef-client):
|
50
|
+
|
51
|
+
require "chef/handler/chef_profiler"
|
52
|
+
report_handlers << Chef::Handler::Profiler.new
|
53
|
+
exception_handlers << Chef::Handler::Profiler.new
|
54
|
+
|
55
|
+
|
56
|
+
### Example output
|
57
|
+
|
58
|
+
|
59
|
+
License and Author
|
60
|
+
==================
|
61
|
+
|
62
|
+
Licensed under the MIT license. See `LICENSE` file for details.
|
63
|
+
|
64
|
+
Author:: Nadir Lloret <https://github.com/nadirollo>
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "chef"
|
2
|
+
require "chef/handler"
|
3
|
+
require "socket"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Handler
|
8
|
+
class Logstash < Chef::Handler
|
9
|
+
attr_writer :tags, :host, :port, :timeout
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
options[:tags] ||= Array.new
|
13
|
+
options[:timeout] ||= 15
|
14
|
+
@tags = options[:tags]
|
15
|
+
@timeout = options[:timeout]
|
16
|
+
@host = options[:host]
|
17
|
+
@port = options[:port]
|
18
|
+
end
|
19
|
+
|
20
|
+
def report
|
21
|
+
# A logstash json_event looks like this:
|
22
|
+
# {
|
23
|
+
# "@source":"typicall determined by logstash input def",
|
24
|
+
# "@type":"determined by logstash input def",
|
25
|
+
# "@tags":[],
|
26
|
+
# "@fields":{},
|
27
|
+
# "@timestamp":"ISO8601 of report seen by logstash",
|
28
|
+
# "@source_host":"host.foo.com",
|
29
|
+
# "@source_path":"typically the name of the log file",
|
30
|
+
# "@message":"escaped representation of report"
|
31
|
+
# }
|
32
|
+
#
|
33
|
+
# When sending an report in native `json_event` format
|
34
|
+
# - You are required to set everything EXCEPT @type and @timestamp
|
35
|
+
# - @type CAN be overridden
|
36
|
+
# - @timestamp will be ignored
|
37
|
+
@updated_resources = []
|
38
|
+
@updated_resources_count = 0
|
39
|
+
if run_status.updated_resources
|
40
|
+
run_status.updated_resources.each do |r|
|
41
|
+
@updated_resources << r.to_s
|
42
|
+
@updated_resources_count += 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
report = Hash.new
|
46
|
+
report["@source"] = "chef://#{run_status.node.name}/handler/logstash"
|
47
|
+
report["@source_path"] = "#{__FILE__}"
|
48
|
+
report["@source_host"] = run_status.node.name
|
49
|
+
report["@tags"] = @tags
|
50
|
+
report["@fields"] = Hash.new
|
51
|
+
report["@fields"]["environment"] = run_status.node.chef_environment
|
52
|
+
report["@fields"]["run_list"] = run_status.node.run_list
|
53
|
+
report["@fields"]["updated_resources"] = @updated_resources
|
54
|
+
report["@fields"]["updated_resources_count"] = @updated_resources_count
|
55
|
+
report["@fields"]["elapsed_time"] = run_status.elapsed_time
|
56
|
+
report["@fields"]["success"] = run_status.success?
|
57
|
+
# (TODO) Convert to ISO8601
|
58
|
+
report["@fields"]["start_time"] = run_status.start_time.to_time.iso8601
|
59
|
+
report["@fields"]["end_time"] = run_status.end_time.to_time.iso8601
|
60
|
+
if run_status.backtrace
|
61
|
+
report["@fields"]["backtrace"] = run_status.backtrace.join("\n")
|
62
|
+
else
|
63
|
+
report["@fields"]["backtrace"] = ""
|
64
|
+
end
|
65
|
+
if run_status.exception
|
66
|
+
report["@fields"]["exception"] = run_status.exception
|
67
|
+
else
|
68
|
+
report["@fields"]["exception"] = ""
|
69
|
+
end
|
70
|
+
report["@message"] = run_status.exception || "Chef client run completed in #{run_status.elapsed_time}"
|
71
|
+
|
72
|
+
begin
|
73
|
+
Timeout::timeout(@timeout) do
|
74
|
+
json = report.to_json
|
75
|
+
ls = TCPSocket.new "#{@host}" , @port
|
76
|
+
ls.puts json
|
77
|
+
ls.close
|
78
|
+
end
|
79
|
+
rescue Exception => e
|
80
|
+
Chef::Log.info("Failed to write to #{@host} on port #{@port}: #{e.message}")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-handler-logstash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- LostMyName
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-11 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: '10.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>'
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.14'
|
27
|
+
description: Send report to logstash port listening for json_events
|
28
|
+
email:
|
29
|
+
- nadir@lostmy.name
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/chef/handler/chef_logstash.rb
|
37
|
+
homepage: https://github.com/lostmyname/chef-handler-logstash
|
38
|
+
licenses: []
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.14
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Chef Profiler Logstash
|
60
|
+
test_files: []
|