Class: DogapiDemo::Client
- Inherits:
-
Object
- Object
- DogapiDemo::Client
- Defined in:
- lib/dogapi-demo/facade.rb
Overview
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.
Instance Method Summary collapse
-
#add_tags(host_id, tags, source = nil) ⇒ Object
Add the tags to the given host.
-
#alert(query, options = {}) ⇒ Object
ALERTS.
-
#all_tags(source = nil) ⇒ Object
Get all tags and their associated hosts at your org.
- #batch_metrics ⇒ Object
- #cancel_downtime(downtime_id) ⇒ Object
-
#comment(message, options = {}) ⇒ Object
Post a comment.
-
#create_dashboard(title, description, graphs, template_variables = nil) ⇒ Object
Create a dashboard.
- #create_embed(graph_json, description = {}) ⇒ Object
-
#create_screenboard(description) ⇒ Object
SCREENBOARD.
- #create_user(description = {}) ⇒ Object
- #delete_alert(alert_id) ⇒ Object
- #delete_comment(comment_id) ⇒ Object
-
#delete_dashboard(dash_id) ⇒ Object
Delete the given dashboard.
- #delete_monitor(monitor_id) ⇒ Object
- #delete_screenboard(board_id) ⇒ Object
-
#detach_tags(host_id, source = nil) ⇒ Object
Remove all tags from the given host.
-
#detatch_tags(host_id) ⇒ Object
DEPRECATED: Spelling mistake temporarily preserved as an alias.
- #disable_user(handle) ⇒ Object
-
#emit_event(event, options = {}) ⇒ Object
Record an event.
-
#emit_point(metric, value, options = {}) ⇒ Object
Record a single point of metric data.
-
#emit_points(metric, points, options = {}) ⇒ Object
Record a set of points of metric data.
- #enable_embed(embed_id) ⇒ Object
- #get_alert(alert_id) ⇒ Object
- #get_all_alerts ⇒ Object
- #get_all_downtimes(options = {}) ⇒ Object
-
#get_all_embeds ⇒ Object
EMBEDS.
- #get_all_monitors(options = {}) ⇒ Object
- #get_all_screenboards ⇒ Object
- #get_all_users ⇒ Object
-
#get_dashboard(dash_id) ⇒ Object
Fetch the given dashboard.
-
#get_dashboards ⇒ Object
Fetch all of the dashboards.
- #get_downtime(downtime_id) ⇒ Object
- #get_embed(embed_id, description = {}) ⇒ Object
-
#get_event(id) ⇒ Object
Get the details of an event.
- #get_monitor(monitor_id, options = {}) ⇒ Object
-
#get_points(query, from, to) ⇒ Object
Get a set of points by query between from and to.
- #get_screenboard(board_id) ⇒ Object
- #get_user(handle) ⇒ Object
-
#graph_snapshot(metric_query, start_ts, end_ts, event_query = nil) ⇒ Object
Graph snapshot.
-
#host_tags(host_id, source = nil, by_source = false) ⇒ Object
Get all tags for the given host.
-
#initialize(api_key, application_key = nil, host = nil, device = nil, silent = true, timeout = nil) ⇒ Client
constructor
Create a new Client optionally specifying a default host and device.
-
#invite(emails, options = {}) ⇒ Object
User invite.
-
#monitor(type, query, options = {}) ⇒ Object
MONITORS.
- #mute_alerts ⇒ Object
-
#mute_host(hostname, options = {}) ⇒ Object
HOST MUTING.
- #mute_monitor(monitor_id, options = {}) ⇒ Object
- #mute_monitors ⇒ Object
- #revoke_embed(embed_id) ⇒ Object
- #revoke_screenboard(board_id) ⇒ Object
-
#schedule_downtime(scope, options = {}) ⇒ Object
MONITOR DOWNTIME.
-
#search(query) ⇒ Object
Run the given search query.
-
#service_check(check, host, status, options = {}) ⇒ Object
SERVICE CHECKS.
- #share_screenboard(board_id) ⇒ Object
-
#start_event(event, options = {}) ⇒ Object
DEPRECATED: Recording events with a duration has been deprecated.
-
#stream(start, stop, options = {}) ⇒ Object
Get an optionally filtered event stream.
- #unmute_alerts ⇒ Object
- #unmute_host(hostname) ⇒ Object
- #unmute_monitor(monitor_id, options = {}) ⇒ Object
- #unmute_monitors ⇒ Object
- #update_alert(alert_id, query, options = {}) ⇒ Object
-
#update_comment(comment_id, options = {}) ⇒ Object
Post a comment.
-
#update_dashboard(dash_id, title, description, graphs, template_variables = nil) ⇒ Object
Update a dashboard.
- #update_downtime(downtime_id, options = {}) ⇒ Object
- #update_monitor(monitor_id, query, options = {}) ⇒ Object
- #update_screenboard(board_id, description) ⇒ Object
-
#update_tags(host_id, tags, source = nil) ⇒ Object
Replace the tags on the given host.
- #update_user(handle, description = {}) ⇒ Object
Constructor Details
#initialize(api_key, application_key = nil, host = nil, device = nil, silent = true, timeout = nil) ⇒ Client
Create a new Client optionally specifying a default host and device
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dogapi-demo/facade.rb', line 14 def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil) if api_key @api_key = api_key else raise 'Please provide an API key to submit your data' end @application_key = application_key @datadog_host = DogapiDemo.find_datadog_host() @host = host ||= DogapiDemo.find_localhost() @device = device # FIXME: refactor to avoid all this code duplication @metric_svc = DogapiDemo::V1::MetricService.new(@api_key, @application_key, silent, timeout) @event_svc = DogapiDemo::V1::EventService.new(@api_key, @application_key, silent, timeout) @tag_svc = DogapiDemo::V1::TagService.new(@api_key, @application_key, silent, timeout) @comment_svc = DogapiDemo::V1::CommentService.new(@api_key, @application_key, silent, timeout) @search_svc = DogapiDemo::V1::SearchService.new(@api_key, @application_key, silent, timeout) @dash_service = DogapiDemo::V1::DashService.new(@api_key, @application_key, silent, timeout) @alert_svc = DogapiDemo::V1::AlertService.new(@api_key, @application_key, silent, timeout) @user_svc = DogapiDemo::V1::UserService.new(@api_key, @application_key, silent, timeout) @snapshot_svc = DogapiDemo::V1::SnapshotService.new(@api_key, @application_key, silent, timeout) @embed_svc = DogapiDemo::V1::EmbedService.new(@api_key, @application_key, silent, timeout) @screenboard_svc = DogapiDemo::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout) @monitor_svc = DogapiDemo::V1::MonitorService.new(@api_key, @application_key, silent, timeout) @service_check_svc = DogapiDemo::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout) @legacy_event_svc = DogapiDemo::EventService.new(@datadog_host) end |
Instance Method Details
#add_tags(host_id, tags, source = nil) ⇒ Object
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
212 213 214 |
# File 'lib/dogapi-demo/facade.rb', line 212 def (host_id, , source = nil) @tag_svc.add(host_id, , source) end |
#alert(query, options = {}) ⇒ Object
ALERTS
271 272 273 |
# File 'lib/dogapi-demo/facade.rb', line 271 def alert(query, = {}) @alert_svc.alert(query, ) end |
#all_tags(source = nil) ⇒ Object
Get all tags and their associated hosts at your org
196 197 198 |
# File 'lib/dogapi-demo/facade.rb', line 196 def (source = nil) @tag_svc.get_all(source) end |
#batch_metrics ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/dogapi-demo/facade.rb', line 104 def batch_metrics() @metric_svc.switch_to_batched begin yield @metric_svc.flush_buffer # flush_buffer should returns the response from last API call ensure @metric_svc.switch_to_single end end |
#cancel_downtime(downtime_id) ⇒ Object
439 440 441 |
# File 'lib/dogapi-demo/facade.rb', line 439 def cancel_downtime(downtime_id) @monitor_svc.cancel_downtime(downtime_id) end |
#comment(message, options = {}) ⇒ Object
Post a comment
168 169 170 |
# File 'lib/dogapi-demo/facade.rb', line 168 def comment(, = {}) @comment_svc.comment(, ) end |
#create_dashboard(title, description, graphs, template_variables = nil) ⇒ Object
Create a dashboard.
243 244 245 |
# File 'lib/dogapi-demo/facade.rb', line 243 def create_dashboard(title, description, graphs, template_variables = nil) @dash_service.create_dashboard(title, description, graphs, template_variables) end |
#create_embed(graph_json, description = {}) ⇒ Object
340 341 342 |
# File 'lib/dogapi-demo/facade.rb', line 340 def (graph_json, description= {}) @embed_svc.(graph_json, description) end |
#create_screenboard(description) ⇒ Object
SCREENBOARD
355 356 357 |
# File 'lib/dogapi-demo/facade.rb', line 355 def create_screenboard(description) @screenboard_svc.create_screenboard(description) end |
#create_user(description = {}) ⇒ Object
304 305 306 |
# File 'lib/dogapi-demo/facade.rb', line 304 def create_user(description = {}) @user_svc.create_user(description) end |
#delete_alert(alert_id) ⇒ Object
283 284 285 |
# File 'lib/dogapi-demo/facade.rb', line 283 def delete_alert(alert_id) @alert_svc.delete_alert(alert_id) end |
#delete_comment(comment_id) ⇒ Object
177 178 179 |
# File 'lib/dogapi-demo/facade.rb', line 177 def delete_comment(comment_id) @comment_svc.delete_comment(comment_id) end |
#delete_dashboard(dash_id) ⇒ Object
Delete the given dashboard.
263 264 265 |
# File 'lib/dogapi-demo/facade.rb', line 263 def delete_dashboard(dash_id) @dash_service.delete_dashboard(dash_id) end |
#delete_monitor(monitor_id) ⇒ Object
399 400 401 |
# File 'lib/dogapi-demo/facade.rb', line 399 def delete_monitor(monitor_id) @monitor_svc.delete_monitor(monitor_id) end |
#delete_screenboard(board_id) ⇒ Object
371 372 373 |
# File 'lib/dogapi-demo/facade.rb', line 371 def delete_screenboard(board_id) @screenboard_svc.delete_screenboard(board_id) end |
#detach_tags(host_id, source = nil) ⇒ Object
Remove all tags from the given host
host_id
can be the host’s numeric id or string name
234 235 236 |
# File 'lib/dogapi-demo/facade.rb', line 234 def (host_id, source = nil) @tag_svc.detach(host_id, source) end |
#detatch_tags(host_id) ⇒ Object
DEPRECATED: Spelling mistake temporarily preserved as an alias.
226 227 228 229 |
# File 'lib/dogapi-demo/facade.rb', line 226 def (host_id) warn "[DEPRECATION] DogapiDemo::Client.detatch() is deprecated. Use `detach` instead." (host_id) end |
#disable_user(handle) ⇒ Object
320 321 322 |
# File 'lib/dogapi-demo/facade.rb', line 320 def disable_user(handle) @user_svc.disable_user(handle) end |
#emit_event(event, options = {}) ⇒ Object
Record an event
Optional arguments:
:host => String
:device => String
122 123 124 125 126 |
# File 'lib/dogapi-demo/facade.rb', line 122 def emit_event(event, = {}) scope = override_scope @event_svc.post(event, scope) end |
#emit_point(metric, value, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dogapi-demo/facade.rb', line 60 def emit_point(metric, value, = {}) defaults = { :timestamp => Time.now } = defaults.merge() self.emit_points( metric, [[[:timestamp], value]], ) end |
#emit_points(metric, points, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dogapi-demo/facade.rb', line 82 def emit_points(metric, points, = {}) scope = override_scope points.each do |p| p[0].kind_of? Time or raise "Not a Time" p[0] = p[0].to_i p[1] = p[1].to_f # TODO: stupid to_f will never raise an exception end @metric_svc.submit(metric, points, scope, ) end |
#enable_embed(embed_id) ⇒ Object
344 345 346 |
# File 'lib/dogapi-demo/facade.rb', line 344 def () @embed_svc.() end |
#get_alert(alert_id) ⇒ Object
279 280 281 |
# File 'lib/dogapi-demo/facade.rb', line 279 def get_alert(alert_id) @alert_svc.get_alert(alert_id) end |
#get_all_alerts ⇒ Object
287 288 289 |
# File 'lib/dogapi-demo/facade.rb', line 287 def get_all_alerts() @alert_svc.get_all_alerts() end |
#get_all_downtimes(options = {}) ⇒ Object
443 444 445 |
# File 'lib/dogapi-demo/facade.rb', line 443 def get_all_downtimes( = {}) @monitor_svc.get_all_downtimes() end |
#get_all_embeds ⇒ Object
EMBEDS
332 333 334 |
# File 'lib/dogapi-demo/facade.rb', line 332 def () @embed_svc.() end |
#get_all_monitors(options = {}) ⇒ Object
403 404 405 |
# File 'lib/dogapi-demo/facade.rb', line 403 def get_all_monitors( = {}) @monitor_svc.get_all_monitors() end |
#get_all_screenboards ⇒ Object
367 368 369 |
# File 'lib/dogapi-demo/facade.rb', line 367 def get_all_screenboards() @screenboard_svc.get_all_screenboards() end |
#get_all_users ⇒ Object
308 309 310 |
# File 'lib/dogapi-demo/facade.rb', line 308 def get_all_users() @user_svc.get_all_users() end |
#get_dashboard(dash_id) ⇒ Object
Fetch the given dashboard.
253 254 255 |
# File 'lib/dogapi-demo/facade.rb', line 253 def get_dashboard(dash_id) @dash_service.get_dashboard(dash_id) end |
#get_dashboards ⇒ Object
Fetch all of the dashboards.
258 259 260 |
# File 'lib/dogapi-demo/facade.rb', line 258 def get_dashboards @dash_service.get_dashboards end |
#get_downtime(downtime_id) ⇒ Object
435 436 437 |
# File 'lib/dogapi-demo/facade.rb', line 435 def get_downtime(downtime_id) @monitor_svc.get_downtime(downtime_id) end |
#get_embed(embed_id, description = {}) ⇒ Object
336 337 338 |
# File 'lib/dogapi-demo/facade.rb', line 336 def (, description= {}) @embed_svc.(, description) end |
#get_event(id) ⇒ Object
Get the details of an event
id
of the event to get
131 132 133 |
# File 'lib/dogapi-demo/facade.rb', line 131 def get_event(id) @event_svc.get(id) end |
#get_monitor(monitor_id, options = {}) ⇒ Object
395 396 397 |
# File 'lib/dogapi-demo/facade.rb', line 395 def get_monitor(monitor_id, = {}) @monitor_svc.get_monitor(monitor_id, ) end |
#get_points(query, from, to) ⇒ Object
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]
100 101 102 |
# File 'lib/dogapi-demo/facade.rb', line 100 def get_points(query, from, to) @metric_svc.get(query, from, to) end |
#get_screenboard(board_id) ⇒ Object
363 364 365 |
# File 'lib/dogapi-demo/facade.rb', line 363 def get_screenboard(board_id) @screenboard_svc.get_screenboard(board_id) end |
#get_user(handle) ⇒ Object
312 313 314 |
# File 'lib/dogapi-demo/facade.rb', line 312 def get_user(handle) @user_svc.get_user(handle) end |
#graph_snapshot(metric_query, start_ts, end_ts, event_query = nil) ⇒ Object
Graph snapshot
325 326 327 |
# File 'lib/dogapi-demo/facade.rb', line 325 def graph_snapshot(metric_query, start_ts, end_ts, event_query = nil) @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query) end |
#host_tags(host_id, source = nil, by_source = false) ⇒ Object
Get all tags for the given host
host_id
can be the host’s numeric id or string name
203 204 205 |
# File 'lib/dogapi-demo/facade.rb', line 203 def (host_id, source = nil, by_source = false) @tag_svc.get(host_id, source, by_source) end |
#invite(emails, options = {}) ⇒ Object
User invite
300 301 302 |
# File 'lib/dogapi-demo/facade.rb', line 300 def invite(emails, = {}) @user_svc.invite(emails, ) end |
#monitor(type, query, options = {}) ⇒ Object
MONITORS
387 388 389 |
# File 'lib/dogapi-demo/facade.rb', line 387 def monitor(type, query, = {}) @monitor_svc.monitor(type, query, ) end |
#mute_alerts ⇒ Object
291 292 293 |
# File 'lib/dogapi-demo/facade.rb', line 291 def mute_alerts() @alert_svc.mute_alerts() end |
#mute_host(hostname, options = {}) ⇒ Object
HOST MUTING
451 452 453 |
# File 'lib/dogapi-demo/facade.rb', line 451 def mute_host(hostname, = {}) @monitor_svc.mute_host(hostname, ) end |
#mute_monitor(monitor_id, options = {}) ⇒ Object
415 416 417 |
# File 'lib/dogapi-demo/facade.rb', line 415 def mute_monitor(monitor_id, = {}) @monitor_svc.mute_monitor(monitor_id, ) end |
#mute_monitors ⇒ Object
407 408 409 |
# File 'lib/dogapi-demo/facade.rb', line 407 def mute_monitors() @monitor_svc.mute_monitors() end |
#revoke_embed(embed_id) ⇒ Object
348 349 350 |
# File 'lib/dogapi-demo/facade.rb', line 348 def () @embed_svc.() end |
#revoke_screenboard(board_id) ⇒ Object
379 380 381 |
# File 'lib/dogapi-demo/facade.rb', line 379 def revoke_screenboard(board_id) @screenboard_svc.revoke_screenboard(board_id) end |
#schedule_downtime(scope, options = {}) ⇒ Object
MONITOR DOWNTIME
427 428 429 |
# File 'lib/dogapi-demo/facade.rb', line 427 def schedule_downtime(scope, = {}) @monitor_svc.schedule_downtime(scope, ) end |
#search(query) ⇒ Object
Run the given search query.
186 187 188 |
# File 'lib/dogapi-demo/facade.rb', line 186 def search(query) @search_svc.search query end |
#service_check(check, host, status, options = {}) ⇒ Object
SERVICE CHECKS
463 464 465 |
# File 'lib/dogapi-demo/facade.rb', line 463 def service_check(check, host, status, = {}) @service_check_svc.service_check(check, host, status, ) end |
#share_screenboard(board_id) ⇒ Object
375 376 377 |
# File 'lib/dogapi-demo/facade.rb', line 375 def share_screenboard(board_id) @screenboard_svc.share_screenboard(board_id) end |
#start_event(event, options = {}) ⇒ Object
DEPRECATED: Recording events with a duration has been deprecated. The functionality will be removed in a later release.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dogapi-demo/facade.rb', line 151 def start_event(event, = {}) warn "[DEPRECATION] DogapiDemo::Client.start_event() is deprecated. Use `emit_event` instead." defaults = { :source_type => nil } = defaults.merge() scope = override_scope @legacy_event_svc.start(@api_key, event, scope, [:source_type]) do yield end end |
#stream(start, stop, options = {}) ⇒ Object
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
145 146 147 |
# File 'lib/dogapi-demo/facade.rb', line 145 def stream(start, stop, = {}) @event_svc.stream(start, stop, ) end |
#unmute_alerts ⇒ Object
295 296 297 |
# File 'lib/dogapi-demo/facade.rb', line 295 def unmute_alerts() @alert_svc.unmute_alerts() end |
#unmute_host(hostname) ⇒ Object
455 456 457 |
# File 'lib/dogapi-demo/facade.rb', line 455 def unmute_host(hostname) @monitor_svc.unmute_host(hostname) end |
#unmute_monitor(monitor_id, options = {}) ⇒ Object
419 420 421 |
# File 'lib/dogapi-demo/facade.rb', line 419 def unmute_monitor(monitor_id, = {}) @monitor_svc.unmute_monitor(monitor_id, ) end |
#unmute_monitors ⇒ Object
411 412 413 |
# File 'lib/dogapi-demo/facade.rb', line 411 def unmute_monitors() @monitor_svc.unmute_monitors() end |
#update_alert(alert_id, query, options = {}) ⇒ Object
275 276 277 |
# File 'lib/dogapi-demo/facade.rb', line 275 def update_alert(alert_id, query, = {}) @alert_svc.update_alert(alert_id, query, ) end |
#update_comment(comment_id, options = {}) ⇒ Object
Post a comment
173 174 175 |
# File 'lib/dogapi-demo/facade.rb', line 173 def update_comment(comment_id, = {}) @comment_svc.update_comment(comment_id, ) end |
#update_dashboard(dash_id, title, description, graphs, template_variables = nil) ⇒ Object
Update a dashboard.
248 249 250 |
# File 'lib/dogapi-demo/facade.rb', line 248 def update_dashboard(dash_id, title, description, graphs, template_variables = nil) @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables) end |
#update_downtime(downtime_id, options = {}) ⇒ Object
431 432 433 |
# File 'lib/dogapi-demo/facade.rb', line 431 def update_downtime(downtime_id, = {}) @monitor_svc.update_downtime(downtime_id, ) end |
#update_monitor(monitor_id, query, options = {}) ⇒ Object
391 392 393 |
# File 'lib/dogapi-demo/facade.rb', line 391 def update_monitor(monitor_id, query, = {}) @monitor_svc.update_monitor(monitor_id, query, ) end |
#update_screenboard(board_id, description) ⇒ Object
359 360 361 |
# File 'lib/dogapi-demo/facade.rb', line 359 def update_screenboard(board_id, description) @screenboard_svc.update_screenboard(board_id, description) end |
#update_tags(host_id, tags, source = nil) ⇒ Object
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
221 222 223 |
# File 'lib/dogapi-demo/facade.rb', line 221 def (host_id, , source = nil) @tag_svc.update(host_id, , source) end |
#update_user(handle, description = {}) ⇒ Object
316 317 318 |
# File 'lib/dogapi-demo/facade.rb', line 316 def update_user(handle, description = {}) @user_svc.update_user(handle, description) end |