dogapi 1.22.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +3 -1
  6. data/CHANGELOG.md +16 -1
  7. data/Gemfile +6 -3
  8. data/README.rdoc +1 -1
  9. data/Rakefile +8 -15
  10. data/lib/capistrano/datadog.rb +12 -12
  11. data/lib/capistrano/datadog/v2.rb +5 -5
  12. data/lib/capistrano/datadog/v3.rb +9 -4
  13. data/lib/dogapi/common.rb +43 -39
  14. data/lib/dogapi/event.rb +4 -4
  15. data/lib/dogapi/facade.rb +57 -54
  16. data/lib/dogapi/metric.rb +2 -2
  17. data/lib/dogapi/v1/alert.rb +17 -80
  18. data/lib/dogapi/v1/comment.rb +8 -39
  19. data/lib/dogapi/v1/dash.rb +20 -67
  20. data/lib/dogapi/v1/embed.rb +11 -57
  21. data/lib/dogapi/v1/event.rb +37 -72
  22. data/lib/dogapi/v1/metric.rb +17 -46
  23. data/lib/dogapi/v1/monitor.rb +54 -194
  24. data/lib/dogapi/v1/screenboard.rb +8 -77
  25. data/lib/dogapi/v1/search.rb +5 -11
  26. data/lib/dogapi/v1/service_check.rb +6 -15
  27. data/lib/dogapi/v1/snapshot.rb +10 -15
  28. data/lib/dogapi/v1/tag.rb +39 -99
  29. data/lib/dogapi/v1/user.rb +15 -69
  30. data/lib/dogapi/version.rb +1 -1
  31. data/spec/integration/alert_spec.rb +48 -0
  32. data/spec/integration/comment_spec.rb +32 -0
  33. data/spec/integration/common_spec.rb +32 -0
  34. data/spec/integration/dash_spec.rb +60 -0
  35. data/spec/integration/embed_spec.rb +43 -0
  36. data/spec/integration/event_spec.rb +73 -0
  37. data/spec/integration/metric_spec.rb +96 -0
  38. data/spec/integration/monitor_spec.rb +106 -0
  39. data/spec/integration/screenboard_spec.rb +61 -0
  40. data/spec/integration/search_spec.rb +11 -0
  41. data/spec/integration/service_check_spec.rb +12 -0
  42. data/spec/integration/snapshot_spec.rb +24 -0
  43. data/spec/integration/tag_spec.rb +66 -0
  44. data/spec/integration/user_spec.rb +46 -0
  45. data/spec/spec_helper.rb +85 -16
  46. data/spec/unit/common_spec.rb +101 -0
  47. data/spec/unit/facade_spec.rb +79 -0
  48. metadata +55 -52
  49. data/spec/alerts_spec.rb +0 -33
  50. data/spec/common_spec.rb +0 -37
  51. data/spec/facade_spec.rb +0 -166
  52. data/spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml +0 -114
  53. data/spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml +0 -114
  54. data/spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml +0 -114
  55. data/spec/support/cassettes/Facade/Events/emits_aggregate_events.yml +0 -193
  56. data/spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml +0 -100
  57. data/spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml +0 -98
  58. data/spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml +0 -442
  59. data/tests/test_alerts.rb +0 -38
  60. data/tests/test_base.rb +0 -30
  61. data/tests/test_client.rb +0 -23
  62. data/tests/test_comments.rb +0 -39
  63. data/tests/test_dashes.rb +0 -85
  64. data/tests/test_embed.rb +0 -194
  65. data/tests/test_monitors.rb +0 -192
  66. data/tests/test_screenboard.rb +0 -90
  67. data/tests/test_search.rb +0 -20
  68. data/tests/test_snapshot.rb +0 -28
  69. data/tests/test_users.rb +0 -65
@@ -5,55 +5,24 @@ module Dogapi
5
5
 
6
6
  class CommentService < Dogapi::APIService
