dogapi 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +70 -0
- data/Gemfile +8 -0
- data/LICENSE +25 -0
- data/README.rdoc +5 -79
- data/Rakefile +26 -0
- data/dogapi.gemspec +32 -0
- data/examples/custom_event.rb +37 -0
- data/examples/custom_metric.rb +29 -0
- data/lib/capistrano/datadog.rb +1 -1
- data/lib/dogapi.rb +1 -0
- data/lib/dogapi/common.rb +10 -1
- data/lib/dogapi/facade.rb +4 -4
- data/lib/dogapi/v1/dash.rb +6 -4
- data/lib/dogapi/version.rb +3 -0
- data/tests/test_base.rb +6 -1
- data/tests/test_client.rb +22 -13
- data/tests/test_comments.rb +2 -2
- data/tests/test_dashes.rb +19 -17
- metadata +108 -34
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Changes
|
2
|
+
=======
|
3
|
+
|
4
|
+
# 1.8.1 / 2013-08-22
|
5
|
+
* Update Dash API to support template variables.
|
6
|
+
|
7
|
+
# 1.8.0 / 2013-07-16
|
8
|
+
* Add an API for interacting with Screenboards
|
9
|
+
|
10
|
+
# 1.7.1 / 2013-06-23
|
11
|
+
* Add an API for inviting users
|
12
|
+
* Add an API for taking graph snapshots
|
13
|
+
* Fix bug in capistrano integration with logging of nil (thanks [@arielo][])
|
14
|
+
|
15
|
+
# 1.7.0
|
16
|
+
* Not released.
|
17
|
+
|
18
|
+
# 1.6.0 / 2013-02-19
|
19
|
+
* Support for setting `source` type when submitting host tags
|
20
|
+
|
21
|
+
# 1.5.2 / 2013-02-13
|
22
|
+
* Fix a bug in hashing the Event object when the instance variables are symbols.
|
23
|
+
|
24
|
+
# 1.5.0 / 2012-11-06
|
25
|
+
* Alerting API
|
26
|
+
|
27
|
+
# 1.4.3
|
28
|
+
* Fix bug with capistrano integration for capistrano 2.13.5 (thanks [@ansel1][])
|
29
|
+
|
30
|
+
# 1.4.2
|
31
|
+
* Added missing dashboards endpoint.
|
32
|
+
|
33
|
+
# 1.4.1
|
34
|
+
* Fixed searching for events with tags.
|
35
|
+
|
36
|
+
# 1.4.0
|
37
|
+
* Added support for the dashboard, search and comment API endpoints.
|
38
|
+
|
39
|
+
# 1.3.6
|
40
|
+
* Small fix for capistrano integration
|
41
|
+
|
42
|
+
# 1.3.4
|
43
|
+
* Various bug fixes (event.to_hash, md5 import, capistrano lambda roles)
|
44
|
+
|
45
|
+
# 1.3.3
|
46
|
+
* Bug fix for submitting counters
|
47
|
+
|
48
|
+
# 1.3.2
|
49
|
+
* Support an aggregation key to aggregate events together
|
50
|
+
|
51
|
+
# 1.3.1
|
52
|
+
* Metrics can be counters, rather than just gauges (thanks to [@treeder][])
|
53
|
+
* Metrics can be tagged.
|
54
|
+
|
55
|
+
# 1.3.0
|
56
|
+
* Capistrano integration. See https://github.com/DataDog/dogapi-rb/tree/master/lib/capistrano
|
57
|
+
|
58
|
+
# 1.2.x
|
59
|
+
* You can now manage host tags
|
60
|
+
* You can now get event details and query the stream in addition to posting events
|
61
|
+
* Functionality relating to events with a duration has been deprecated
|
62
|
+
* The underlying clients have been updated to use Datadog's new public HTTP API[https://github.com/DataDog/dogapi/wiki]
|
63
|
+
|
64
|
+
# 1.1.x
|
65
|
+
* You do not need to use environment variables anymore to use the client.
|
66
|
+
|
67
|
+
<!--- The following link definition list is generated by PimpMyChangelog --->
|
68
|
+
[@ansel1]: https://github.com/ansel1
|
69
|
+
[@arielo]: https://github.com/arielo
|
70
|
+
[@treeder]: https://github.com/treeder
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2011, Datadog <info@datadoghq.com>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the Datadog nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL DATADOG BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
data/README.rdoc
CHANGED
@@ -1,85 +1,11 @@
|
|
1
1
|
= Ruby client for Datadog API v1.8.0
|
2
|
+
{<img src="https://travis-ci.org/DataDog/dogapi-rb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/DataDog/dogapi-rb]
|
2
3
|
|
3
4
|
The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog's raw HTTP interface for reporting events and metrics.
|
4
5
|
|
5
6
|
= What's new?
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
* Add an API for interacting with Screenboards
|
10
|
-
|
11
|
-
== v1.7.1
|
12
|
-
|
13
|
-
* Add an API for inviting users
|
14
|
-
* Add an API for taking graph snapshots
|
15
|
-
* Fix bug in capistrano integration with logging of nil (thanks @arielo)
|
16
|
-
|
17
|
-
== v1.7.0
|
18
|
-
|
19
|
-
* Not released.
|
20
|
-
|
21
|
-
== v1.6.0
|
22
|
-
|
23
|
-
* Support for setting `source` type when submitting host tags
|
24
|
-
|
25
|
-
== v1.5.2
|
26
|
-
* Fix a bug in hashing the Event object when the instance variables are symbols.
|
27
|
-
|
28
|
-
== v1.5.0
|
29
|
-
|
30
|
-
* Alerting API
|
31
|
-
|
32
|
-
== v1.4.3
|
33
|
-
|
34
|
-
* Fix bug with capistrano integration for capistrano 2.13.5 (thanks @ansel1)
|
35
|
-
|
36
|
-
== v1.4.2
|
37
|
-
|
38
|
-
* Added missing dashboards endpoint.
|
39
|
-
|
40
|
-
== v1.4.1
|
41
|
-
|
42
|
-
* Fixed searching for events with tags.
|
43
|
-
|
44
|
-
== v1.4.0
|
45
|
-
|
46
|
-
* Added support for the dashboard, search and comment API endpoints.
|
47
|
-
|
48
|
-
== v1.3.6
|
49
|
-
|
50
|
-
* Small fix for capistrano integration
|
51
|
-
|
52
|
-
== v1.3.4
|
53
|
-
|
54
|
-
* Various bug fixes (event.to_hash, md5 import, capistrano lambda roles)
|
55
|
-
|
56
|
-
== v1.3.3
|
57
|
-
|
58
|
-
* Bug fix for submitting counters
|
59
|
-
|
60
|
-
== v1.3.2
|
61
|
-
|
62
|
-
* Support an aggregation key to aggregate events together
|
63
|
-
|
64
|
-
== v1.3.1
|
65
|
-
|
66
|
-
* Metrics can be counters, rather than just gauges (thanks to @treeder)
|
67
|
-
* Metrics can be tagged.
|
68
|
-
|
69
|
-
== v1.3.0
|
70
|
-
|
71
|
-
* Capistrano integration. See https://github.com/DataDog/dogapi-rb/tree/master/lib/capistrano
|
72
|
-
|
73
|
-
== v1.2.x
|
74
|
-
|
75
|
-
* You can now manage host tags
|
76
|
-
* You can now get event details and query the stream in addition to posting events
|
77
|
-
* Functionality relating to events with a duration has been deprecated
|
78
|
-
* The underlying clients have been updated to use Datadog's new public HTTP API[https://github.com/DataDog/dogapi/wiki]
|
79
|
-
|
80
|
-
== v1.1.x
|
81
|
-
|
82
|
-
* You do not need to use environment variables anymore to use the client.
|
8
|
+
See CHANGELOG.md for details
|
83
9
|
|
84
10
|
= Installation
|
85
11
|
|
@@ -88,8 +14,8 @@ The Ruby client is a library suitable for inclusion in existing Ruby projects or
|
|
88
14
|
Available at: https://github.com/DataDog/dogapi-rb
|
89
15
|
|
90
16
|
$ cd dogapi-rb
|
91
|
-
$
|
92
|
-
$
|
17
|
+
$ bundle
|
18
|
+
$ rake install
|
93
19
|
|
94
20
|
== Using RubyGems
|
95
21
|
|
@@ -103,7 +29,7 @@ If you get a permission error, you might need to run the install process with su
|
|
103
29
|
|
104
30
|
If you get a LoadError, missing mkmf, you need to install the development packages for ruby.
|
105
31
|
|
106
|
-
|
32
|
+
# on ubuntu e.g.
|
107
33
|
$ sudo apt-get install ruby-dev
|
108
34
|
|
109
35
|
= Usage
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
# Assign some test keys if they aren't already set.
|
6
|
+
ENV["DATADOG_API_KEY"] ||= '9775a026f1ca7d1c6c5af9d94d9595a4'
|
7
|
+
ENV["DATADOG_APP_KEY"] ||= '87ce4a24b5553d2e482ea8a8500e71b8ad4554ff'
|
8
|
+
|
9
|
+
task :default => [:test]
|
10
|
+
|
11
|
+
Rake::TestTask.new(:test) do |test|
|
12
|
+
test.libs.push 'lib'
|
13
|
+
test.libs.push 'tests'
|
14
|
+
test.test_files = FileList['tests/test_*.rb']
|
15
|
+
end
|
16
|
+
|
17
|
+
# Doc stuff
|
18
|
+
RDoc::Task.new do |rd|
|
19
|
+
rd.main = 'README.rdoc'
|
20
|
+
rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'CHANGELOG.md')
|
21
|
+
rd.options << '--line-numbers' << '--inline-source'
|
22
|
+
rd.rdoc_dir = 'doc'
|
23
|
+
rd.title = 'DogAPI -- DataDog Client'
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => [:test]
|
data/dogapi.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dogapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dogapi'
|
8
|
+
spec.version = Dogapi::VERSION
|
9
|
+
spec.authors = ['Datadog, Inc.']
|
10
|
+
spec.email = ['packages@datadoghq.com']
|
11
|
+
spec.description = 'Ruby bindings for Datadog\'s API'
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'http://datadoghq.com/'
|
14
|
+
spec.license = 'BSD'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($\)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.has_rdoc = true
|
22
|
+
spec.extra_rdoc_files = ['README.rdoc']
|
23
|
+
spec.rdoc_options << '--title' << 'DogAPI -- Datadog Client' <<
|
24
|
+
'--main' << 'README.rdoc' <<
|
25
|
+
'--line-numbers' << '--inline-source'
|
26
|
+
|
27
|
+
spec.add_dependency 'json', '>= 1.5.1'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10'
|
31
|
+
spec.add_development_dependency 'rdoc'
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'dogapi'
|
3
|
+
|
4
|
+
# Create a simple client
|
5
|
+
# The host is optional here, it's a shortcut to tie event and metrics to a given host
|
6
|
+
#
|
7
|
+
# You typically want to do:
|
8
|
+
# Dogapi::Client.new(your_actual_api_key_as_a_string, ...)
|
9
|
+
# We are using ENV to let you experiment via an environment variable.
|
10
|
+
dog = Dogapi::Client.new(ENV['DATADOG_KEY'])
|
11
|
+
|
12
|
+
# Let's use tags and aggregation
|
13
|
+
# We will send 2 related events, one error and one success.
|
14
|
+
|
15
|
+
dog.emit_event(Dogapi::Event.new("Uh-oh, something bad happened",
|
16
|
+
:msg_title => "Alert! Alert!",
|
17
|
+
:aggregation_key => "job-123",
|
18
|
+
:alert_type => "error",
|
19
|
+
:tags => ["ruby", "dogapi"]
|
20
|
+
))
|
21
|
+
|
22
|
+
dog.emit_event(Dogapi::Event.new("Now that's better",
|
23
|
+
:msg_title => "All systems green",
|
24
|
+
:aggregation_key => "job-123",
|
25
|
+
:alert_type => "success",
|
26
|
+
:tags => ["ruby", "dogapi"]
|
27
|
+
))
|
28
|
+
|
29
|
+
# You should see something like this in your stream:
|
30
|
+
# screenshot: https://img.skitch.com/20120705-3s4icgxfc689x1jtrx1yr1m5k.png
|
31
|
+
|
32
|
+
# And if you graph a metric and want to overlay these events on the graphs
|
33
|
+
# You can use the following query: "tags:dogapi tags:ruby" in the graph editor
|
34
|
+
# screenshot: https://img.skitch.com/20120705-m4h6f4377cbm2d3rctnd6biej9.png
|
35
|
+
|
36
|
+
# Then you can see the events neatly overlaid on your graph
|
37
|
+
# screenshot: https://img.skitch.com/20120705-xybhimti31u4s4m42ac854568h.png
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'dogapi'
|
3
|
+
|
4
|
+
# Create a simple client
|
5
|
+
# The host is optional here, it's a shortcut to tie event and metrics to a given host
|
6
|
+
#
|
7
|
+
# You typically want to do:
|
8
|
+
# Dogapi::Client.new(your_actual_api_key_as_a_string, ...)
|
9
|
+
# We are using ENV to let you experiment via an environment variable.
|
10
|
+
dog = Dogapi::Client.new(ENV['DATADOG_KEY'])
|
11
|
+
|
12
|
+
# Emit points one by one, timestamp is omitted and is the time this call is made.
|
13
|
+
dog.emit_point('test.api.test_metric', 4.0)
|
14
|
+
|
15
|
+
sleep 1
|
16
|
+
|
17
|
+
dog.emit_point('test.api.test_metric', 5.0)
|
18
|
+
|
19
|
+
# Emit a list of points in one go as a list of (timestamp, value)
|
20
|
+
# here we pretend to send a point a minute for the past hour
|
21
|
+
now = Time.now
|
22
|
+
points = (0...60).map do |i|
|
23
|
+
i = 60 - i
|
24
|
+
t = now - (i*60)
|
25
|
+
[t, Math.cos(i) + 1.0]
|
26
|
+
end
|
27
|
+
|
28
|
+
# And emit the data in one call
|
29
|
+
dog.emit_points('test.api.test_metric', points)
|
data/lib/capistrano/datadog.rb
CHANGED
data/lib/dogapi.rb
CHANGED
data/lib/dogapi/common.rb
CHANGED
@@ -150,7 +150,16 @@ module Dogapi
|
|
150
150
|
ENV["DATADOG_HOST"] || "https://app.datadoghq.com"
|
151
151
|
end
|
152
152
|
|
153
|
+
# Memoize the hostname as a module variable
|
154
|
+
@@hostname = nil
|
155
|
+
|
153
156
|
def Dogapi.find_localhost
|
154
|
-
|
157
|
+
begin
|
158
|
+
# prefer hostname -f over Socket.gethostname
|
159
|
+
@@hostname ||= %x[hostname -f].strip
|
160
|
+
rescue
|
161
|
+
raise "Cannot determine local hostname via hostname -f"
|
162
|
+
end
|
155
163
|
end
|
164
|
+
|
156
165
|
end
|
data/lib/dogapi/facade.rb
CHANGED
@@ -220,13 +220,13 @@ module Dogapi
|
|
220
220
|
#
|
221
221
|
|
222
222
|
# Create a dashboard.
|
223
|
-
def create_dashboard(title, description, graphs)
|
224
|
-
@dash_service.create_dashboard(title, description, graphs)
|
223
|
+
def create_dashboard(title, description, graphs, template_variables=nil)
|
224
|
+
@dash_service.create_dashboard(title, description, graphs, template_variables)
|
225
225
|
end
|
226
226
|
|
227
227
|
# Update a dashboard.
|
228
|
-
def update_dashboard(dash_id, title, description, graphs)
|
229
|
-
@dash_service.update_dashboard(dash_id, title, description, graphs)
|
228
|
+
def update_dashboard(dash_id, title, description, graphs, template_variables=nil)
|
229
|
+
@dash_service.update_dashboard(dash_id, title, description, graphs, template_variables)
|
230
230
|
end
|
231
231
|
|
232
232
|
# Fetch the given dashboard.
|
data/lib/dogapi/v1/dash.rb
CHANGED
@@ -7,7 +7,7 @@ module Dogapi
|
|
7
7
|
|
8
8
|
API_VERSION = "v1"
|
9
9
|
|
10
|
-
def create_dashboard(title, description, graphs)
|
10
|
+
def create_dashboard(title, description, graphs, template_variables=nil)
|
11
11
|
|
12
12
|
begin
|
13
13
|
params = {
|
@@ -18,7 +18,8 @@ module Dogapi
|
|
18
18
|
body = {
|
19
19
|
:title => title,
|
20
20
|
:description => description,
|
21
|
-
:graphs => graphs
|
21
|
+
:graphs => graphs,
|
22
|
+
:template_variables => (template_variables or [])
|
22
23
|
}
|
23
24
|
|
24
25
|
request(Net::HTTP::Post, "/api/#{API_VERSION}/dash", params, body, true)
|
@@ -27,7 +28,7 @@ module Dogapi
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def update_dashboard(dash_id, title, description, graphs)
|
31
|
+
def update_dashboard(dash_id, title, description, graphs, template_variables=nil)
|
31
32
|
|
32
33
|
begin
|
33
34
|
params = {
|
@@ -38,7 +39,8 @@ module Dogapi
|
|
38
39
|
body = {
|
39
40
|
:title => title,
|
40
41
|
:description => description,
|
41
|
-
:graphs => graphs
|
42
|
+
:graphs => graphs,
|
43
|
+
:template_variables => (template_variables or [])
|
42
44
|
}
|
43
45
|
|
44
46
|
request(Net::HTTP::Put, "/api/#{API_VERSION}/dash/#{dash_id}", params, body, true)
|
data/tests/test_base.rb
CHANGED
@@ -21,5 +21,10 @@ module TestBase
|
|
21
21
|
Kernel.rand 100000
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
def job_number
|
25
|
+
# Get the Travis ENV and use that to 'seed' the dashboard titles, in attempt
|
26
|
+
# to prevent parallel testing conflicts
|
27
|
+
job_number = ENV['TRAVIS_JOB_NUMBER'] || '1'
|
28
|
+
end
|
25
29
|
|
30
|
+
end
|
data/tests/test_client.rb
CHANGED
@@ -5,8 +5,15 @@ require 'test_base.rb'
|
|
5
5
|
class TestClient < Test::Unit::TestCase
|
6
6
|
include TestBase
|
7
7
|
|
8
|
+
def test_find_localhost
|
9
|
+
# Must be an FQDN
|
10
|
+
assert Dogapi.find_localhost.index(".") > 0
|
11
|
+
assert Dogapi.find_localhost.split(".").length > 1
|
12
|
+
assert Dogapi.find_localhost == %x[hostname -f].strip
|
13
|
+
end
|
14
|
+
|
8
15
|
def test_tags
|
9
|
-
hostname = "test.tag.host.#{
|
16
|
+
hostname = "test.tag.host.#{job_number}"
|
10
17
|
dog = Dogapi::Client.new(@api_key, @app_key)
|
11
18
|
|
12
19
|
# post a metric to make sure the test host context exists
|
@@ -50,7 +57,9 @@ class TestClient < Test::Unit::TestCase
|
|
50
57
|
def test_events
|
51
58
|
now = Time.now()
|
52
59
|
|
53
|
-
|
60
|
+
# Tag the events with the build number, because Travis parallel testing
|
61
|
+
# can cause problems with the event stream
|
62
|
+
tags = ["test-run:#{job_number}"]
|
54
63
|
|
55
64
|
now_ts = now
|
56
65
|
now_title = 'dogapi-rb end test title ' + now_ts.to_i.to_s
|
@@ -63,40 +72,40 @@ class TestClient < Test::Unit::TestCase
|
|
63
72
|
dog = Dogapi::Client.new(@api_key, @app_key)
|
64
73
|
dog_r = Dogapi::Client.new(@api_key)
|
65
74
|
|
66
|
-
|
67
|
-
|
68
|
-
e2 = Dogapi::Event.new(before_message, :msg_title =>before_title,
|
69
|
-
|
75
|
+
e1 = Dogapi::Event.new(now_message, :msg_title => now_title,
|
76
|
+
:date_happened => now_ts, :tags => tags)
|
77
|
+
e2 = Dogapi::Event.new(before_message, :msg_title => before_title,
|
78
|
+
:date_happened => before_ts, :tags => tags)
|
70
79
|
|
71
80
|
code, resp = dog_r.emit_event(e1)
|
72
81
|
now_event_id = resp["event"]["id"]
|
73
82
|
code, resp = dog_r.emit_event(e2)
|
74
83
|
before_event_id = resp["event"]["id"]
|
75
84
|
|
76
|
-
sleep
|
85
|
+
sleep 5
|
77
86
|
|
78
87
|
code, resp = dog.stream(before_ts, now_ts + 1, :tags => tags)
|
79
88
|
stream = resp["events"]
|
80
89
|
|
81
|
-
assert_equal 2, stream.length()
|
82
|
-
assert_equal stream.last['title'], before_title
|
83
|
-
assert_equal stream.first['title'], now_title
|
84
|
-
|
85
90
|
code, resp = dog.get_event(now_event_id)
|
91
|
+
assert !resp['event'].nil?
|
86
92
|
now_event = resp['event']
|
93
|
+
|
87
94
|
code, resp = dog.get_event(before_event_id)
|
95
|
+
assert !resp['event'].nil?
|
88
96
|
before_event = resp['event']
|
89
97
|
|
90
98
|
assert now_event['text'] == now_message
|
91
99
|
assert before_event['text'] == before_message
|
92
100
|
|
93
101
|
# Testing priorities
|
94
|
-
code, resp = dog_r.emit_event(Dogapi::Event.new(now_message, :msg_title =>now_title, :date_happened => now_ts, :priority => "low"))
|
102
|
+
code, resp = dog_r.emit_event(Dogapi::Event.new(now_message, :msg_title => now_title, :date_happened => now_ts, :priority => "low"))
|
95
103
|
low_event_id = resp["event"]["id"]
|
96
104
|
|
97
|
-
sleep
|
105
|
+
sleep 5
|
98
106
|
|
99
107
|
code, resp = dog.get_event(low_event_id)
|
108
|
+
assert !resp['event'].nil?
|
100
109
|
low_event = resp['event']
|
101
110
|
assert low_event['priority'] == "low"
|
102
111
|
|
data/tests/test_comments.rb
CHANGED
@@ -16,12 +16,12 @@ class TestComments < Test::Unit::TestCase
|
|
16
16
|
handle = "carlo+14.1@datadoghq.com"
|
17
17
|
status, comment_response = dog.comment('test comment with handle', :handle => handle)
|
18
18
|
comment = comment_response["comment"]
|
19
|
-
assert_equal "200", status, "Comment did not succeed"
|
19
|
+
assert_equal "200", status, "Comment did not succeed, response: #{comment_response}"
|
20
20
|
|
21
21
|
# Reply to a comment.
|
22
22
|
status, reply_response = dog.comment('replying!', :related_event_id => comment["id"])
|
23
23
|
reply = reply_response["comment"]
|
24
|
-
assert_equal "200", status, "Reply did not work
|
24
|
+
assert_equal "200", status, "Reply did not work, response: #{reply_response}"
|
25
25
|
# HACK: issue #900 on dogweb. id types should be the same.
|
26
26
|
assert_equal comment["id"].to_s, reply["related_event_id"]
|
27
27
|
|
data/tests/test_dashes.rb
CHANGED
@@ -9,73 +9,75 @@ class TestDashes < Test::Unit::TestCase
|
|
9
9
|
dog = Dogapi::Client.new(@api_key, @app_key)
|
10
10
|
|
11
11
|
# Create a dashboard.
|
12
|
-
title =
|
12
|
+
title = "foobar-#{job_number}"
|
13
13
|
description = 'desc'
|
14
14
|
graphs = [{
|
15
15
|
"definition" => {
|
16
16
|
"events" => [],
|
17
|
-
"requests
|
17
|
+
"requests" => [
|
18
18
|
{"q" => "avg:system.mem.free{*}"}
|
19
19
|
],
|
20
|
-
|
20
|
+
"viz" => "timeseries"
|
21
21
|
},
|
22
22
|
"title" => "Average Memory Free"
|
23
23
|
}]
|
24
24
|
|
25
25
|
status, dash_response = dog.create_dashboard(title, description, graphs)
|
26
|
-
assert_equal "200", status, "Creation failed"
|
26
|
+
assert_equal "200", status, "Creation failed, response: #{dash_response}"
|
27
27
|
|
28
28
|
dash_id = dash_response["dash"]["id"]
|
29
29
|
|
30
30
|
# Fetch the dashboard and assert all is well.
|
31
31
|
status, dash_response = dog.get_dashboard(dash_id)
|
32
|
-
assert_equal "200", status, "Fetch failed"
|
32
|
+
assert_equal "200", status, "Fetch failed, response: #{dash_response}"
|
33
33
|
dash = dash_response["dash"]
|
34
34
|
assert_equal title, dash["title"]
|
35
35
|
assert_equal description, dash["description"]
|
36
36
|
assert_equal graphs, dash["graphs"]
|
37
37
|
|
38
38
|
# Update the dashboard.
|
39
|
-
title =
|
39
|
+
title = "blahfoobar-#{job_number}"
|
40
40
|
description = 'asdfdesc'
|
41
41
|
graphs = [{
|
42
42
|
"definition" => {
|
43
43
|
"events" => [],
|
44
|
-
"requests
|
44
|
+
"requests" => [
|
45
45
|
{"q" => "sum:system.mem.free{*}"}
|
46
46
|
],
|
47
|
-
|
47
|
+
"viz" => "timeseries"
|
48
48
|
},
|
49
49
|
"title" => "Sum Memory Free"
|
50
50
|
}]
|
51
|
+
tpl_vars = ["foo", "bar"]
|
51
52
|
|
52
|
-
status, dash_response = dog.update_dashboard(dash_id, title, description, graphs)
|
53
|
-
assert_equal "200", status, "Updated failed"
|
53
|
+
status, dash_response = dog.update_dashboard(dash_id, title, description, graphs, tpl_vars)
|
54
|
+
assert_equal "200", status, "Updated failed, response: #{dash_response}"
|
54
55
|
|
55
56
|
# Fetch the dashboard and assert all is well.
|
56
57
|
status, dash_response = dog.get_dashboard(dash_id)
|
57
|
-
assert_equal "200", status, "Fetch failed"
|
58
|
+
assert_equal "200", status, "Fetch failed, response: #{dash_response}"
|
58
59
|
dash = dash_response["dash"]
|
59
60
|
assert_equal title, dash["title"]
|
60
61
|
assert_equal description, dash["description"]
|
61
62
|
assert_equal graphs, dash["graphs"]
|
63
|
+
assert_equal tpl_vars, dash["template_variables"]
|
62
64
|
|
63
|
-
# Fetch all the dashboards
|
65
|
+
# Fetch all the dashboards, assert our created one is in the list of all
|
64
66
|
status, dash_response = dog.get_dashboards()
|
65
|
-
assert_equal "200", status, "fetch failed"
|
67
|
+
assert_equal "200", status, "fetch failed, response: #{dash_response}"
|
66
68
|
dashes = dash_response["dashes"]
|
67
|
-
assert dashes.
|
68
|
-
dash = dashes.
|
69
|
+
assert dashes.any? { |d| title == d["title"] }
|
70
|
+
dash = dashes.find { |d| title == d["title"] }
|
69
71
|
assert_equal title, dash["title"]
|
70
72
|
assert_equal dash_id.to_s, dash["id"]
|
71
73
|
|
72
74
|
# Delete the dashboard.
|
73
75
|
status, dash_response = dog.delete_dashboard(dash_id)
|
74
|
-
assert_equal "204", status, "Deleted failed"
|
76
|
+
assert_equal "204", status, "Deleted failed, response: #{dash_response}"
|
75
77
|
|
76
78
|
# Fetch the dashboard and assert all it's gone.
|
77
79
|
status, dash_response = dog.get_dashboard(dash_id)
|
78
|
-
assert_equal "404", status, "Still there failed"
|
80
|
+
assert_equal "404", status, "Still there failed, response: #{dash_response}"
|
79
81
|
|
80
82
|
end
|
81
83
|
end
|
metadata
CHANGED
@@ -1,34 +1,101 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogapi
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 8
|
9
|
+
- 1
|
10
|
+
version: 1.8.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Datadog, Inc.
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2013-08-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: json
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 1
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 5
|
32
|
+
- 1
|
21
33
|
version: 1.5.1
|
22
34
|
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 9
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 3
|
48
|
+
version: "1.3"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rake
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 10
|
62
|
+
version: "10"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rdoc
|
23
67
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
79
|
+
description: Ruby bindings for Datadog's API
|
80
|
+
email:
|
81
|
+
- packages@datadoghq.com
|
27
82
|
executables: []
|
83
|
+
|
28
84
|
extensions: []
|
29
|
-
|
85
|
+
|
86
|
+
extra_rdoc_files:
|
87
|
+
- README.rdoc
|
88
|
+
files:
|
89
|
+
- .gitignore
|
90
|
+
- .travis.yml
|
91
|
+
- CHANGELOG.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
30
94
|
- README.rdoc
|
31
|
-
|
95
|
+
- Rakefile
|
96
|
+
- dogapi.gemspec
|
97
|
+
- examples/custom_event.rb
|
98
|
+
- examples/custom_metric.rb
|
32
99
|
- lib/capistrano/README.md
|
33
100
|
- lib/capistrano/datadog.rb
|
34
101
|
- lib/dogapi.rb
|
@@ -47,6 +114,7 @@ files:
|
|
47
114
|
- lib/dogapi/v1/snapshot.rb
|
48
115
|
- lib/dogapi/v1/tag.rb
|
49
116
|
- lib/dogapi/v1/user.rb
|
117
|
+
- lib/dogapi/version.rb
|
50
118
|
- tests/test_alerts.rb
|
51
119
|
- tests/test_base.rb
|
52
120
|
- tests/test_client.rb
|
@@ -56,37 +124,43 @@ files:
|
|
56
124
|
- tests/test_search.rb
|
57
125
|
- tests/test_snapshot.rb
|
58
126
|
- tests/test_users.rb
|
59
|
-
- README.rdoc
|
60
127
|
homepage: http://datadoghq.com/
|
61
|
-
licenses:
|
128
|
+
licenses:
|
62
129
|
- BSD
|
63
130
|
post_install_message:
|
64
|
-
rdoc_options:
|
131
|
+
rdoc_options:
|
65
132
|
- --title
|
66
|
-
- DogAPI --
|
133
|
+
- DogAPI -- Datadog Client
|
67
134
|
- --main
|
68
135
|
- README.rdoc
|
69
136
|
- --line-numbers
|
70
137
|
- --inline-source
|
71
|
-
require_paths:
|
138
|
+
require_paths:
|
72
139
|
- lib
|
73
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
141
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
150
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
85
158
|
requirements: []
|
159
|
+
|
86
160
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.8.
|
161
|
+
rubygems_version: 1.8.15
|
88
162
|
signing_key:
|
89
163
|
specification_version: 3
|
90
164
|
summary: Ruby bindings for Datadog's API
|
91
|
-
test_files:
|
92
|
-
|
165
|
+
test_files: []
|
166
|
+
|