Skip to content

Commit

Permalink
Merge pull request #1 from binford2k/master
Browse files Browse the repository at this point in the history
Changed to ruby_gntp
  • Loading branch information
jamtur01 committed Jul 15, 2012
2 parents 442cda0 + 9ef6785 commit 309100e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
38 changes: 33 additions & 5 deletions lib/puppet/reports/growl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 14 additions & 3 deletions test.rb
Original file line number Diff line number Diff line change
@@ -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,
})

0 comments on commit 309100e

Please sign in to comment.