chef-jabber-paste-snitch 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in chef-jabber-snitch.gemspec
4
+ gemspec
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alice Kaerast
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.org ADDED
@@ -0,0 +1,26 @@
1
+ * Install
2
+
3
+ : gem install chef-jabber-snitch
4
+
5
+ * Usage
6
+
7
+ ** Configure Chef to Use The Handler
8
+
9
+ Append the following to your Chef client configs, usually at =/etc/chef/client.rb=
10
+
11
+ : # Notify admins via IRC when a Chef run fails
12
+ : require 'chef-jabber-snitch'
13
+ :
14
+ : jabber_user = "alice@gmail.com"
15
+ : jabber_password = "password"
16
+ : jabber_server = "talk.google.com"
17
+ : jabber_to = "bob@gmail.com"
18
+ : github_user = "foobar"
19
+ : github_token = "asKkwqofovX3shBmtMf8EWhDzSr7ouUb"
20
+ :
21
+ : jabber_handler = JabberSnitch.new(jabber_user, jabber_password, jabber_to, github_user, github_token, jabber_server)
22
+ : exception_handlers << jabber_handler
23
+
24
+ * License
25
+
26
+ Chef-Jabber-Snitch is released under the [[https://github.com/kaerast/chef-jabber-snitch/blob/master/MIT-LICENSE.txt][MIT license]].
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "chef-jabber-paste-snitch"
3
+ s.version = "1.0.1"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ["Kendrick Martin"]
6
+ s.email = ["kendrick.martin@webtrends.com"]
7
+ s.homepage = "https://github.com/kendrickm/chef-jabber-snitch"
8
+ s.summary = %q{An exception handler for OpsCode Chef runs (Pastebin & Jabber)}
9
+ s.description = %q{An exception handler for OpsCode Chef runs (Pastebin & Jabber)}
10
+ s.has_rdoc = false
11
+ s.license = "MIT"
12
+
13
+ s.add_dependency('chef')
14
+ s.add_dependency('xmpp4r')
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ require 'chef'
3
+ require 'chef/handler'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'xmpp4r/client'
8
+ require 'xmpp4r'
9
+ require 'xmpp4r/muc'
10
+ require 'xmpp4r/roster'
11
+
12
+ class ChefJabberPasteSnitch < Chef::Handler
13
+
14
+ def initialize(jabber_user, jabber_password, jabber_room, pastebin_server, jabber_server = 'talk.google.com', pastebin_expire = 74880, jabber_port = 5222)
15
+ @jabber_user = jabber_user
16
+ @jabber_password = jabber_password
17
+ @jabber_server = jabber_server
18
+ @jabber_room = jabber_room
19
+ @pastebin_server = pastebin_server
20
+ @pastebin_expire = pastebin_expire
21
+ @jabber_port = jabber_port
22
+ @timestamp = Time.now.getutc
23
+ end
24
+
25
+ def fmt_run_list
26
+ node.run_list.map {|r| r.type == :role ? r.name : r.to_s }.join(', ')
27
+ end
28
+
29
+ def fmt_output
30
+ message = "Node: #{node.name} (#{node.ipaddress})\n"
31
+ message << "Run list: #{node.run_list}\n"
32
+ message << "All roles: #{node.roles.join(', ')}\n"
33
+ message << "\n"
34
+ message << "#{run_status.formatted_exception}\n"
35
+ message << Array(backtrace).join("\n")
36
+ return message
37
+ end
38
+
39
+ def report
40
+ Chef::Log.debug("Starting jabber handling")
41
+ if STDOUT.tty?
42
+ Chef::Log.error("Chef run failed @ #{@timestamp}")
43
+ Chef::Log.error("#{run_status.formatted_exception}")
44
+ else
45
+ Chef::Log.error("Chef run failed @ #{@timestamp}, snitchin' to chefs via Jabber")
46
+ end
47
+ res = nil
48
+ begin
49
+ timeout(10) do
50
+ res = Net::HTTP.post_form(URI.parse(@pastebin_server), {"expire" => @pastebin_expire, "text" => fmt_output, "name" => node.name, "title" => "Failed Chef run #{@timestamp}"})
51
+ Chef::Log.info("Created output #{res.body}")
52
+ end
53
+ rescue Timeout::Error
54
+ Chef::Log.error("Timed out while attempting to post to pastebin server #{pastebin_server}")
55
+ end
56
+
57
+ message = "Chef failed on #{node.name} Run List - (#{fmt_run_list}) #{res.body}"
58
+
59
+ begin
60
+ Chef::Log.debug("It's jabber time")
61
+ timeout(10) do
62
+
63
+ chef_jid = Jabber::JID::new(@jabber_user)
64
+ chef_client = Jabber::Client::new(chef_jid)
65
+ chef_client.connect(@jabber_server,@jabber_port)
66
+ chef_client.auth(@jabber_password)
67
+
68
+ muc = Jabber::MUC::MUCClient.new(chef_client)
69
+ muc.join(Jabber::JID::new("#{@jabber_room}/" + chef_client.jid.node))
70
+
71
+ m = Jabber::Message::new(@jabber_room, message)
72
+ muc.send m
73
+ Chef::Log.info("Informed chefs via Jabber '#{message}'")
74
+ end
75
+ rescue Timeout::Error
76
+ Chef::Log.error("Timed out while attempting to message Chefs via Jabber")
77
+ end
78
+ end
79
+
80
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-jabber-paste-snitch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kendrick Martin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: xmpp4r
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: An exception handler for OpsCode Chef runs (Pastebin & Jabber)
47
+ email:
48
+ - kendrick.martin@webtrends.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - MIT-LICENSE.txt
56
+ - README.org
57
+ - Rakefile
58
+ - chef-jabber-snitch.gemspec
59
+ - lib/chef-jabber-paste-snitch.rb
60
+ homepage: https://github.com/kendrickm/chef-jabber-snitch
61
+ licenses:
62
+ - MIT
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.25
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: An exception handler for OpsCode Chef runs (Pastebin & Jabber)
85
+ test_files: []