Class: Chef::Handler::LogDNA
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- Chef::Handler::LogDNA
- Defined in:
- lib/chef/handler/logdna.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #get_hostname ⇒ Object
-
#initialize(config = {}) ⇒ LogDNA
constructor
A new instance of LogDNA.
- #prepare_logdna ⇒ Object
- #report ⇒ Object
- #sendLog(status, line) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ LogDNA
Returns a new instance of LogDNA.
14 15 16 17 |
# File 'lib/chef/handler/logdna.rb', line 14 def initialize(config={}) @config = Mash.new(config) @ldna = prepare_logdna end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/chef/handler/logdna.rb', line 12 def config @config end |
Instance Method Details
#get_hostname ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chef/handler/logdna.rb', line 29 def get_hostname node = run_status.node use_ec2_instance_id = !config.key?(:use_ec2_instance_id) || (config.key?(:use_ec2_instance_id) && config[:use_ec2_instance_id]) if config[:hostname] config[:hostname] elsif use_ec2_instance_id && node.attribute?('ec2') && node.ec2.attribute?('instance_id') node.ec2.instance_id else node.name end end |
#prepare_logdna ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chef/handler/logdna.rb', line 41 def prepare_logdna = {:hostname => get_hostname, :index_meta => true, :mac => Mac.addr} logdna_key = config[:logdna_key] if !config.key?(:logdna_key) Chef::Log.warn("You need LogDNA Ingestion Key in order to stream logs") fail ArgumentError, 'Missing LogDNA Ingestion Key' return false else Logdna::Ruby.new(config[:logdna_key], ) end end |
#report ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/chef/handler/logdna.rb', line 19 def report if run_status.success? status = "SUCCESS" else status = "FAILURE" end line = run_status sendLog status line end |
#sendLog(status, line) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/handler/logdna.rb', line 53 def sendLog(status, line) unless @ldna.nil? @ldna.log(line, {:app => "chef", :level => status}) else Chef::Log.warn("LogDNA Handler has not been set properly") end rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e Chef::Log.error("Connection error:\n"+e) end |