Class: Chef::Handler::Graylog::GelfEventHandler

Inherits:
EventDispatch::Base
  • Object
show all
Defined in:
lib/chef/handler/graylog/gelf_event_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(sender) ⇒ GelfEventHandler

Returns a new instance of GelfEventHandler.



11
12
13
14
# File 'lib/chef/handler/graylog/gelf_event_handler.rb', line 11

def initialize(sender)
  @sender = sender
  @run_status = nil
end

Instance Method Details

#resource_updated(resource, action) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/handler/graylog/gelf_event_handler.rb', line 50

def resource_updated(resource, action)
  message = new_message(resource.node, 'resource_updated')

  message.message = "Resource updated: #{resource.resource_name}"

  message.add_field('resource_action', Array(resource.action).join(','))
  message.add_field('resource_identity', resource.identity)
  message.add_field('resource_name', resource.resource_name)
  message.add_field('resource_cookbook_name', resource.cookbook_name)
  message.add_field('resource_cookbook_version', resource.cookbook_version.version)
  message.add_field('resource_recipe_name', resource.recipe_name)
  message.add_field('resource_declared_type', resource.declared_type)
  message.add_field('resource_defined_at', resource.defined_at)
  message.add_field('resource_duration', resource.elapsed_time)

  @sender.send_payload(message)
rescue Object => e
  log_error(__method__.downcase, e)
end

#run_completed(node) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/handler/graylog/gelf_event_handler.rb', line 22

def run_completed(node)
  message = new_message(node, 'run_completed')

  message.message = "Chef run succeeded on node #{node.name}"

  add_common_run_status_fields(message)

  @sender.send_payload(message)
rescue Object => e
  log_error(__method__.downcase, e)
end

#run_failed(exception) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chef/handler/graylog/gelf_event_handler.rb', line 34

def run_failed(exception)
  message = new_message(@run_status.node, 'run_failed')

  message.message = "Chef run failed on node #{@run_status.node.name}"

  add_common_run_status_fields(message)

  message.add_field('error_message', exception.to_s)
  message.add_field('error_type', exception.class)
  message.add_field('error_backtrace', Array(@run_status.backtrace).join("\n"))

  @sender.send_payload(message)
rescue Object => e
  log_error(__method__.downcase, e)
end

#run_started(run_status) ⇒ Object



16
17
18
19
20
# File 'lib/chef/handler/graylog/gelf_event_handler.rb', line 16

def run_started(run_status)
  @run_status = run_status
rescue Object => e
  log_error(__method__.downcase, e)
end