class DogapiDemo::Client

A simple DogAPI client

See DogapiDemo::V1 for the thick underlying clients

Class methods return a tuple of (response_code, response_body). Unless otherwise noted, the response body is deserialized JSON. Up-to-date information about the JSON object structure is available in the HTTP API documentation, here.

Public Class Methods

new(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil) click to toggle source

Create a new Client optionally specifying a default host and device

   # File lib/dogapi-demo/facade.rb
14 def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil)
15 
16   if api_key
17     @api_key = api_key
18   else
19     raise 'Please provide an API key to submit your data'
20   end
21 
22   @application_key = application_key
23 
24   @datadog_host = DogapiDemo.find_datadog_host()
25 
26   @host = host ||= DogapiDemo.find_localhost()
27 
28   @device = device
29 
30   # FIXME: refactor to avoid all this code duplication
31   @metric_svc = DogapiDemo::V1::MetricService.new(@api_key, @application_key, silent, timeout)
32   @event_svc = DogapiDemo::V1::EventService.new(@api_key, @application_key, silent, timeout)
33   @tag_svc = DogapiDemo::V1::TagService.new(@api_key, @application_key, silent, timeout)
34   @comment_svc = DogapiDemo::V1::CommentService.new(@api_key, @application_key, silent, timeout)
35   @search_svc = DogapiDemo::V1::SearchService.new(@api_key, @application_key, silent, timeout)
36   @dash_service = DogapiDemo::V1::DashService.new(@api_key, @application_key, silent, timeout)
37   @alert_svc = DogapiDemo::V1::AlertService.new(@api_key, @application_key, silent, timeout)
38   @user_svc = DogapiDemo::V1::UserService.new(@api_key, @application_key, silent, timeout)
39   @snapshot_svc = DogapiDemo::V1::SnapshotService.new(@api_key, @application_key, silent, timeout)
40   @embed_svc = DogapiDemo::V1::EmbedService.new(@api_key, @application_key, silent, timeout)
41   @screenboard_svc = DogapiDemo::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout)
42   @monitor_svc = DogapiDemo::V1::MonitorService.new(@api_key, @application_key, silent, timeout)
43   @service_check_svc = DogapiDemo::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout)
44   @legacy_event_svc = DogapiDemo::EventService.new(@datadog_host)
45 end

Public Instance Methods

add_tags(host_id, tags, source = nil) click to toggle source

Add the tags to the given host

host_id can be the host's numeric id or string name

tags is and Array of Strings

    # File lib/dogapi-demo/facade.rb
212 def add_tags(host_id, tags, source = nil)
213   @tag_svc.add(host_id, tags, source)
214 end
alert(query, options = {}) click to toggle source

ALERTS

    # File lib/dogapi-demo/facade.rb
271 def alert(query, options = {})
272   @alert_svc.alert(query, options)
273 end
all_tags(source = nil) click to toggle source

Get all tags and their associated hosts at your org

    # File lib/dogapi-demo/facade.rb
196 def all_tags(source = nil)
197   @tag_svc.get_all(source)
198 end
batch_metrics() { || ... } click to toggle source
    # File lib/dogapi-demo/facade.rb