7
7
 
8
- API_VERSION = "v1"
8
+ API_VERSION = 'v1'
9
9
 
10
10
  # Submit a comment.
11
11
  def comment(message, options = {})
12
- begin
13
- params = {
14
- :api_key => @api_key,
15
- :application_key => @application_key
16
- }
17
-
18
- body = {
19
- 'message' => message,
20
- }.merge options
21
-
22
- request(Net::HTTP::Post, "/api/#{API_VERSION}/comments", params, body, true)
23
- rescue Exception => e
24
- suppress_error_if_silent e
25
- end
12
+ body = {
13
+ 'message' => message,
14
+ }.merge options
15
+
16
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/comments", nil, body, true)
26
17
  end
27
18
 
28
19
  # Update a comment.
29
20
  def update_comment(comment_id, options = {})
30
- begin
31
- params = {
32
- :api_key => @api_key,
33
- :application_key => @application_key
34
- }
35
-
36
- if options.empty?
37
- raise "Must update something."
38
- end
39
-
40
- request(Net::HTTP::Put, "/api/#{API_VERSION}/comments/#{comment_id}", params, options, true)
41
- rescue Exception => e
42
- suppress_error_if_silent e
43
- end
21
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/comments/#{comment_id}", nil, options, true)
44
22
  end
45
23
 
46
24
  def delete_comment(comment_id)
47
- begin
48
- params = {
49
- :api_key => @api_key,
50
- :application_key => @application_key
51
- }
52
-
53
- request(Net::HTTP::Delete, "/api/#{API_VERSION}/comments/#{comment_id}", params, nil, false)
54
- rescue Exception => e
55
- suppress_error_if_silent e
56
- end
25
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/comments/#{comment_id}", nil, nil, false)
57
26
  end
58
27
 
59
28
  end
@@ -5,87 +5,40 @@ module Dogapi
5
5
 
6
6
  class DashService < Dogapi::APIService
7
7
 
8
- API_VERSION = "v1"
8
+ API_VERSION = 'v1'
9
9
 
10
10
  def create_dashboard(title, description, graphs, template_variables = nil)
11
-
12
- begin
13
- params = {
14
- :api_key => @api_key,
15
- :application_key => @application_key
16
- }
17
-
18
- body = {
19
- :title => title,
20
- :description => description,
21
- :graphs => graphs,
22
- :template_variables => (template_variables or [])
23
- }
24
-
25
- request(Net::HTTP::Post, "/api/#{API_VERSION}/dash", params, body, true)
26
- rescue Exception => e
27
- suppress_error_if_silent e
28
- end
11
+ body = {
12
+ :title => title,
13
+ :description => description,
14
+ :graphs => graphs,
15
+ :template_variables => (template_variables or [])
16
+ }
17
+
18
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/dash", nil, body, true)
29
19
  end
30
20
 
31
21
  def update_dashboard(dash_id, title, description, graphs, template_variables=nil)
32
-
33
- begin
34
- params = {
35
- :api_key => @api_key,
36
- :application_key => @application_key
37
- }
38
-
39
- body = {
40
- :title => title,
41
- :description => description,
42
- :graphs => graphs,
43
- :template_variables => (template_variables or [])
44
- }
45
-
46
- request(Net::HTTP::Put, "/api/#{API_VERSION}/dash/#{dash_id}", params, body, true)
47
- rescue Exception => e
48
- suppress_error_if_silent e
49
- end
22
+ body = {
23
+ :title => title,
24
+ :description => description,
25
+ :graphs => graphs,
26
+ :template_variables => (template_variables or [])
27
+ }
28
+
29
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/dash/#{dash_id}", nil, body, true)
50
30
  end
51
31
 
52
32
  def get_dashboard(dash_id)
