lita-datadog 0.2.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd4e57520c88208a94b5c25e9097ddb937434faa
4
- data.tar.gz: 83cb05a53cfc3fb0a92599d4ca5bf9aa3423c6fe
3
+ metadata.gz: 674d744f8af8eef3c2124caf7fe6f330edfed54d
4
+ data.tar.gz: dd9e912e13bb4ce44fd3ba42991301c68b2c8790
5
5
  SHA512:
6
- metadata.gz: 6b69e3ff4a8a1929187424cef95957ee6dfcc7644fc9cf631bb0cd2438368c87eff14e628377e4fec97678b2db03e22434075ce63905d29a6423bee507c27757
7
- data.tar.gz: 146518897c2d1ce891f12f0ddbaf27b130895e5f7be0ef40e03b75d1fe84f404b8178781ca54db09c5e6d7cdad4b47bd84c17c922c00589ffdc45b460388d0b6
6
+ metadata.gz: 1e331d216b2083724b8ee65a9c939a7be060200b8a86720362b653175315a424aae3698e292830b3c3d8a1248969f1f22d867a9647a4babd959a23c9fefc000f
7
+ data.tar.gz: fe96cea3e2fd8a0040f81e0be28da1a0da91ec463be3890eb137ce8ac6784c5d68f08b1f7095293f26baa29d33318f1736d5ff2de816fc6e50ec1c61060b7bb6
data/.rubocop.yml CHANGED
@@ -1,12 +1,7 @@
1
- AllCops:
2
- Excludes:
3
- - lita-datadog.gemspec
4
-
5
- LineLength:
6
- Max: 120
7
-
8
- MethodLength:
9
- Max: 20
10
-
11
1
  Documentation:
12
- Enabled: false
2
+ Exclude:
3
+ - lib/lita/handlers/datadog.rb
4
+
5
+ FileName:
6
+ Exclude:
7
+ - lib/lita-datadog.rb
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.1
4
4
  script: bundle exec rake
5
5
  before_install:
6
6
  - gem update --system
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ Pull requests are awesome! Pull requests with tests are even more awesome!
2
+
3
+ ## Quick steps
4
+
5
+ 1. Fork the repo.
6
+ 2. Run the tests: `bundle && rake`
7
+ 3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, it needs a test!
8
+ 4. Make the test pass.
9
+ 5. Push to your fork and submit a pull request.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # lita-datadog
2
2
 
