Class: Hotdog::Sources::Datadog
- Inherits:
-
BaseSource
- Object
- BaseSource
- Hotdog::Sources::Datadog
- Defined in:
- lib/hotdog/sources/datadog.rb
Instance Attribute Summary
Attributes inherited from BaseSource
#application, #logger, #options
Instance Method Summary collapse
- #add_tags(host_name, tags, options = {}) ⇒ Object
- #api_key ⇒ Object
- #application_key ⇒ Object
- #cancel_downtime(id, options = {}) ⇒ Object
- #detach_tags(host_name, options = {}) ⇒ Object
- #endpoint ⇒ Object
- #get_all_downtimes(options = {}) ⇒ Object
- #get_all_tags(options = {}) ⇒ Object
- #get_host_tags(host_name, options = {}) ⇒ Object
- #id ⇒ Object
-
#initialize(application) ⇒ Datadog
constructor
A new instance of Datadog.
- #name ⇒ Object
- #schedule_downtime(scope, options = {}) ⇒ Object
- #update_tags(host_name, tags, options = {}) ⇒ Object
Constructor Details
#initialize(application) ⇒ Datadog
Returns a new instance of Datadog.
12 13 14 15 16 17 18 |
# File 'lib/hotdog/sources/datadog.rb', line 12 def initialize(application) super(application) [:endpoint] = ENV.fetch("DATADOG_HOST", "https://app.datadoghq.com") [:api_key] = ENV["DATADOG_API_KEY"] [:application_key] = ENV["DATADOG_APPLICATION_KEY"] @dog = nil # lazy initialization end |
Instance Method Details
#add_tags(host_name, tags, options = {}) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/hotdog/sources/datadog.rb', line 95 def (host_name, , ={}) code, resp = dog.(host_name, , ) if code.to_i / 100 != 2 raise("dog.add_tags(#{host_name.inspect}, #{.inspect}, #{.inspect}) returns [#{code.inspect}, #{resp.inspect}]") end resp end |
#api_key ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hotdog/sources/datadog.rb', line 32 def api_key() if [:api_key] [:api_key] else update_api_key! if [:api_key] [:api_key] else raise("DATADOG_API_KEY is not set") end end end |
#application_key ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hotdog/sources/datadog.rb', line 45 def application_key() if [:application_key] [:application_key] else update_application_key! if [:application_key] [:application_key] else raise("DATADOG_APPLICATION_KEY is not set") end end end |
#cancel_downtime(id, options = {}) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/hotdog/sources/datadog.rb', line 67 def cancel_downtime(id, ={}) code, cancel = dog.cancel_downtime(id) if code.to_i / 100 != 2 raise("dog.cancel_downtime(%s) returns [%s, %s]" % [id.inspect, code.inspect, cancel.inspect]) end cancel end |
#detach_tags(host_name, options = {}) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/hotdog/sources/datadog.rb', line 103 def (host_name, ={}) code, = dog.(host_name, ) if code.to_i / 100 != 2 raise("dog.detach_tags(#{host_name.inspect}, #{.inspect}) returns [#{code.inspect}, #{.inspect}]") end end |
#endpoint ⇒ Object
28 29 30 |
# File 'lib/hotdog/sources/datadog.rb', line 28 def endpoint() [:endpoint] end |
#get_all_downtimes(options = {}) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/hotdog/sources/datadog.rb', line 75 def get_all_downtimes(={}) now = Time.new.to_i Array(datadog_get("/api/v1/downtime")).select { |downtime| # active downtimes downtime["active"] and ( downtime["start"].nil? or downtime["start"] < now ) and ( downtime["end"].nil? or now <= downtime["end"] ) and downtime["monitor_id"].nil? } end |
#get_all_tags(options = {}) ⇒ Object
83 84 85 |
# File 'lib/hotdog/sources/datadog.rb', line 83 def (={}) Hash(datadog_get("/api/v1/tags/hosts")).fetch("tags", {}) end |
#get_host_tags(host_name, options = {}) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/hotdog/sources/datadog.rb', line 87 def (host_name, ={}) code, = dog.(host_name, ) if code.to_i / 100 != 2 raise("dog.host_tags(#{host_name.inspect}, #{.inspect}) returns [#{code.inspect}, #{.inspect}]") end end |
#id ⇒ Object
20 21 22 |
# File 'lib/hotdog/sources/datadog.rb', line 20 def id() Hotdog::SOURCE_DATADOG end |
#name ⇒ Object
24 25 26 |
# File 'lib/hotdog/sources/datadog.rb', line 24 def name() "datadog" end |
#schedule_downtime(scope, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/hotdog/sources/datadog.rb', line 58 def schedule_downtime(scope, ={}) code, schedule = dog.schedule_downtime(scope, :start => [:start].to_i, :end => ([:start]+[:downtime]).to_i) logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, [:start].to_i, ([:start]+[:downtime]).to_i, code.inspect, schedule.inspect]) if code.to_i / 100 != 2 raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect]) end schedule end |
#update_tags(host_name, tags, options = {}) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/hotdog/sources/datadog.rb', line 111 def (host_name, , ={}) code, = dog.(host_name, , ) if code.to_i / 100 != 2 raise("dog.update_tags(#{host_name.inspect}, #{.inspect}, #{.inspect}) returns [#{code.inspect}, #{.inspect}]") end end |