Class: HipChat::NotifyRoom
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- HipChat::NotifyRoom
- Defined in:
- lib/hipchat/chef.rb
Instance Method Summary collapse
-
#initialize(api_token, room_name, options = {}) ⇒ NotifyRoom
constructor
A new instance of NotifyRoom.
- #report ⇒ Object
Constructor Details
#initialize(api_token, room_name, options = {}) ⇒ NotifyRoom
Returns a new instance of NotifyRoom.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hipchat/chef.rb', line 18 def initialize(api_token, room_name, ={}) defaults = { hipchat_options: {}, msg_options: {}, excluded_envs: [], msg_prefix: ''} = defaults.merge() @api_token = api_token @room_name = room_name = [:hipchat_options] = [:msg_options] @msg_prefix = [:msg_prefix] @excluded_envs = [:excluded_envs] end |
Instance Method Details
#report ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hipchat/chef.rb', line 29 def report unless @excluded_envs.include?(node.chef_environment) msg = if run_status.failed? then "Failure on \"#{node.name}\" (\"#{node.chef_environment}\" env): #{run_status.formatted_exception}" elsif run_status.success? && [:notify] "Chef run on \"#{node.name}\" completed in #{run_status.elapsed_time.round(2)} seconds" else nil end [:color]= if run_status.success? then 'green' else 'red' end if msg client = HipChat::Client.new(@api_token, ) client[@room_name].send('Chef', [@msg_prefix, msg].join(' '), ) end end end |