Class: DatadogChefEvents
- Inherits:
-
Object
- Object
- DatadogChefEvents
- Includes:
- DatadogUtil
- Defined in:
- lib/chef/handler/datadog_chef_events.rb
Overview
helper class for sending events about chef runs
Instance Attribute Summary collapse
-
#event_body ⇒ Object
readonly
Returns the value of attribute event_body.
-
#event_title ⇒ Object
readonly
Returns the value of attribute event_title.
Instance Method Summary collapse
-
#emit_to_datadog(dog) ⇒ Object
Emit Chef event to Datadog.
-
#initialize ⇒ DatadogChefEvents
constructor
A new instance of DatadogChefEvents.
-
#with_failure_notifications(failure_notifications) ⇒ DatadogChefTags
set the failure notification list.
-
#with_hostname(hostname) ⇒ DatadogChefTags
set the target hostname (chef node name).
-
#with_run_status(run_status) ⇒ DatadogChefTags
set the chef run status used for the report.
-
#with_tags(tags) ⇒ DatadogChefTags
set the datadog host tags associated with the event.
Constructor Details
#initialize ⇒ DatadogChefEvents
Returns a new instance of DatadogChefEvents.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 16 def initialize @hostname = nil @run_status = nil @failure_notfications = nil @alert_type = '' @event_priority = '' @event_title = '' # TODO: refactor how event_body is constructed in the class methods # handling of the event_body is a bit clunky and depends on the order of # method calls @event_body = '' end |
Instance Attribute Details
#event_body ⇒ Object (readonly)
Returns the value of attribute event_body.
14 15 16 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 14 def event_body @event_body end |
#event_title ⇒ Object (readonly)
Returns the value of attribute event_title.
13 14 15 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 13 def event_title @event_title end |
Instance Method Details
#emit_to_datadog(dog) ⇒ Object
Emit Chef event to Datadog
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 69 def emit_to_datadog(dog) @event_body = '' build_event_data begin evt = dog.emit_event(Dogapi::Event.new(@event_body, msg_title: @event_title, event_type: 'config_management.run', event_object: @hostname, alert_type: @alert_type, priority: @event_priority, source_type_name: 'chef', tags: @tags ), host: @hostname) # FIXME: nice-to-have: abstract format of return value away a bit # in dogapi directly. See https://github.com/DataDog/dogapi-rb/issues/18 if evt.length < 2 Chef::Log.warn("Unexpected response from Datadog Event API: #{evt}") else # [http_response_code, {"event" => {"url" => "...", ...}}] # 2xx means ok if evt[0].to_i / 100 != 2 Chef::Log.warn("Could not submit event to Datadog (HTTP call failed): #{evt[0]}") else Chef::Log.debug("Successfully submitted Chef event to Datadog for #{@hostname} at #{evt[1]['event']['url']}") end end rescue StandardError => e Chef::Log.warn("Could not determine whether Chef event was successfully submitted to Datadog: #{evt}. Error:\n#{e}") end end |
#with_failure_notifications(failure_notifications) ⇒ DatadogChefTags
set the failure notification list
52 53 54 55 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 52 def with_failure_notifications(failure_notifications) @failure_notifications = failure_notifications self end |
#with_hostname(hostname) ⇒ DatadogChefTags
set the target hostname (chef node name)
34 35 36 37 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 34 def with_hostname(hostname) @hostname = hostname self end |
#with_run_status(run_status) ⇒ DatadogChefTags
set the chef run status used for the report
43 44 45 46 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 43 def with_run_status(run_status) @run_status = run_status self end |
#with_tags(tags) ⇒ DatadogChefTags
set the datadog host tags associated with the event
61 62 63 64 |
# File 'lib/chef/handler/datadog_chef_events.rb', line 61 def () @tags = self end |