lita-datadog 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.travis.yml +1 -1
- data/README.md +18 -1
- data/lib/lita/handlers/datadog.rb +27 -11
- data/lita-datadog.gemspec +2 -1
- data/spec/lita/handlers/datadog_spec.rb +39 -8
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd4e57520c88208a94b5c25e9097ddb937434faa
|
4
|
+
data.tar.gz: 83cb05a53cfc3fb0a92599d4ca5bf9aa3423c6fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b69e3ff4a8a1929187424cef95957ee6dfcc7644fc9cf631bb0cd2438368c87eff14e628377e4fec97678b2db03e22434075ce63905d29a6423bee507c27757
|
7
|
+
data.tar.gz: 146518897c2d1ce891f12f0ddbaf27b130895e5f7be0ef40e03b75d1fe84f404b8178781ca54db09c5e6d7cdad4b47bd84c17c922c00589ffdc45b460388d0b6
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,8 @@ You will need to get your API key, and configure an application key. Go to http
|
|
25
25
|
|
26
26
|
### Optional attributes
|
27
27
|
|
28
|
-
* `
|
28
|
+
* `timerange` (Integer) - How long in seconds a time range will be for graphs. Default: `3600`
|
29
|
+
* `waittime` (Integer) - How long to wait after getting a URL from Datadog to display it (sometimes the graph isn't ready yet). Default: `1`
|
29
30
|
|
30
31
|
### Example
|
31
32
|
|
@@ -33,9 +34,25 @@ You will need to get your API key, and configure an application key. Go to http
|
|
33
34
|
|
34
35
|
```
|
35
36
|
Lita graph metric:"system.load.1{*}"
|
37
|
+
Lita graph metric:"system.load.1{host:hostname01}"
|
36
38
|
Lita graph metric:"system.load.1{*},system.load.5{*}"
|
39
|
+
Lita graph metric:"system.load.1{*}" event:"sources:sourcename"
|
40
|
+
Lita graph metric:"system.load.1{*}" start:"2 hours ago"
|
41
|
+
Lita graph metric:"system.load.1{*}" from:"2 hours ago" to:"30 minutes ago"
|
37
42
|
```
|
38
43
|
|
44
|
+
Graph takes the following arguments:
|
45
|
+
```
|
46
|
+
metric:"<metric>"
|
47
|
+
event:"<event>"
|
48
|
+
start:"<time description>"
|
49
|
+
end:"<time description>"
|
50
|
+
from:"<time description>"
|
51
|
+
to:"<time description>"
|
52
|
+
```
|
53
|
+
|
54
|
+
Time descriptions are parsed by https://github.com/mojombo/chronic
|
55
|
+
|
39
56
|
## License
|
40
57
|
|
41
58
|
[MIT](http://opensource.org/licenses/MIT)
|
@@ -1,29 +1,30 @@
|
|
1
1
|
require 'dogapi'
|
2
|
+
require 'chronic'
|
2
3
|
|
3
4
|
module Lita
|
4
5
|
module Handlers
|
5
6
|
class Datadog < Handler
|
6
7
|
route(
|
7
|
-
/^graph\
|
8
|
-
:
|
8
|
+
/^graph\s(.*)$/,
|
9
|
+
:graph,
|
9
10
|
command: true,
|
10
11
|
help: { 'graph metric:"simple.metric.1{*},simple.metric.5{*}"' =>
|
11
|
-
'Graph those metrics
|
12
|
+
'Graph those metrics, for the default time range' }
|
12
13
|
)
|
13
14
|
|
14
15
|
def self.default_config(config)
|
15
16
|
config.api_key = nil
|
16
17
|
config.application_key = nil
|
17
|
-
config.
|
18
|
+
config.timerange = 3600
|
19
|
+
config.waittime = 1
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
sleep 1 # TODO: Requesting the image immediately causes a blank image to be cached.
|
22
|
+
def graph(response)
|
23
|
+
args = parse_arguments(response.matches[0][0])
|
24
|
+
return_code, snapshot = graph_snapshot(args[:metric], args[:start],
|
25
|
+
args[:end], args[:event])
|
26
|
+
if return_code.to_s == '200'
|
27
|
+
sleep Lita.config.handlers.datadog.waittime
|
27
28
|
response.reply(snapshot['snapshot_url'])
|
28
29
|
else
|
29
30
|
response.reply('Error requesting Datadog graph')
|
@@ -41,6 +42,21 @@ module Lita
|
|
41
42
|
|
42
43
|
return client.graph_snapshot(metric_query, start_ts, end_ts, event_query) if client
|
43
44
|
end
|
45
|
+
|
46
|
+
def parse_arguments(arg_string)
|
47
|
+
end_m = /(to|end):"(.+?)"/.match(arg_string)
|
48
|
+
end_ts = end_m ? Chronic.parse(end_m[2]).to_i : Time.now.to_i
|
49
|
+
start_m = /(from|start):"(.+?)"/.match(arg_string)
|
50
|
+
start_ts = start_m ? Chronic.parse(start_m[2]).to_i : end_ts - Lita.config.handlers.datadog.timerange
|
51
|
+
metric_m = /metric:"(.+?)"/.match(arg_string)
|
52
|
+
metric = metric_m ? metric_m[1] : 'system.load.1{*}'
|
53
|
+
event_m = /event:"(.+?)"/.match(arg_string)
|
54
|
+
event = event_m ? event_m[1] : ''
|
55
|
+
{ metric: metric,
|
56
|
+
start: start_ts,
|
57
|
+
end: end_ts,
|
58
|
+
event: event }
|
59
|
+
end
|
44
60
|
end
|
45
61
|
|
46
62
|
Lita.register_handler(Datadog)
|
data/lita-datadog.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-datadog"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.2.0"
|
4
4
|
spec.authors = ["Eric Sigler"]
|
5
5
|
spec.email = ["me@esigler.com"]
|
6
6
|
spec.description = %q{A Lita handler for interacting with Datadog}
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 3.0"
|
18
18
|
spec.add_runtime_dependency "dogapi"
|
19
|
+
spec.add_runtime_dependency "chronic"
|
19
20
|
|
20
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
22
|
spec.add_development_dependency "rake"
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Lita::Handlers::Datadog, lita_handler: true do
|
4
|
-
|
5
|
-
|
4
|
+
EXAMPLE_IMAGE_URL = 'http://www.example.com/path/that/ends/in.png'
|
5
|
+
EXAMPLE_ERROR_MSG = 'Error requesting Datadog graph'
|
6
|
+
|
7
|
+
it { routes_command('graph metric:"system.load.1{*}"').to(:graph) }
|
8
|
+
it { routes_command('graph metric:"system.load.1{host:hostname01}"').to(:graph) }
|
9
|
+
it { routes_command('graph metric:"system.load.1{*},system.load.5{*}"').to(:graph) }
|
10
|
+
it { routes_command('graph metric:"system.load.1{*}" event:"sources:something"').to(:graph) }
|
6
11
|
|
7
12
|
describe '.default_config' do
|
8
13
|
it 'sets the api_key to nil' do
|
@@ -13,25 +18,51 @@ describe Lita::Handlers::Datadog, lita_handler: true do
|
|
13
18
|
expect(Lita.config.handlers.datadog.application_key).to be_nil
|
14
19
|
end
|
15
20
|
|
16
|
-
it 'sets the
|
17
|
-
expect(Lita.config.handlers.datadog.
|
21
|
+
it 'sets the timerange to 3600' do
|
22
|
+
expect(Lita.config.handlers.datadog.timerange).to eq(3600)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the waittime to 1' do
|
26
|
+
expect(Lita.config.handlers.datadog.waittime).to eq(1)
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
describe '#
|
30
|
+
describe '#graph' do
|
22
31
|
it 'with valid metric returns an image url' do
|
23
|
-
response = { 'snapshot_url' =>
|
32
|
+
response = { 'snapshot_url' => EXAMPLE_IMAGE_URL }
|
24
33
|
allow_any_instance_of(Lita::Handlers::Datadog).to \
|
25
34
|
receive(:graph_snapshot).with(any_args).and_return([200, response])
|
26
35
|
send_command('graph metric:"system.load.1{*}"')
|
27
|
-
expect(replies.last).to eq(
|
36
|
+
expect(replies.last).to eq(EXAMPLE_IMAGE_URL)
|
28
37
|
end
|
29
38
|
|
30
39
|
it 'with invalid metric returns an error' do
|
31
40
|
allow_any_instance_of(Lita::Handlers::Datadog).to \
|
32
41
|
receive(:graph_snapshot).with(any_args).and_return([500, nil])
|
33
42
|
send_command('graph metric:"omg.wtf.bbq{*}"')
|
34
|
-
expect(replies.last).to eq(
|
43
|
+
expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'with valid metric and event returns an image url' do
|
47
|
+
response = { 'snapshot_url' => EXAMPLE_IMAGE_URL }
|
48
|
+
allow_any_instance_of(Lita::Handlers::Datadog).to \
|
49
|
+
receive(:graph_snapshot).with(any_args).and_return([200, response])
|
50
|
+
send_command('graph metric:"system.load.1{*}"')
|
51
|
+
expect(replies.last).to eq(EXAMPLE_IMAGE_URL)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'with an invalid metric returns an error' do
|
55
|
+
allow_any_instance_of(Lita::Handlers::Datadog).to \
|
56
|
+
receive(:graph_snapshot).with(any_args).and_return([500, nil])
|
57
|
+
send_command('graph metric:"omg.wtf.bbq{*}" event:"sources:sourcename"')
|
58
|
+
expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'with an invalid event returns an error' do
|
62
|
+
allow_any_instance_of(Lita::Handlers::Datadog).to \
|
63
|
+
receive(:graph_snapshot).with(any_args).and_return([500, nil])
|
64
|
+
send_command('graph metric:"system.load.1{*}" event:"omg:wtf"')
|
65
|
+
expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
|
35
66
|
end
|
36
67
|
end
|
37
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-datadog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sigler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chronic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|