53
- begin
54
- params = {
55
- :api_key => @api_key,
56
- :application_key => @application_key
57
- }
58
-
59
- request(Net::HTTP::Get, "/api/#{API_VERSION}/dash/#{dash_id}", params, nil, false)
60
- rescue Exception => e
61
- suppress_error_if_silent e
62
- end
33
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/dash/#{dash_id}", nil, nil, false)
63
34
  end
64
35
 
65
36
  def get_dashboards
66
- begin
67
- params = {
68
- :api_key => @api_key,
69
- :application_key => @application_key
70
- }
71
-
72
- request(Net::HTTP::Get, "/api/#{API_VERSION}/dash", params, nil, false)
73
- rescue Exception => e
74
- suppress_error_if_silent e
75
- end
37
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/dash", nil, nil, false)
76
38
  end
77
39
 
78
40
  def delete_dashboard(dash_id)
79
- begin
80
- params = {
81
- :api_key => @api_key,
82
- :application_key => @application_key
83
- }
84
-
85
- request(Net::HTTP::Delete, "/api/#{API_VERSION}/dash/#{dash_id}", params, nil, false)
86
- rescue Exception => e
87
- suppress_error_if_silent e
88
- end
41
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/dash/#{dash_id}", nil, nil, false)
89
42
  end
90
43
 
91
44
  end
@@ -4,44 +4,25 @@ module Dogapi
4
4
  class V1 # for namespacing
5
5
 
6
6
  # ================
7
- # EMBED API
7
+ # EMBED API
8
8
  # ================
9
9
  class EmbedService < Dogapi::APIService
10
10
 
11
- API_VERSION = "v1"
11
+ API_VERSION = 'v1'
12
12
 
13
13
  # Get all embeds for the API user's org
14
14
  def get_all_embeds()
15
- begin
16
- params = {
17
- :api_key => @api_key,
18
- :application_key => @application_key
19
- }
20
-
21
- request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed", params, nil, false)
22
- rescue Exception => e
23
- suppress_error_if_silent e
24
- end
15
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed", nil, nil, false)
25
16
  end
26
17
 
27
18
  # Get a specific embed
28
19
  #
29
20
  # :embed_id => String: embed token for a specific embed
30
- # :size => String: "small", "medium"(defualt), "large", or "xlarge".
21
+ # :size => String: "small", "medium"(defualt), "large", or "xlarge".
31
22
  # :legend => String: "yes" or "no"(default)
32
23
  # :template_vars => String: variable name => variable value (any number of template vars)
33
24
  def get_embed(embed_id, description= {})
34
- begin
35
- # Initialize parameters and merge with description
36
- params = {
37
- :api_key => @api_key,
38
- :application_key => @application_key,
39
- }.merge(description)
40
-
41
- request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}", params, nil, false)
42
- rescue Exception => e
43
- suppress_error_if_silent e
44
- end
25
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}", description, nil, false)
45
26
  end
46
27
 
47
28
  # Create an embeddable graph
@@ -52,52 +33,25 @@ module Dogapi
52
33
  # :legend => String: flag representing whether a legend is displayed. Default is "no".
53
34
  # :title => String: represents title of the graph. Default is "Embed created through API."
54
35
  def create_embed(graph_json, description= {})
55
- begin
56
- params = {
57
- :api_key => @api_key,
58
- :application_key => @application_key
59
- }
60
-
61
- body = {
62
- :graph_json => graph_json,
63
- }.merge(description)
36
+ body = {
37
+ :graph_json => graph_json,
38
+ }.merge(description)
64
39
 
65
- request(Net::HTTP::Post, "/api/#{API_VERSION}/graph/embed", params, body, true)
66
- rescue Exception => e
67
- suppress_error_if_silent e
68
- end
40
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/graph/embed", nil, body, true)
69
41
  end
70
42
 
71
43
  # Enable a specific embed
72
44
  #
73
45
  # :embed_id => String: embed token for a specific embed
74
46
  def enable_embed(embed_id)
