Class: DumblogChef::Handler
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- DumblogChef::Handler
- Defined in:
- lib/dumblog-chef/handler.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(group = '/chef', stream = nil, region = nil) ⇒ Handler
constructor
A new instance of Handler.
- #report ⇒ Object
Constructor Details
#initialize(group = '/chef', stream = nil, region = nil) ⇒ Handler
Returns a new instance of Handler.
8 9 10 11 12 13 14 15 |
# File 'lib/dumblog-chef/handler.rb', line 8 def initialize(group='/chef', stream=nil, region=nil) @time = Time.now.utc @instance_id = `wget -qO- http://169.254.169.254/latest/meta-data/instance-id` @group = group @stream = [nil, ''].include?(stream) ? "#{time.strftime("%Y/%m/%d")}/#{instance_id}" : stream @region = [nil, ''].include?(region) ? 'us-west-2' : region end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
6 7 8 |
# File 'lib/dumblog-chef/handler.rb', line 6 def group @group end |
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
5 6 7 |
# File 'lib/dumblog-chef/handler.rb', line 5 def instance_id @instance_id end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
6 7 8 |
# File 'lib/dumblog-chef/handler.rb', line 6 def region @region end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
6 7 8 |
# File 'lib/dumblog-chef/handler.rb', line 6 def stream @stream end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/dumblog-chef/handler.rb', line 5 def time @time end |
Instance Method Details
#report ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dumblog-chef/handler.rb', line 17 def report if run_status.failed? = {} [:subject] = "chef-client Run Failed" [:time] = time.iso8601 [:node] = "Chef run failed on #{node.name}" [:instance_id] = instance_id [:exception] = run_status.formatted_exception [:backtrace] = Array(backtrace).join('\n') file = Tempfile.new('dumblog-chef') begin file.write .to_json file.flush `for i in {1..5}; do dumblog -group #{group} -stream #{stream} -region #{region} $(cat #{file.path}) && break || sleep 15; done` ensure file.close file.unlink end end end |