chef-handler-zabbix 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2c4c5d7a2d1e780fafb0039b54bb6c8032d0caf
4
+ data.tar.gz: 81f5593e5266155a9b374ef6e7e64720646a4dd1
5
+ SHA512:
6
+ metadata.gz: 79aa5b8c81df198c5df564c003068a13d76fba5dbc76e867b2d0706ce4c028b17f5773f91b4861275511ccd60e2e0ef4ef21cb29cbbd58d3f49ac07a609e7e48
7
+ data.tar.gz: ff4a749e243fcadb9fd197b9c63197dbab96a09948fc227939ccf811fafb8bd93f3fdc029f2360c84b1b3a98648466cffaccf209e3e3f451fa8c682e72178bbc
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 zabbix 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-zabbix` gem during the compile phase
28
+ chef_gem "chef-handler-zabbix"
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_zabbix'
33
+
34
+ # Activate the handler immediately during compile phase
35
+ chef_handler "Chef::Handler::zabbix" do
36
+ source "chef/handler/chef_zabbix"
37
+ arguments [
38
+ :host => 'your_zabbix_host'
39
+ ]
40
+ action :nothing
41
+ end.run_action(:enable)
42
+
43
+
44
+ ### Method 2
45
+
46
+ Install the gem ahead of time, and configure Chef to use
47
+ them:
48
+
49
+ gem install chef-handler-zabbix
50
+
51
+ Then add to the configuration (`/etc/chef/solo.rb` for chef-solo or
52
+ `/etc/chef/client.rb` for chef-client):
53
+
54
+ require "chef/handler/chef_zabbix"
55
+ report_handlers << Chef::Handler::zabbix.new(:host => 'foo', :port => 'bar', :timeout => 15, :tags => ['chef-client'])
56
+ exception_handlers << Chef::Handler::zabbix.new(:host => 'foo', :port => 'bar', :timeout => 15, :tags => ['chef-client'])
57
+
58
+
59
+ License and Author
60
+ ==================
61
+
62
+ Licensed under the MIT license. See `MIT-LICENSE` file for details.
63
+
64
+ Author:: Nadir Lloret <https://github.com/nadirollo>
@@ -0,0 +1,46 @@
1
+ require "chef"
2
+ require "chef/handler"
3
+ require "socket"
4
+ require "timeout"
5
+
6
+ class Chef
7
+ class Handler
8
+ class Zabbix < Chef::Handler
9
+ attr_writer :host, :zabbix_conf_file
10
+
11
+ def initialize(options = {})
12
+ @zabbix_conf_file = options[:zabbix_conf_file]
13
+ end
14
+
15
+ def report
16
+ Chef::Log.info "Zabbix::Report handler started"
17
+
18
+ prefix = "custom.chef-client.last_run"
19
+ file = Tempfile.new('client-handler-zabbix-report')
20
+ host_name = node.fqdn
21
+
22
+ message = [
23
+ "#{@host_name} #{prefix}.success #{run_status.success? ? 1 : 0}",
24
+ "#{@host_name} #{prefix}.elapsed_time #{run_status.elapsed_time}",
25
+ "#{@host_name} #{prefix}.start_time #{run_status.start_time.to_i}",
26
+ "#{@host_name} #{prefix}.end_time #{run_status.end_time.to_i}",
27
+ "#{@host_name} #{prefix}.all_resources_num #{run_status.all_resources.length}",
28
+ "#{@host_name} #{prefix}.updated_resources_num #{run_status.updated_resources.length}",
29
+ ].join("\n")
30
+
31
+ file.write(message)
32
+ file.close()
33
+ cmd = ["zabbix_sender", "--config", @zabbix_conf_file, "--input-file", file.path]
34
+ Chef::Log.debug "Sending to zabbix: #{message}"
35
+ Chef::Log.debug "Command #{cmd.join(" ")}"
36
+ if RUBY_VERSION < "1.9"
37
+ out = IO.popen(cmd.join(" "))
38
+ else
39
+ out = IO.popen(cmd)
40
+ end
41
+ Chef::Log.debug "output #{out.readlines}"
42
+ out.close
43
+ end
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-handler-zabbix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - LostMyName
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-30 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 zabbix
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_zabbix.rb
37
+ homepage: https://github.com/lostmyname/chef-handler-zabbix
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.4.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Chef Zabbix Notifier
60
+ test_files: []