75
- begin
76
- params = {
77
- :api_key => @api_key,
78
- :application_key => @application_key
79
- }
80
-
81
- request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/enable", params, nil, false)
82
- rescue Exception => e
83
- suppress_error_if_silent e
84
- end
47
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/enable", nil, nil, false)
85
48
  end
86
49
 
87
50
  # Revoke a specific embed
88
51
  #
89
52
  # :embed_id => String: embed token for a specific embed
90
53
  def revoke_embed(embed_id)
91
- begin
92
- params = {
93
- :api_key => @api_key,
94
- :application_key => @application_key
95
- }
96
-
97
- request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/revoke", params, nil, false)
98
- rescue Exception => e
99
- suppress_error_if_silent e
100
- end
54
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/revoke", nil, nil, false)
101
55
  end
102
56
 
103
57
  end
@@ -6,93 +6,58 @@ module Dogapi
6
6
  # Event-specific client affording more granular control than the simple Dogapi::Client
7
7
  class EventService < Dogapi::APIService
8
8
 
9
- API_VERSION = "v1"
9
+ API_VERSION = 'v1'
10
10
  MAX_BODY_LENGTH = 4000
11
11
  MAX_TITLE_LENGTH = 100
12
12
 
13
13
  # Records an Event with no duration
14
14
  def post(event, scope=nil)
15
- begin
16
- scope = scope || Dogapi::Scope.new()
17
- params = {
18
- :api_key => @api_key
19
- }
15
+ scope = scope || Dogapi::Scope.new()
16
+ body = event.to_hash.merge({
17
+ :title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
18
+ :text => event.msg_text[0..MAX_BODY_LENGTH - 1],
19
+ :date_happened => event.date_happened.to_i,
20
+ :host => scope.host,
21
+ :device => scope.device,
22
+ :aggregation_key => event.aggregation_key.to_s
23
+ })
20
24
 
21
- body = event.to_hash.merge({
22
- :title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
23
- :text => event.msg_text[0..MAX_BODY_LENGTH - 1],
24
- :date_happened => event.date_happened.to_i,
25
- :host => scope.host,
26
- :device => scope.device,
27
- :aggregation_key => event.aggregation_key.to_s
28
- })
29
-
30
- request(Net::HTTP::Post, '/api/v1/events', params, body, true)
31
- rescue Exception => e
32
- if @silent
33
- warn e
34
- return -1, {}
35
- else
36
- raise e
37
- end
38
- end
25
+ request(Net::HTTP::Post, '/api/v1/events', nil, body, true, false)
39
26
  end
40
27
 
41
28
  def get(id)
42
- begin
43
- params = {
44
- :api_key => @api_key,
45
- :application_key => @application_key
46
- }
47
-
48
- request(Net::HTTP::Get, '/api/' + API_VERSION + '/events/' + id.to_s, params, nil, false)
49
- rescue Exception => e
50
- if @silent
51
- warn e
52
- return -1, {}
53
- else
54
- raise e
55
- end
56
- end
29
+ request(Net::HTTP::Get, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false)
57
30
  end
58
31
 
59
- def stream(start, stop, options = {})
60
- begin
61
- defaults = {
62
- :priority => nil,
63
- :sources => nil,
64
- :tags => nil
65
- }
66
- options = defaults.merge(options)
67
-
68
- params = {
69
- :api_key => @api_key,
70
- :application_key => @application_key,
32
+ def delete(id)
33
+ request(Net::HTTP::Delete, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false)
34
+ end
71
35
 
72
- :start => start.to_i,
73
- :end => stop.to_i
74
- }
36
+ def stream(start, stop, options= {})
37
+ defaults = {
38
+ :priority => nil,
39
+ :sources => nil,
40
+ :tags => nil
41
+ }
42
+ options = defaults.merge(options)
75
43
 