104 def batch_metrics()
105   @metric_svc.switch_to_batched
106   begin
107     yield
108     @metric_svc.flush_buffer # flush_buffer should returns the response from last API call
109   ensure
110     @metric_svc.switch_to_single
111   end
112 end
cancel_downtime(downtime_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
439 def cancel_downtime(downtime_id)
440   @monitor_svc.cancel_downtime(downtime_id)
441 end
comment(message, options = {}) click to toggle source

Post a comment

    # File lib/dogapi-demo/facade.rb
168 def comment(message, options = {})
169   @comment_svc.comment(message, options)
170 end
create_dashboard(title, description, graphs, template_variables = nil) click to toggle source

Create a dashboard.

    # File lib/dogapi-demo/facade.rb
243 def create_dashboard(title, description, graphs, template_variables = nil)
244   @dash_service.create_dashboard(title, description, graphs, template_variables)
245 end
create_embed(graph_json, description= {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
340 def create_embed(graph_json, description= {})
341   @embed_svc.create_embed(graph_json, description)
342 end
create_screenboard(description) click to toggle source

SCREENBOARD

    # File lib/dogapi-demo/facade.rb
355 def create_screenboard(description)
356   @screenboard_svc.create_screenboard(description)
357 end
create_user(description = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
304 def create_user(description = {})
305   @user_svc.create_user(description)
306 end
delete_alert(alert_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
283 def delete_alert(alert_id)
284   @alert_svc.delete_alert(alert_id)
285 end
delete_comment(comment_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
177 def delete_comment(comment_id)
178   @comment_svc.delete_comment(comment_id)
179 end
delete_dashboard(dash_id) click to toggle source

Delete the given dashboard.

    # File lib/dogapi-demo/facade.rb
263 def delete_dashboard(dash_id)
264   @dash_service.delete_dashboard(dash_id)
265 end
delete_monitor(monitor_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
399 def delete_monitor(monitor_id)
400   @monitor_svc.delete_monitor(monitor_id)
401 end
delete_screenboard(board_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
371 def delete_screenboard(board_id)
372   @screenboard_svc.delete_screenboard(board_id)
373 end
detach_tags(host_id, source = nil) click to toggle source

Remove all tags from the given host

host_id can be the host's numeric id or string name

    # File lib/dogapi-demo/facade.rb
234 def detach_tags(host_id, source = nil)
235   @tag_svc.detach(host_id, source)
236 end
detatch_tags(host_id) click to toggle source

DEPRECATED: Spelling mistake temporarily preserved as an alias.

    # File lib/dogapi-demo/facade.rb
226 def detatch_tags(host_id)
227   warn "[DEPRECATION] DogapiDemo::Client.detatch() is deprecated. Use `detach` instead."
228   detach_tags(host_id)
229 end
disable_user(handle) click to toggle source
    # File lib/dogapi-demo/facade.rb
320 def disable_user(handle)
321   @user_svc.disable_user(handle)
322 end
emit_event(event, options = {}) click to toggle source

Record an event

Optional arguments:

:host        => String
:device      => String
    # File lib/dogapi-demo/facade.rb
122 def emit_event(event, options = {})
123   scope = override_scope options
124 
125   @event_svc.post(event, scope)
126 end
emit_point(metric, value, options = {}) click to toggle source

Record a single point of metric data

Optional arguments:

:timestamp => Ruby stdlib Time
:host      => String
:device    => String
:options   => Map

options = “counter” to specify a counter metric options = [“tag1”, “tag2”] to tag the point

   # File lib/dogapi-demo/facade.rb
60 def emit_point(metric, value, options = {})
61   defaults = { :timestamp => Time.now }
62   options = defaults.merge(options)
63 
64   self.emit_points(
65     metric,
66     [[options[:timestamp], value]],
67     options
68   )
69 end
emit_points(metric, points, options = {}) click to toggle source

Record a set of points of metric data

points is an array of [Time, value] doubles

Optional arguments:

:host   => String
:device => String
:options   => Map

options = “counter” to specify a counter metric options = [“tag1”, “tag2”] to tag the point

   # File lib/dogapi-demo/facade.rb
82 def emit_points(metric, points, options = {})
83   scope = override_scope options
84 
85   points.each do |p|
86     p[0].kind_of? Time or raise "Not a Time"
87     p[0] = p[0].to_i
88     p[1] = p[1].to_f # TODO: stupid to_f will never raise an exception
89   end
90 
91   @metric_svc.submit(metric, points, scope, options)
92 end
enable_embed(embed_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
344 def enable_embed(embed_id)
345   @embed_svc.enable_embed(embed_id)
346 end
get_alert(alert_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
279 def get_alert(alert_id)
280   @alert_svc.get_alert(alert_id)
281 end
get_all_alerts() click to toggle source
    # File lib/dogapi-demo/facade.rb
287 def get_all_alerts()
288   @alert_svc.get_all_alerts()
289 end
get_all_downtimes(options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
443 def get_all_downtimes(options = {})
444   @monitor_svc.get_all_downtimes(options)
445 end
get_all_embeds() click to toggle source

EMBEDS

    # File lib/dogapi-demo/facade.rb
332 def get_all_embeds()
333   @embed_svc.get_all_embeds()
334 end
get_all_monitors(options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
403 def get_all_monitors(options = {})
404   @monitor_svc.get_all_monitors(options)
405 end
get_all_screenboards() click to toggle source
    # File lib/dogapi-demo/facade.rb
367 def get_all_screenboards()
368   @screenboard_svc.get_all_screenboards()
369 end
get_all_users() click to toggle source
    # File lib/dogapi-demo/facade.rb
308 def get_all_users()
309   @user_svc.get_all_users()
310 end
get_dashboard(dash_id) click to toggle source

Fetch the given dashboard.

    # File lib/dogapi-demo/facade.rb
253 def get_dashboard(dash_id)
254   @dash_service.get_dashboard(dash_id)
255 end
get_dashboards() click to toggle source

Fetch all of the dashboards.

    # File lib/dogapi-demo/facade.rb
258 def get_dashboards
259   @dash_service.get_dashboards
260 end
get_downtime(downtime_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
435 def get_downtime(downtime_id)
436   @monitor_svc.get_downtime(downtime_id)
437 end
get_embed(embed_id, description= {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
336 def get_embed(embed_id, description= {})
337   @embed_svc.get_embed(embed_id, description)
338 end
get_event(id) click to toggle source

Get the details of an event

id of the event to get

    # File lib/dogapi-demo/facade.rb
131 def get_event(id)
132   @event_svc.get(id)
133 end
get_monitor(monitor_id, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
395 def get_monitor(monitor_id, options = {})
396   @monitor_svc.get_monitor(monitor_id, options)
397 end
get_points(query, from, to) click to toggle source

Get a set of points by query between from and to

from The seconds since the unix epoch [Time, Integer] to The seconds since the unix epoch [Time, Integer] query The query string [String]

    # File lib/dogapi-demo/facade.rb
100 def get_points(query, from, to)
101   @metric_svc.get(query, from, to)
102 end
get_screenboard(board_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
363 def get_screenboard(board_id)
364   @screenboard_svc.get_screenboard(board_id)
365 end
get_user(handle) click to toggle source
    # File lib/dogapi-demo/facade.rb
312 def get_user(handle)
313   @user_svc.get_user(handle)
314 end
graph_snapshot(metric_query, start_ts, end_ts, event_query = nil) click to toggle source

Graph snapshot

    # File lib/dogapi-demo/facade.rb
325 def graph_snapshot(metric_query, start_ts, end_ts, event_query = nil)
326   @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query)
327 end
host_tags(host_id, source = nil, by_source = false) click to toggle source

Get all tags for the given host

host_id can be the host's numeric id or string name

    # File lib/dogapi-demo/facade.rb
203 def host_tags(host_id, source = nil, by_source = false)
204   @tag_svc.get(host_id, source, by_source)
205 end
invite(emails, options = {}) click to toggle source

User invite

    # File lib/dogapi-demo/facade.rb
300 def invite(emails, options = {})
301   @user_svc.invite(emails, options)
302 end
monitor(type, query, options = {}) click to toggle source

MONITORS

    # File lib/dogapi-demo/facade.rb
387 def monitor(type, query, options = {})
388   @monitor_svc.monitor(type, query, options)
389 end
mute_alerts() click to toggle source
    # File lib/dogapi-demo/facade.rb
291 def mute_alerts()
292   @alert_svc.mute_alerts()
293 end
mute_host(hostname, options = {}) click to toggle source

HOST MUTING

    # File lib/dogapi-demo/facade.rb
451 def mute_host(hostname, options = {})
452   @monitor_svc.mute_host(hostname, options)
453 end
mute_monitor(monitor_id, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
415 def mute_monitor(monitor_id, options = {})
416   @monitor_svc.mute_monitor(monitor_id, options)
417 end
mute_monitors() click to toggle source
    # File lib/dogapi-demo/facade.rb
407 def mute_monitors()
408   @monitor_svc.mute_monitors()
409 end
revoke_embed(embed_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
348 def revoke_embed(embed_id)
349   @embed_svc.revoke_embed(embed_id)
350 end
revoke_screenboard(board_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
379 def revoke_screenboard(board_id)
380   @screenboard_svc.revoke_screenboard(board_id)
381 end
schedule_downtime(scope, options = {}) click to toggle source

MONITOR DOWNTIME

    # File lib/dogapi-demo/facade.rb
427 def schedule_downtime(scope, options = {})
428   @monitor_svc.schedule_downtime(scope, options)
429 end
service_check(check, host, status, options = {}) click to toggle source

SERVICE CHECKS

    # File lib/dogapi-demo/facade.rb
463 def service_check(check, host, status, options = {})
464   @service_check_svc.service_check(check, host, status, options)
465 end
share_screenboard(board_id) click to toggle source
    # File lib/dogapi-demo/facade.rb
375 def share_screenboard(board_id)
376   @screenboard_svc.share_screenboard(board_id)
377 end
start_event(event, options = {}) { || ... } click to toggle source

DEPRECATED: Recording events with a duration has been deprecated. The functionality will be removed in a later release.

    # File lib/dogapi-demo/facade.rb
151 def start_event(event, options = {})
152   warn "[DEPRECATION] DogapiDemo::Client.start_event() is deprecated. Use `emit_event` instead."
153   defaults = { :source_type => nil }
154   options = defaults.merge(options)
155 
156   scope = override_scope options
157 
158   @legacy_event_svc.start(@api_key, event, scope, options[:source_type]) do
159     yield
160   end
161 end
stream(start, stop, options = {}) click to toggle source

Get an optionally filtered event stream

start is a Time object for when to start the stream

stop is a Time object for when to end the stream

Optional arguments:

:priority   => "normal" or "low"
:sources    => String, see https://github.com/DataDog/dogapi-demo/wiki/Event for a current list of sources
:tags       => Array of Strings
    # File lib/dogapi-demo/facade.rb
145 def stream(start, stop, options = {})
146   @event_svc.stream(start, stop, options)
147 end
unmute_alerts() click to toggle source
    # File lib/dogapi-demo/facade.rb
295 def unmute_alerts()
296   @alert_svc.unmute_alerts()
297 end
unmute_host(hostname) click to toggle source
    # File lib/dogapi-demo/facade.rb
455 def unmute_host(hostname)
456   @monitor_svc.unmute_host(hostname)
457 end
unmute_monitor(monitor_id, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
419 def unmute_monitor(monitor_id, options = {})
420   @monitor_svc.unmute_monitor(monitor_id, options)
421 end
unmute_monitors() click to toggle source
    # File lib/dogapi-demo/facade.rb
411 def unmute_monitors()
412   @monitor_svc.unmute_monitors()
413 end
update_alert(alert_id, query, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
275 def update_alert(alert_id, query, options = {})
276   @alert_svc.update_alert(alert_id, query, options)
277 end
update_comment(comment_id, options = {}) click to toggle source

Post a comment

    # File lib/dogapi-demo/facade.rb
173 def update_comment(comment_id, options = {})
174   @comment_svc.update_comment(comment_id, options)
175 end
update_dashboard(dash_id, title, description, graphs, template_variables = nil) click to toggle source

Update a dashboard.

    # File lib/dogapi-demo/facade.rb
248 def update_dashboard(dash_id, title, description, graphs, template_variables = nil)
249   @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables)
250 end
update_downtime(downtime_id, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
431 def update_downtime(downtime_id, options = {})
432   @monitor_svc.update_downtime(downtime_id, options)
433 end
update_monitor(monitor_id, query, options = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
391 def update_monitor(monitor_id, query, options = {})
392   @monitor_svc.update_monitor(monitor_id, query, options)
393 end
update_screenboard(board_id, description) click to toggle source
    # File lib/dogapi-demo/facade.rb
359 def update_screenboard(board_id, description)
360   @screenboard_svc.update_screenboard(board_id, description)
361 end
update_tags(host_id, tags, source = nil) click to toggle source

Replace the tags on the given host

host_id can be the host's numeric id or string name

tags is and Array of Strings

    # File lib/dogapi-demo/facade.rb
221 def update_tags(host_id, tags, source = nil)
222   @tag_svc.update(host_id, tags, source)
223 end
update_user(handle, description = {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
316 def update_user(handle, description = {})
317   @user_svc.update_user(handle, description)
318 end

Private Instance Methods

override_scope(options= {}) click to toggle source
    # File lib/dogapi-demo/facade.rb
469 def override_scope(options= {})
470   defaults = { :host => @host, :device => @device }
471   options = defaults.merge(options)
472   Scope.new(options[:host], options[:device])
473 end