From 9ef67851daa169a7f2b2608573e6c310cf4fe5e8 Mon Sep 17 00:00:00 2001 From: Ben Ford Date: Sat, 14 Jul 2012 16:38:43 -0700 Subject: [PATCH] Changed to ruby_gntp ruby-growl requires Ruby 1.9.2 now, which Puppet doesn't support. Also, added two notification types so the end user can enable/disable them at will. As a learning exercise, I want it to be noisier so users get immediate feedback, not only when it fails. --- lib/puppet/reports/growl.rb | 38 ++++++++++++++++++++++++++++++++----- test.rb | 17 ++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/lib/puppet/reports/growl.rb b/lib/puppet/reports/growl.rb index 9569bc3..60d1c21 100644 --- a/lib/puppet/reports/growl.rb +++ b/lib/puppet/reports/growl.rb @@ -2,9 +2,9 @@ require 'yaml' begin - require 'ruby-growl' + require 'ruby_gntp' rescue LoadError => e - Puppet.info "You need the `ruby-growl` gem to use the Growl report" + Puppet.info "You need the `ruby_gntp` gem to use the Growl report" end Puppet::Reports.register_report(:growl) do @@ -19,11 +19,39 @@ DESC def process + # Make sure that our report handler is registered with Growl + g = GNTP.new('Puppet Report Notifications', "#{GROWL_SERVER}") + g.register({ + :notifications => [{ + :name => 'Failed Puppet Run', + :enabled => true, + }, + { + :name => 'Puppet Run', + :enabled => true, + }] + }) + if self.status == 'failed' - Puppet.debug "Sending status for #{self.host} to Growl #{GROWL_SERVER}" - g = Growl.new("#{GROWL_SERVER}", "Puppet", ["Puppet Notification"], ["Puppet Notification"], nil) + Puppet.debug "Sending failed report for #{self.host} to Growl (#{GROWL_SERVER})" msg = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime}" - g.notify("Puppet Notification", "Puppet", msg, 1, true) + g.notify({ + :name => "Failed Puppet Run", + :title => "Failed Puppet Run", + :text => msg, + :sticky => true + }) + + else + Puppet.debug "Sending successful report for #{self.host} to Growl (#{GROWL_SERVER})" + msg = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime}" + g.notify({ + :name => "Puppet Run", + :title => "Puppet Run", + :text => msg, + :sticky => false + }) + end end end diff --git a/test.rb b/test.rb index c8e518e..eab65cc 100644 --- a/test.rb +++ b/test.rb @@ -1,5 +1,16 @@ require 'rubygems' -require 'ruby-growl' +require 'ruby_gntp' -g = Growl.new("71.193.201.169", "ruby-growl", ["ruby-growl Notification"], ["ruby-growl Notification"], nil) -g.notify("ruby-growl Notification", "It Came From Ruby-Growl", "Greetings!", 1, true) +# -- Standard way +growl = GNTP.new("Ruby/GNTP self test", '192.168.2.1') +growl.register({:notifications => [{ + :name => "notify", + :enabled => true, +}]}) + +growl.notify({ + :name => "notify", + :title => "Congratulations", + :text => "Congratulations! You have successfully installed ruby_gntp.", + :sticky=> true, +}) \ No newline at end of file