Class: Chef::GELF::Handler

Inherits:
Handler
  • Object
show all
Defined in:
lib/chef/gelf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



15
16
17
18
19
20
# File 'lib/chef/gelf.rb', line 15

def initialize(options = {})
  self.options = options
  
  Chef::Log.debug "Initialised GELF handler for gelf://#{self.options[:server]}:#{self.options[:port]}/#{self.options[:facility]}"
  @notifier = ::GELF::Notifier.new(self.options[:server], self.options[:port], 'WAN', :facility => self.options[:facility])
end

Instance Attribute Details

#notifierObject (readonly)

Returns the value of attribute notifier.



8
9
10
# File 'lib/chef/gelf.rb', line 8

def notifier
  @notifier
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/chef/gelf.rb', line 9

def options
  @options
end

Instance Method Details

#reportObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/gelf.rb', line 22

def report
  Chef::Log.debug "Reporting #{run_status.inspect}"
  if run_status.failed?
    Chef::Log.debug "Notifying Graylog server of failure."
    @notifier.notify!(:short_message => "Chef run failed on #{@notifier.host}. Updated #{changes[:count]} resources.",
                      :full_message => run_status.formatted_exception + "\n" + Array(backtrace).join("\n") + changes[:message],
                      :level => ::GELF::Levels::FATAL,
                      :host => host_name)
  else
    Chef::Log.debug "Notifying Graylog server of success."
    @notifier.notify!(:short_message => "Chef run completed on #{node.name} in #{elapsed_time}. Updated #{changes[:count]} resources.",
                      :full_message => changes[:message],
                      :level => ::GELF::Levels::INFO,
                      :host => host_name)
  end
end