class HipChat::NotifyRoom

Public Class Methods

new(api_token, room_name, options={}, msg_options={}, notify_users=false, report_success=false, excluded_envs=[], msg_prefix='') click to toggle source
# File lib/hipchat/chef.rb, line 18
def initialize(api_token, room_name, options={}, msg_options={}, notify_users=false, report_success=false, excluded_envs=[], msg_prefix='')
  @api_token = api_token
  @room_name = room_name
  @options = options
  @report_success = report_success
  @msg_options = msg_options
  @msg_options[:notify] = notify_users 
  @excluded_envs = excluded_envs
end

Public Instance Methods

report() click to toggle source
# File lib/hipchat/chef.rb, line 28
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? && @report_success
            "Chef run on \"#{node.name}\" completed in #{run_status.elapsed_time.round(2)} seconds"
          else nil
          end

    @msg_options[:color]= if run_status.success? then 'green'
            else 'red'
            end

    if msg
      client = HipChat::Client.new(@api_token, @options)
      client[@room_name].send('Chef', [msg_prefix, msg].join(' '), @msg_options)
    end
  end
end