chef-irc-snitch 0.1.0 → 0.2.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.org CHANGED
@@ -9,14 +9,12 @@
9
9
  Append the following to your Chef client configs, usually at =/etc/chef/client.rb=
10
10
 
11
11
  : # Notify admins via IRC when a Chef run fails
12
- : require 'chef-irc-snitch'
12
+ : require "chef-irc-snitch"
13
13
  :
14
14
  : irc_uri = "irc://nick:password@irc.domain.com:6667/#admins"
15
- : github_user = "foobar"
16
- : github_password = "secret"
17
15
  : enable_ssl = true
18
16
  :
19
- : irc_handler = IRCSnitch.new(irc_uri, github_user, github_password, enable_ssl)
17
+ : irc_handler = IRCSnitch.new(irc_uri, enable_ssl)
20
18
  : exception_handlers << irc_handler
21
19
 
22
20
  * License
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "chef-irc-snitch"
3
- s.version = "0.1.0"
3
+ s.version = "0.2.0.beta"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Sean Porter"]
6
6
  s.email = ["portertech@gmail.com"]
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.rubyforge_project = "chef-irc-snitch"
14
14
 
15
- s.add_dependency('carrier-pigeon')
15
+ s.add_dependency("carrier-pigeon")
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.require_paths = ["lib"]
@@ -2,69 +2,84 @@ require 'rubygems'
2
2
  require 'chef/handler'
3
3
  require 'uri'
4
4
  require 'json'
5
- require 'net/http'
5
+ require 'net/https'
6
6
  require 'carrier-pigeon'
7
7
 
8
8
  class IRCSnitch < Chef::Handler
9
9
 
10
- def initialize(irc_uri, github_user, github_password, ssl = false)
10
+ def initialize(irc_uri, ssl=false)
11
11
  @irc_uri = irc_uri
12
- @github_user = github_user
13
- @github_password = github_password
14
12
  @ssl = ssl
15
13
  @timestamp = Time.now.getutc
14
+ @gist_url = nil
16
15
  end
17
16
 
18
17
  def formatted_run_list
19
- node.run_list.map {|r| r.type == :role ? r.name : r.to_s }.join(', ')
18
+ node.run_list.map { |r| r.type == :role ? r.name : r.to_s }.join(', ')
20
19
  end
21
20
 
22
21
  def formatted_gist
23
- ([ "Node: #{node.name} (#{node.ipaddress})",
24
- "Run list: #{node.run_list}",
25
- "All roles: #{node.roles.join(', ')}",
26
- "",
27
- "#{run_status.formatted_exception}",
28
- ""
29
- ] + Array(backtrace)).join("\n")
22
+ info = [
23
+ "Node: #{node.name} (#{node.ipaddress})",
24
+ "Run list: #{node.run_list}",
25
+ "All roles: #{node.roles.join(', ')}"
26
+ ].join("\n")
27
+ backtrace = Array(backtrace).join("\n")
28
+ [info, run_status.formatted_exception, backtrace].join("\n")
30
29
  end
31
30
 
32
- def report
31
+ def create_gist
32
+ begin
33
+ timeout(10) do
34
+ uri = URI.parse("https://api.github.com/gists")
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ http.use_ssl = true
37
+ request = Net::HTTP::Post.new(uri.request_uri)
38
+ request.body = {
39
+ "description" => "Chef run failed on #{node.name} @ #{@timestamp}",
40
+ "public" => false,
41
+ "files" => {
42
+ "chef_exception.txt" => {
43
+ "content" => formatted_gist
44
+ }
45
+ }
46
+ }.to_json
47
+ response = http.request(request)
48
+ @gist_url = JSON.parse(response.body)["html_url"]
49
+ end
50
+ Chef::Log.info("Created a GitHub Gist @ #{@gist_url}")
51
+ rescue Timeout::Error
52
+ Chef::Log.error("Timed out while attempting to create a GitHub Gist")
53
+ rescue => error
54
+ Chef::Log.error("Unexpected error while attempting to create a GitHub Gist: #{error}")
55
+ end
56
+ end
57
+
58
+ def message_irc
59
+ message = "Chef failed on #{node.name} (#{formatted_run_list}): #{@gist_url}"
60
+ begin
61
+ timeout(10) do
62
+ CarrierPigeon.send(:uri => @irc_uri, :message => message, :ssl => @ssl)
63
+ end
64
+ Chef::Log.info("Informed chefs via IRC: #{message}")
65
+ rescue Timeout::Error
66
+ Chef::Log.error("Timed out while attempting to message chefs via IRC")
67
+ rescue => error
68
+ Chef::Log.error("Unexpected error while attempting to message chefs via IRC: #{error}")
69
+ end
70
+ end
33
71
 
72
+ def report
73
+ @timestamp = Time.now.getutc
34
74
  if STDOUT.tty?
35
75
  Chef::Log.error("Chef run failed @ #{@timestamp}")
36
- Chef::Log.error("#{run_status.formatted_exception}")
76
+ Chef::Log.error(run_status.formatted_exception)
37
77
  else
38
78
  Chef::Log.error("Chef run failed @ #{@timestamp}, snitchin' to chefs via IRC")
39
-
40
- gist_id = nil
41
- begin
42
- timeout(10) do
43
- response = Net::HTTP.post_form(URI.parse("http://gist.github.com/api/v1/json/new"), {
44
- "files[#{node.name}-#{@timestamp.to_i}]" => formatted_gist,
45
- "login" => @github_user,
46
- "password" => @github_password,
47
- "description" => "Chef run failed on #{node.name} @ #{@timestamp}",
48
- "public" => false
49
- })
50
- gist_id = JSON.parse(response.body)["gists"].first["repo"]
51
- Chef::Log.info("Created a GitHub Gist @ https://gist.github.com/#{gist_id}")
52
- end
53
- rescue Timeout::Error
54
- Chef::Log.error("Timed out while attempting to create a GitHub Gist")
55
- end
56
-
57
- message = "Chef failed on #{node.name} (#{formatted_run_list}): https://gist.github.com/#{gist_id}"
58
-
59
- begin
60
- timeout(10) do
61
- CarrierPigeon.send(:uri => @irc_uri, :message => message, :ssl => @ssl)
62
- Chef::Log.info("Informed chefs via IRC '#{message}'")
63
- end
64
- rescue Timeout::Error
65
- Chef::Log.error("Timed out while attempting to message Chefs via IRC")
79
+ create_gist
80
+ unless @gist_url.nil?
81
+ message_irc
66
82
  end
67
83
  end
68
84
  end
69
-
70
85
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-irc-snitch
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 31098193
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ - beta
11
+ version: 0.2.0.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - Sean Porter
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2012-05-04 00:00:00 -07:00
19
+ date: 2012-06-19 00:00:00 -07:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -70,12 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
71
  required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  none: false
72
73
  requirements:
73
- - - ">="
74
+ - - ">"
74
75
  - !ruby/object:Gem::Version
75
- hash: 3
76
+ hash: 25
76
77
  segments:
77
- - 0
78
- version: "0"
78
+ - 1
79
+ - 3
80
+ - 1
81
+ version: 1.3.1
79
82
  requirements: []
80
83
 
81
84
  rubyforge_project: chef-irc-snitch