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
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
ALERTS
# File lib/dogapi-demo/facade.rb 271 def alert(query, options = {}) 272 @alert_svc.alert(query, options) 273 end
# 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
# File lib/dogapi-demo/facade.rb 439 def cancel_downtime(downtime_id) 440 @monitor_svc.cancel_downtime(downtime_id) 441 end
Post a comment
# File lib/dogapi-demo/facade.rb 168 def comment(message, options = {}) 169 @comment_svc.comment(message, options) 170 end
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
# File lib/dogapi-demo/facade.rb 340 def create_embed(graph_json, description= {}) 341 @embed_svc.create_embed(graph_json, description) 342 end
SCREENBOARD
# File lib/dogapi-demo/facade.rb 355 def create_screenboard(description) 356 @screenboard_svc.create_screenboard(description) 357 end
# File lib/dogapi-demo/facade.rb 304 def create_user(description = {}) 305 @user_svc.create_user(description) 306 end
# File lib/dogapi-demo/facade.rb 283 def delete_alert(alert_id) 284 @alert_svc.delete_alert(alert_id) 285 end
# File lib/dogapi-demo/facade.rb 177 def delete_comment(comment_id) 178 @comment_svc.delete_comment(comment_id) 179 end
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
# File lib/dogapi-demo/facade.rb 399 def delete_monitor(monitor_id) 400 @monitor_svc.delete_monitor(monitor_id) 401 end
# File lib/dogapi-demo/facade.rb 371 def delete_screenboard(board_id) 372 @screenboard_svc.delete_screenboard(board_id) 373 end
# File lib/dogapi-demo/facade.rb 320 def disable_user(handle) 321 @user_svc.disable_user(handle) 322 end
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
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
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
# File lib/dogapi-demo/facade.rb 344 def enable_embed(embed_id) 345 @embed_svc.enable_embed(embed_id) 346 end
# File lib/dogapi-demo/facade.rb 279 def get_alert(alert_id) 280 @alert_svc.get_alert(alert_id) 281 end
# File lib/dogapi-demo/facade.rb 287 def get_all_alerts() 288 @alert_svc.get_all_alerts() 289 end
# File lib/dogapi-demo/facade.rb 443 def get_all_downtimes(options = {}) 444 @monitor_svc.get_all_downtimes(options) 445 end
EMBEDS
# File lib/dogapi-demo/facade.rb 332 def get_all_embeds() 333 @embed_svc.get_all_embeds() 334 end
# File lib/dogapi-demo/facade.rb 403 def get_all_monitors(options = {}) 404 @monitor_svc.get_all_monitors(options) 405 end
# File lib/dogapi-demo/facade.rb 367 def get_all_screenboards() 368 @screenboard_svc.get_all_screenboards() 369 end
# File lib/dogapi-demo/facade.rb 308 def get_all_users() 309 @user_svc.get_all_users() 310 end
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
Fetch all of the dashboards.
# File lib/dogapi-demo/facade.rb 258 def get_dashboards 259 @dash_service.get_dashboards 260 end
# File lib/dogapi-demo/facade.rb 435 def get_downtime(downtime_id) 436 @monitor_svc.get_downtime(downtime_id) 437 end
# File lib/dogapi-demo/facade.rb 336 def get_embed(embed_id, description= {}) 337 @embed_svc.get_embed(embed_id, description) 338 end
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
# File lib/dogapi-demo/facade.rb 395 def get_monitor(monitor_id, options = {}) 396 @monitor_svc.get_monitor(monitor_id, options) 397 end
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
# File lib/dogapi-demo/facade.rb 363 def get_screenboard(board_id) 364 @screenboard_svc.get_screenboard(board_id) 365 end
# File lib/dogapi-demo/facade.rb 312 def get_user(handle) 313 @user_svc.get_user(handle) 314 end
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
User invite
# File lib/dogapi-demo/facade.rb 300 def invite(emails, options = {}) 301 @user_svc.invite(emails, options) 302 end
MONITORS
# File lib/dogapi-demo/facade.rb 387 def monitor(type, query, options = {}) 388 @monitor_svc.monitor(type, query, options) 389 end
# File lib/dogapi-demo/facade.rb 291 def mute_alerts() 292 @alert_svc.mute_alerts() 293 end
HOST MUTING
# File lib/dogapi-demo/facade.rb 451 def mute_host(hostname, options = {}) 452 @monitor_svc.mute_host(hostname, options) 453 end
# File lib/dogapi-demo/facade.rb 415 def mute_monitor(monitor_id, options = {}) 416 @monitor_svc.mute_monitor(monitor_id, options) 417 end
# File lib/dogapi-demo/facade.rb 407 def mute_monitors() 408 @monitor_svc.mute_monitors() 409 end
# File lib/dogapi-demo/facade.rb 348 def revoke_embed(embed_id) 349 @embed_svc.revoke_embed(embed_id) 350 end
# File lib/dogapi-demo/facade.rb 379 def revoke_screenboard(board_id) 380 @screenboard_svc.revoke_screenboard(board_id) 381 end
MONITOR DOWNTIME
# File lib/dogapi-demo/facade.rb 427 def schedule_downtime(scope, options = {}) 428 @monitor_svc.schedule_downtime(scope, options) 429 end
Run the given search query.
# File lib/dogapi-demo/facade.rb 186 def search(query) 187 @search_svc.search query 188 end
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
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
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
# File lib/dogapi-demo/facade.rb 295 def unmute_alerts() 296 @alert_svc.unmute_alerts() 297 end
# File lib/dogapi-demo/facade.rb 455 def unmute_host(hostname) 456 @monitor_svc.unmute_host(hostname) 457 end
# File lib/dogapi-demo/facade.rb 419 def unmute_monitor(monitor_id, options = {}) 420 @monitor_svc.unmute_monitor(monitor_id, options) 421 end
# File lib/dogapi-demo/facade.rb 411 def unmute_monitors() 412 @monitor_svc.unmute_monitors() 413 end
# 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
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 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
# File lib/dogapi-demo/facade.rb 431 def update_downtime(downtime_id, options = {}) 432 @monitor_svc.update_downtime(downtime_id, options) 433 end
# 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
# File lib/dogapi-demo/facade.rb 359 def update_screenboard(board_id, description) 360 @screenboard_svc.update_screenboard(board_id, description) 361 end
# File lib/dogapi-demo/facade.rb 316 def update_user(handle, description = {}) 317 @user_svc.update_user(handle, description) 318 end
Private Instance Methods
# 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