76
- if options[:priority]
77
- params[:priority] = options[:priority]
78
- end
79
- if options[:sources]
80
- params[:sources] = options[:sources]
81
- end
82
- if options[:tags]
83
- tags = options[:tags]
84
- params[:tags] = tags.kind_of?(Array) ? tags.join(",") : tags
85
- end
44
+ extra_params = {
45
+ :start => start.to_i,
46
+ :end => stop.to_i
47
+ }
86
48
 
87
- request(Net::HTTP::Get, '/api/' + API_VERSION + '/events', params, nil, false)
88
- rescue Exception => e
89
- if @silent
90
- warn e
91
- return -1, {}
92
- else
93
- raise e
94
- end
49
+ if options[:priority]
50
+ extra_params[:priority] = options[:priority]
51
+ end
52
+ if options[:sources]
53
+ extra_params[:sources] = options[:sources]
95
54
  end
55
+ if options[:tags]
56
+ tags = options[:tags]
57
+ extra_params[:tags] = tags.kind_of?(Array) ? tags.join(',') : tags
58
+ end
59
+
60
+ request(Net::HTTP::Get, '/api/' + API_VERSION + '/events', extra_params, nil, false)
96
61
  end
97
62
 
98
63
  end
@@ -6,54 +6,30 @@ module Dogapi
6
6
  # Event-specific client affording more granular control than the simple Dogapi::Client
7
7
  class MetricService < Dogapi::APIService
8
8
 
9
- API_VERSION = "v1"
9
+ API_VERSION = 'v1'
10
10
 
11
11
  def get(query, from, to)
12
- begin
13
- params = {
14
- :api_key => @api_key,
15
- :application_key => @application_key,
16
-
17
- from: from.to_i,
18
- to: to.to_i,
19
- query: query
20
- }
21
- request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', params, nil, false)
22
- rescue Exception => e
23
- if @silent
24
- warn e
25
- return -1, {}
26
- else
27
- raise e
28
- end
29
- end
12
+ extra_params = {
13
+ from: from.to_i,
14
+ to: to.to_i,
15
+ query: query
16
+ }
17
+ request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', extra_params, nil, false)
30
18
  end
31
19
 
32
20
  def upload(metrics)
33
- begin
34
- params = {
35
- :api_key => @api_key
36
- }
37
- body = {
38
- :series => metrics
39
- }
40
- request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true)
41
- rescue Exception => e
42
- if @silent
43
- warn e
44
- return -1, {}
45
- else
46
- raise e
47
- end
48
- end
21
+ body = {
22
+ :series => metrics
23
+ }
24
+ request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', nil, body, true, false)
49
25
  end
50
26
 
51
- def submit_to_api(metric, points, scope, options = {})
27
+ def submit_to_api(metric, points, scope, options= {})
52
28
  payload = self.make_metric_payload(metric, points, scope, options)
53
29
  self.upload([payload])
54
30
  end
55
31
 
56
- def submit_to_buffer(metric, points, scope, options = {})
32
+ def submit_to_buffer(metric, points, scope, options= {})
57
33
  payload = self.make_metric_payload(metric, points, scope, options)
58
34
  @buffer << payload
59
35
  return 200, {}
@@ -83,10 +59,10 @@ module Dogapi
83
59
 
84
60
  def make_metric_payload(metric, points, scope, options)
85
61
  begin
86
- typ = options[:type] || "gauge"
62
+ typ = options[:type] || 'gauge'
87
63
 
88
- if typ != "gauge" && typ != "counter"
89
- raise ArgumentError, "metric type must be gauge or counter"
64
+ if typ != 'gauge' && typ != 'counter'
65
+ raise ArgumentError, 'metric type must be gauge or counter'
90
66
  end
91
67
 
92
68
  metric_payload = {
@@ -104,12 +80,7 @@ module Dogapi
104
80
 
105
81
  return metric_payload
106
82
  rescue Exception => e
107
- if @silent
108
- warn e
109
- return -1, {}
110
- else
111
- raise e
112
- end
83
+ suppress_error_if_silent e
113
84
  end
114
85
  end
115
86
  end