Class: Chef::Handler::Copperegg

Inherits:
Chef::Handler show all
Defined in:
lib/chef/handler/copperegg.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Copperegg

Returns a new instance of Copperegg.



9
10
11
12
13
14
15
16
17
# File 'lib/chef/handler/copperegg.rb', line 9

def initialize(opts = {})
  @opts = opts 
  @apikey = opts['apikey']
  @annotate_success = opts['annotate_success']
  @annotate_fail = opts['annotate_fail']
  @tags = opts['tags']
  @hostname = opts['hostname']
  @cuegg = CopperEgg::API.new(@apikey,'handler')
end

Instance Method Details

#reportObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/handler/copperegg.rb', line 19

def report
     
  elapsed = run_status.elapsed_time.to_i
  if elapsed < 60                                       # force duration to be >= 1 min for annotations to display
    annot_endtime = run_status.start_time.to_i + 60
  else
    annot_endtime = run_statusend_time.to_i
  end
  elapsed_str = elapsed.to_s + (elapsed <= 1 ? 'second' : 'seconds')

  if run_status.success? && @annotate_success 
    Chef::Log.info("CopperEgg Chef Handler: Chef Run Successful, host:  #{@hostname}")
    note = "Chef Run Completed in #{elapsed_str} on #{@hostname}. Updated #{run_status.updated_resources.length} of #{run_status.all_resources.length} Resources. Tags are #{@tags}"
    label =  'green'       

  elsif run_status.failed? && @annotate_fail
    Chef::Log.info("CopperEgg Chef Handler: Chef Run Failed, host:  #{@hostname}")
    note = "Chef Run FAILED in #{elapsed_str} on #{@hostname}; #{run_status.formatted_exception}.  Tags are #{@tags}"
    label =  'red'

  else
    Chef::Log.debug("CopperEgg Chef Handler: Unknown")
    return
  end

  params = {'note' => note,
            'starttime' => run_status.start_time.to_i,
            'endtime' => annot_endtime,
            'label' => label,
            'tags' => @tags  }
  @cuegg.create_annotation(@hostname, params)
  
end