3
- [![Build Status](https://travis-ci.org/esigler/lita-datadog.png?branch=master)](https://travis-ci.org/esigler/lita-datadog)
4
- [![Code Climate](https://codeclimate.com/github/esigler/lita-datadog.png)](https://codeclimate.com/github/esigler/lita-datadog)
5
- [![Coverage Status](https://coveralls.io/repos/esigler/lita-datadog/badge.png)](https://coveralls.io/r/esigler/lita-datadog)
3
+ [![Build Status](https://img.shields.io/travis/esigler/lita-datadog/master.svg)](https://travis-ci.org/esigler/lita-datadog)
4
+ [![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://tldrlegal.com/license/mit-license)
5
+ [![RubyGems :: RMuh Gem Version](http://img.shields.io/gem/v/lita-datadog.svg)](https://rubygems.org/gems/lita-datadog)
6
+ [![Coveralls Coverage](https://img.shields.io/coveralls/esigler/lita-datadog/master.svg)](https://coveralls.io/r/esigler/lita-datadog)
7
+ [![Code Climate](https://img.shields.io/codeclimate/github/esigler/lita-datadog.svg)](https://codeclimate.com/github/esigler/lita-datadog)
8
+ [![Gemnasium](https://img.shields.io/gemnasium/esigler/lita-datadog.svg)](https://gemnasium.com/esigler/lita-datadog)
6
9
 
7
- Interact with Datadog (https://www.datadoghq.com/).
10
+ A [Datadog](http://datadoghq.com) plugin for [Lita](https://github.com/jimmycuadra/lita).
8
11
 
9
12
  ## Installation
10
13
 
@@ -18,25 +21,50 @@ gem "lita-datadog"
18
21
 
19
22
  ### Required attributes
20
23
 
21
- You will need to get your API key, and configure an application key. Go to https://app.datadoghq.com/account/settings#api for both.
24
+ You will need a DataDog API key, and an application key. Go to https://app.datadoghq.com/account/settings#api for both.
22
25
 
23
- * `api_key` (String) - Your DataDog API key. Default: `nil`
24
- * `application_key` (String) - Your DataDog application key. Default: `nil`
26
+ Add the following variable to your Lita config file:
27
+ ```
28
+ Lita.configure do |config|
29
+ ...
30
+ config.handlers.datadog.api_key = '_api_key_goes_here_'
31
+ config.handlers.datadog.application_key = '_app_key_goes_here_'
32
+ ...
33
+ end
34
+ ```
25
35
 
26
36
  ### Optional attributes
27
37
 
28
38
  * `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`
30
-
31
- ### Example
39
+ * `waittime` (Integer) - How long to wait after getting a URL from Datadog to display it (sometimes the graph isn't ready yet). Default: `0`
32
40
 
33
41
  ## Usage
34
42
 
43
+ ### Graphs
44
+
45
+ Basic graph of the load on all of your systems:
46
+
35
47
  ```
36
48
  Lita graph metric:"system.load.1{*}"
49
+ ```
50
+
51
+ Graph of load for one specific system:
52
+ ```
37
53
  Lita graph metric:"system.load.1{host:hostname01}"
54
+ ```
55
+
56
+ Multiple attributes plotted in one graph:
57
+ ```
38
58
  Lita graph metric:"system.load.1{*},system.load.5{*}"
59
+ ```
60
+
61
+ Show graph, with events marked in:
62
+ ```
39
63
  Lita graph metric:"system.load.1{*}" event:"sources:sourcename"
64
+ ```
65
+
66
+ Manipulate time range being graphed:
67
+ ```
40
68
  Lita graph metric:"system.load.1{*}" start:"2 hours ago"
41
69
  Lita graph metric:"system.load.1{*}" from:"2 hours ago" to:"30 minutes ago"
42
70
  ```
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
5
7
 
6
- task default: :spec
8
+ task default: [:spec, :rubocop]
data/lib/lita-datadog.rb CHANGED
@@ -5,3 +5,6 @@ Lita.load_locales Dir[File.expand_path(
5
5
  )]
6
6
 
7
7
  require 'lita/handlers/datadog'
8
+
9
+ require 'dogapi'
10
+ require 'chronic'
@@ -1,61 +1,73 @@
1
- require 'dogapi'
2
- require 'chronic'
3
-
4
1
  module Lita
5
2
  module Handlers
6
3
  class Datadog < Handler
4
+ config :api_key, required: true
5
+ config :application_key, required: true
6
+ config :timerange, default: 3600
7
+ config :waittime, default: 0
8
+
7
9
  route(
8
10
  /^graph\s(.*)$/,
9
11
  :graph,
10
12
  command: true,
11
- help: { 'graph metric:"simple.metric.1{*},simple.metric.5{*}"' =>
12
- 'Graph those metrics, for the default time range' }
13
+ help: { t('help.graph.syntax') => t('help.graph.desc') }
13
14
  )
14
15
 
15
- def self.default_config(config)
16
- config.api_key = nil
17
- config.application_key = nil
18
- config.timerange = 3600
19
- config.waittime = 1
20
- end
21
-
22
16
  def graph(response)
23
17
  args = parse_arguments(response.matches[0][0])
24
- return_code, snapshot = graph_snapshot(args[:metric], args[:start],
25
- args[:end], args[:event])
18
+ response.reply(get_response(args))
19
+ end
20
+
21
+ private
22
+
23
+ def get_response(args)
24
+ return_code, snapshot = get_graph_url(args[:metric],
25
+ args[:start],
26
+ args[:end],
27
+ args[:event])
28
+
26
29
  if return_code.to_s == '200'
27
- sleep Lita.config.handlers.datadog.waittime
28
- response.reply(snapshot['snapshot_url'])
30
+ sleep config.waittime
31
+ return snapshot['snapshot_url']
29
32
  else
30
- response.reply('Error requesting Datadog graph')
33
+ t('errors.request')
31
34
  end
32
35
  end
33
36
 
34
- private
37
+ def get_graph_url(metric_query, start_ts, end_ts, event_query)
38
+ client = Dogapi::Client.new(config.api_key, config.application_key)
35
39
 
36
- def graph_snapshot(metric_query, start_ts, end_ts, event_query)
37
- return nil if Lita.config.handlers.datadog.api_key.nil? ||
38
- Lita.config.handlers.datadog.application_key.nil?
40
+ return nil unless client
39
41
 
40
- client = Dogapi::Client.new(Lita.config.handlers.datadog.api_key,
41
- Lita.config.handlers.datadog.application_key)
42
-
43
- return client.graph_snapshot(metric_query, start_ts, end_ts, event_query) if client
42
+ client.graph_snapshot(metric_query, start_ts, end_ts, event_query)
44
43
  end
45
44
 
46
45
  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 }
46
+ end_ts = parse_end(arg_string)
47
+ start_ts = parse_start(arg_string, end_ts)
48
+ metric = parse_metric(arg_string)
49
+ event = parse_event(arg_string)
50
+ { metric: metric, start: start_ts, end: end_ts, event: event }
51
+ end
52
+
53
+ def parse_end(string)
54
+ found = /(to|end):"(.+?)"/.match(string)
55
+ found ? Chronic.parse(found[2]).to_i : Time.now.to_i
56
+ end
57
+
58
+ def parse_start(string, end_ts)
59
+ found = /(from|start):"(.+?)"/.match(string)
60
+ found ? Chronic.parse(found[2]).to_i : end_ts - config.timerange
61
+ end
62
+
63
+ def parse_metric(string)
64
+ found = /metric:"(.+?)"/.match(string)
65
+ found ? found[1] : 'system.load.1{*}'
66
+ end
67
+
68
+ def parse_event(string)
69
+ found = /event:"(.+?)"/.match(string)
70
+ found ? found[1] : ''
59
71
  end
60
72
  end
61
73
 
data/lita-datadog.gemspec CHANGED
@@ -1,26 +1,27 @@
1
1
  Gem::Specification.new do |spec|
2
- spec.name = "lita-datadog"
3
- spec.version = "0.2.0"
4
- spec.authors = ["Eric Sigler"]
5
- spec.email = ["me@esigler.com"]
6
- spec.description = %q{A Lita handler for interacting with Datadog}
7
- spec.summary = %q{Query metrics, events, and generate graphs from Datadog}
8
- spec.homepage = "http://github.com/esigler/lita-datadog"
9
- spec.license = "MIT"
10
- spec.metadata = { "lita_plugin_type" => "handler" }
2
+ spec.name = 'lita-datadog'
3
+ spec.version = '0.9.0'
4
+ spec.authors = ['Eric Sigler']
5
+ spec.email = ['me@esigler.com']
6
+ spec.description = 'A Datadog plugin for Lita'
7
+ spec.summary = 'A Datadog plugin for Lita'
8
+ spec.homepage = 'http://github.com/esigler/lita-datadog'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
11
 
12
- spec.files = `git ls-files`.split($/)
13
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
- spec.require_paths = ["lib"]
12
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
13
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
15
+ spec.require_paths = ['lib']
16
16
 
17
- spec.add_runtime_dependency "lita", ">= 3.0"
18
- spec.add_runtime_dependency "dogapi"
19
- spec.add_runtime_dependency "chronic"
17
+ spec.add_runtime_dependency 'lita', '>= 4.0'
18
+ spec.add_runtime_dependency 'dogapi'
19
+ spec.add_runtime_dependency 'chronic'
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
24
- spec.add_development_dependency "simplecov"
25
- spec.add_development_dependency "coveralls"
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'coveralls'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
25
+ spec.add_development_dependency 'rubocop'
26
+ spec.add_development_dependency 'simplecov'
26
27
  end
data/locales/en.yml CHANGED
@@ -2,3 +2,9 @@ en:
2
2
  lita:
3
3
  handlers:
4
4
  datadog:
5
+ errors:
6
+ request: Error requesting Datadog graph
7
+ help:
8
+ graph:
9
+ syntax: 'graph metric:"simple.metric.1{*},simple.metric.5{*}'
10
+ desc: 'Graph those metrics, for the default time range'
@@ -4,10 +4,34 @@ describe Lita::Handlers::Datadog, lita_handler: true do
4
4
  EXAMPLE_IMAGE_URL = 'http://www.example.com/path/that/ends/in.png'
5
5
  EXAMPLE_ERROR_MSG = 'Error requesting Datadog graph'
6
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) }
7
+ let(:success) do
8
+ client = double
9
+ allow(client).to receive(:graph_snapshot) {
10
+ [200, { 'snapshot_url' => EXAMPLE_IMAGE_URL }]
11
+ }
12
+ client
13
+ end
14
+
15
+ let(:error) do
16
+ client = double
17
+ allow(client).to receive(:graph_snapshot) { [500, {}] }
18
+ client
19
+ end
20
+
21
+ it do
22
+ is_expected.to route_command(
23
+ 'graph metric:"system.load.1{*}"')
24
+ .to(:graph)
25
+ is_expected.to route_command(
26
+ 'graph metric:"system.load.1{host:hostname01}"')
27
+ .to(:graph)
28
+ is_expected.to route_command(
29
+ 'graph metric:"system.load.1{*},system.load.5{*}"')
30
+ .to(:graph)
31
+ is_expected.to route_command(
32
+ 'graph metric:"system.load.1{*}" event:"sources:something"')
33
+ .to(:graph)
34
+ end
11
35
 
12
36
  describe '.default_config' do
13
37
  it 'sets the api_key to nil' do
@@ -22,45 +46,38 @@ describe Lita::Handlers::Datadog, lita_handler: true do
22
46
  expect(Lita.config.handlers.datadog.timerange).to eq(3600)
23
47
  end
24
48
 
25
- it 'sets the waittime to 1' do
26
- expect(Lita.config.handlers.datadog.waittime).to eq(1)
49
+ it 'sets the waittime to 0' do
50
+ expect(Lita.config.handlers.datadog.waittime).to eq(0)
27
51
  end
28
52
  end
29
53
 
30
54
  describe '#graph' do
31
55
  it 'with valid metric returns an image url' do
32
- response = { 'snapshot_url' => EXAMPLE_IMAGE_URL }
33
- allow_any_instance_of(Lita::Handlers::Datadog).to \
34
- receive(:graph_snapshot).with(any_args).and_return([200, response])
56
+ expect(Dogapi::Client).to receive(:new) { success }
35
57
  send_command('graph metric:"system.load.1{*}"')
36
58
  expect(replies.last).to eq(EXAMPLE_IMAGE_URL)
37
59
  end
38
60
 
39
61
  it 'with invalid metric returns an error' do
40
- allow_any_instance_of(Lita::Handlers::Datadog).to \
41
- receive(:graph_snapshot).with(any_args).and_return([500, nil])
62
+ expect(Dogapi::Client).to receive(:new) { error }
42
63
  send_command('graph metric:"omg.wtf.bbq{*}"')
43
64
  expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
44
65
  end
45
66
 
46
67
  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])
68
+ expect(Dogapi::Client).to receive(:new) { success }
50
69
  send_command('graph metric:"system.load.1{*}"')
51
70
  expect(replies.last).to eq(EXAMPLE_IMAGE_URL)
52
71
  end
53
72
 
54
73
  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])
74
+ expect(Dogapi::Client).to receive(:new) { error }
57
75
  send_command('graph metric:"omg.wtf.bbq{*}" event:"sources:sourcename"')
58
76
  expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
59
77
  end
60
78
 
61
79
  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])
80
+ expect(Dogapi::Client).to receive(:new) { error }
64
81
  send_command('graph metric:"system.load.1{*}" event:"omg:wtf"')
65
82
  expect(replies.last).to eq(EXAMPLE_ERROR_MSG)
66
83
  end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,5 @@ SimpleCov.start { add_filter '/spec/' }
8
8
 
9
9
  require 'lita-datadog'
10
10
  require 'lita/rspec'
11
+
12
+ Lita.version_3_compatibility_mode = false
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.2.0
4
+ version: 0.9.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-12 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dogapi
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -86,16 +100,16 @@ dependencies:
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: 3.0.0.beta2
103
+ version: 3.0.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: 3.0.0.beta2
110
+ version: 3.0.0
97
111
  - !ruby/object:Gem::Dependency
98
- name: simplecov
112
+ name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: coveralls
126
+ name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -122,7 +136,7 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
- description: A Lita handler for interacting with Datadog
139
+ description: A Datadog plugin for Lita
126
140
  email:
127
141
  - me@esigler.com
128
142
  executables: []
@@ -132,6 +146,7 @@ files:
132
146
  - ".gitignore"
133
147
  - ".rubocop.yml"
134
148
  - ".travis.yml"
149
+ - CONTRIBUTING.md
135
150
  - Gemfile
136
151
  - LICENSE
137
152
  - README.md
@@ -163,10 +178,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
178
  version: '0'
164
179
  requirements: []
165
180
  rubyforge_project:
166
- rubygems_version: 2.2.1
181
+ rubygems_version: 2.2.2
167
182
  signing_key:
168
183
  specification_version: 4
169
- summary: Query metrics, events, and generate graphs from Datadog
184
+ summary: A Datadog plugin for Lita
170
185
  test_files:
171
186
  - spec/lita/handlers/datadog_spec.rb
172
187
  - spec/spec_helper.rb