barkdog 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c21615f347dced36cd4409fb53dc2df65166ee91
4
- data.tar.gz: 08dae8f1e3eaab800c87fc5bae38068466b49193
3
+ metadata.gz: 72c3787a7e3e9dbfe3739e193c70e5d9a64113b5
4
+ data.tar.gz: e5362d78f263ba2a77e0aa28ad6c648c6d5d510a
5
5
  SHA512:
6
- metadata.gz: 979495548620024f79d5bebf457f6826d307479ac239d567c45db493ebe4a3de4384c6a851914d6107517425d17c07a8ee6e023580011a725dda93649e718287
7
- data.tar.gz: ec08151e9f466f7b00ea6cc32ab94248233ad27967605a257f118fb20358b09398ab7b85a89f127cd7295d54b05205e0c32fa72b1635876c880799a4ce86ccbd
6
+ metadata.gz: 56afbf59c6f690d741d4230058800a0617b68268f3c12ae74fd4aab58ec0fffeaf49a0e7afbdd683a709ffdb472ae0e4740b754087e3abd4c04e7335d7f71a1b
7
+ data.tar.gz: 2831088d7adb245160e4a1ed7d85f7be3aeea267bb59abf088b22158573e34896c633b8e031d5fbd3f817828daea85c5336affc179202943d147957259a268f5
data/.travis.yml CHANGED
@@ -6,5 +6,5 @@ script:
6
6
  - bundle exec rake
7
7
  env:
8
8
  global:
9
- - secure: "isrR0KYg4po5oZNWV3X6eSIryA7BdcMdyztIJPILZR0gRVd0IQLbe/0npvxFKzn7Y4mwQ/4N3oLnd1Jv/okuIC+zvMim+ZDyZP6uK0mDg9AFY718BVBhDcXjp85aW2KXki7dpUZ6G+cbsAtYbomEh/Soi3y47m+Ov/1odz7qylXBnwEZKbsxsoGd9iwb/DmFOCQeXvit+pQa4lPkTynu2etUxJtrzUPCxEBjcDXOB08GuDOQlAbnokiqN2pMwq60HC1UxynRF8OsUgb9yWOu+w80MbR5Qd+ZOXLe9sxY9/vuPPK3U3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 - BARKDOG_TEST_API_KEY=31aef8b41be3ad6070ea1013b90fc9e8
10
+ - BARKDOG_TEST_APP_KEY=d31f2d115e8a70f5647bf691081a292cd631c3be
data/README.md CHANGED
@@ -9,7 +9,7 @@ It defines Datadog monitors using Ruby DSL, and updates monitors according to DS
9
9
 
10
10
  ## Notice
11
11
  * `>= 0.1.3`
12
- * Support Template
12
+ * Support Template
13
13
 
14
14
  ## Installation
15
15
 
@@ -48,10 +48,13 @@ Usage: barkdog [options]
48
48
  -a, --apply
49
49
  -f, --file FILE
50
50
  --dry-run
51
+ --ignore-silenced
51
52
  -e, --export
52
53
  -o, --output FILE
53
54
  --no-color
55
+ --no-delete
54
56
  --debug
57
+ --datadog-timeout TIMEOUT
55
58
  -h, --help
56
59
  ```
57
60
 
data/barkdog.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler'
27
27
  spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'rspec', '>= 0.3.0'
29
+ spec.add_development_dependency 'rspec-match_fuzzy'
29
30
  end
data/bin/barkdog CHANGED
@@ -23,20 +23,23 @@ options = {
23
23
  :ignore_silenced => false,
24
24
  :color => true,
25
25
  :debug => false,
26
+ :datadog_timeout => nil
26
27
  }
27
28
 
28
29
  ARGV.options do |opt|
29
30
  begin
30
- opt.on('' , '--api-key API_KEY') {|v| options[:api_key] = v }
31
- opt.on('' , '--app-key APP_KEY') {|v| options[:application_key] = v }
32
- opt.on('-a', '--apply') { mode = :apply }
33
- opt.on('-f', '--file FILE') {|v| file = v }
34
- opt.on('' , '--dry-run') { options[:dry_run] = true }
35
- opt.on('' , '--ignore-silenced') { options[:ignore_silenced] = true }
36
- opt.on('-e', '--export') { mode = :export }
37
- opt.on('-o', '--output FILE') {|v| output_file = v }
38
- opt.on('' , '--no-color') { options[:color] = false }
39
- opt.on('' , '--debug') { options[:debug] = true }
31
+ opt.on('' , '--api-key API_KEY') {|v| options[:api_key] = v }
32
+ opt.on('' , '--app-key APP_KEY') {|v| options[:application_key] = v }
33
+ opt.on('-a', '--apply') { mode = :apply }
34
+ opt.on('-f', '--file FILE') {|v| file = v }
35
+ opt.on('' , '--dry-run') { options[:dry_run] = true }
36
+ opt.on('' , '--ignore-silenced') { options[:ignore_silenced] = true }
37
+ opt.on('-e', '--export') { mode = :export }
38
+ opt.on('-o', '--output FILE') {|v| output_file = v }
39
+ opt.on('' , '--no-color') { options[:color] = false }
40
+ opt.on('' , '--no-delete') { options[:no_delete] = true }
41
+ opt.on('' , '--debug') { options[:debug] = true }
42
+ opt.on('' , '--datadog-timeout TIMEOUT') {|v| options[:datadog_timeout] = v.to_i }
40
43
 
41
44
  opt.on('-h', '--help') do
42
45
  puts opt.help
@@ -8,7 +8,9 @@ class Barkdog::Client
8
8
  raise 'API Key does not exist' unless api_key
9
9
  raise 'Application Key does not exist' unless app_key
10
10
 
11
- @dog = Dogapi::Client.new(api_key, app_key)
11
+ # api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil
12
+ # We force silent to false so any exceptions get propated back out and we fail loudly.
13
+ @dog = Dogapi::Client.new(api_key, app_key, nil, nil, false, @options[:datadog_timeout])
12
14
  @driver = Barkdog::Driver.new(@dog, @options)
13
15
  end
14
16
 
@@ -31,6 +31,8 @@ class Barkdog::Driver
31
31
  end
32
32
 
33
33
  def delete_monitor(name, attrs)
34
+ return false if @options[:no_delete]
35
+
34
36
  updated = false
35
37
  log(:info, "Delete Monitor: #{name}", :color => :red)
36
38
 
@@ -47,8 +49,8 @@ class Barkdog::Driver
47
49
  updated = false
48
50
 
49
51
  if @options[:ignore_silenced]
50
- expected['options'].delete('silenced')
51
- actual['options'].delete('silenced')
52
+ expected['options'].delete('silenced') if expected['options']
53
+ actual['options'].delete('silenced') if actual['options']
52
54
  end
53
55
 
54
56
  diffy = Diffy::Diff.new(
@@ -1,3 +1,3 @@
1
1
  module Barkdog
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -0,0 +1,90 @@
1
+ describe Barkdog::Client do
2
+ subject { barkdog_client(options).export }
3
+ let(:options) { {} }
4
+
5
+ let(:dsl) {
6
+ <<-'RUBY'
7
+ monitor "my metric check", :type=>"metric alert" do
8
+ query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
9
+ message "metric check message"
10
+ options do
11
+ locked false
12
+ no_data_timeframe 2
13
+ notify_audit false
14
+ notify_no_data false
15
+ silenced({})
16
+ end
17
+ end
18
+
19
+ monitor "my service check", :type=>"service check" do
20
+ query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
21
+ message "service check message"
22
+ options do
23
+ locked false
24
+ no_data_timeframe 2
25
+ notify_audit false
26
+ notify_no_data true
27
+ period 15
28
+ renotify_interval 0
29
+ silenced({})
30
+ thresholds "critical"=>1, "ok"=>1, "warning"=>1
31
+ timeout_h 0
32
+ end
33
+ end
34
+ RUBY
35
+ }
36
+
37
+ context 'when create monitors' do
38
+ specify do
39
+ barkdog(options) { dsl }
40
+ expect(subject).to match_fuzzy dsl
41
+ end
42
+ end
43
+
44
+ context 'when use template monitors' do
45
+ specify do
46
+ barkdog(options) {
47
+ <<-'RUBY'
48
+ template 'my metric check' do
49
+ query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
50
+ message "metric check message"
51
+ options do
52
+ locked false
53
+ no_data_timeframe context.no_data_timeframe
54
+ notify_audit false
55
+ notify_no_data false
56
+ silenced({})
57
+ end
58
+ end
59
+
60
+ template "my service check options" do
61
+ locked false
62
+ no_data_timeframe 2
63
+ notify_audit false
64
+ notify_no_data true
65
+ period context.period
66
+ renotify_interval 0
67
+ silenced({})
68
+ thresholds "critical"=>1, "ok"=>1, "warning"=>1
69
+ timeout_h 0
70
+ end
71
+
72
+ monitor "my metric check", :type=>"metric alert" do
73
+ include_template "my metric check", :no_data_timeframe=>2
74
+ end
75
+
76
+ monitor "my service check", :type=>"service check" do
77
+ query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
78
+ message "service check message"
79
+ options do
80
+ context.period = 15
81
+ include_template "my service check options"
82
+ end
83
+ end
84
+ RUBY
85
+ }
86
+
87
+ expect(subject).to match_fuzzy dsl
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,60 @@
1
+ describe Barkdog::Client do
2
+ subject { barkdog_client(options).export }
3
+ let(:options) { {} }
4
+
5
+ let(:dsl) {
6
+ <<-'RUBY'
7
+ monitor "my metric check", :type=>"metric alert" do
8
+ query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
9
+ message "metric check message"
10
+ options do
11
+ locked false
12
+ no_data_timeframe 2
13
+ notify_audit false
14
+ notify_no_data false
15
+ silenced({})
16
+ end
17
+ end
18
+
19
+ monitor "my service check", :type=>"service check" do
20
+ query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
21
+ message "service check message"
22
+ options do
23
+ locked false
24
+ no_data_timeframe 2
25
+ notify_audit false
26
+ notify_no_data true
27
+ period 15
28
+ renotify_interval 0
29
+ silenced({})
30
+ thresholds "critical"=>1, "ok"=>1, "warning"=>1
31
+ timeout_h 0
32
+ end
33
+ end
34
+ RUBY
35
+ }
36
+
37
+ context 'when delete monitors' do
38
+ before do
39
+ barkdog(options) { dsl }
40
+ end
41
+
42
+ specify do
43
+ barkdog(options) { '' }
44
+ expect(subject).to match_fuzzy ''
45
+ end
46
+ end
47
+
48
+ context 'when delete monitors (no delete)' do
49
+ let(:options) { {no_delete: true} }
50
+
51
+ before do
52
+ barkdog(options) { dsl }
53
+ end
54
+
55
+ specify do
56
+ barkdog(options) { '' }
57
+ expect(subject).to match_fuzzy dsl
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,88 @@
1
+ describe Barkdog::Client do
2
+ subject { barkdog_client(options).export }
3
+ let(:options) { {} }
4
+
5
+ let(:before_dsl) do
6
+ <<-'RUBY'
7
+ monitor "my metric check", :type=>"metric alert" do
8
+ query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
9
+ message "metric check message"
10
+ options do
11
+ locked false
12
+ no_data_timeframe 2
13
+ notify_audit false
14
+ notify_no_data false
15
+ silenced({})
16
+ end
17
+ end
18
+
19
+ monitor "my service check", :type=>"service check" do
20
+ query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
21
+ message "service check message"
22
+ options do
23
+ locked false
24
+ no_data_timeframe 2
25
+ notify_audit false
26
+ notify_no_data true
27
+ period 15
28
+ renotify_interval 0
29
+ silenced({})
30
+ thresholds "critical"=>1, "ok"=>1, "warning"=>1
31
+ timeout_h 0
32
+ end
33
+ end
34
+ RUBY
35
+ end
36
+
37
+ let(:update_dsl) do
38
+ <<-'RUBY'
39
+ monitor "my metric check", :type=>"metric alert" do
40
+ query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 2"
41
+ message "metric check message2"
42
+ options do
43
+ locked false
44
+ no_data_timeframe 3
45
+ notify_audit true
46
+ notify_no_data true
47
+ silenced "*"=>nil
48
+ end
49
+ end
50
+
51
+ monitor "my service check", :type=>"service check" do
52
+ query "\"datadog.agent.up\".over(\"*\").last(3).count_by_status()"
53
+ message "service check message2"
54
+ options do
55
+ locked false
56
+ no_data_timeframe 3
57
+ notify_audit true
58
+ notify_no_data true
59
+ period 30
60
+ renotify_interval 1
61
+ silenced "*"=>nil
62
+ thresholds "critical"=>2, "ok"=>2, "warning"=>2
63
+ timeout_h 1
64
+ end
65
+ end
66
+ RUBY
67
+ end
68
+
69
+ context 'when update monitors' do
70
+ before do
71
+ barkdog(options) { before_dsl }
72
+ end
73
+
74
+ specify do
75
+ barkdog(options) { update_dsl }
76
+ expect(subject).to match_fuzzy update_dsl
77
+ end
78
+ end
79
+
80
+ context 'when use template monitors (ignore silenced)' do
81
+ let(:options) { {ignore_silenced: true} }
82
+
83
+ specify do
84
+ barkdog(options) { update_dsl }
85
+ expect(subject).to match_fuzzy update_dsl.gsub('silenced "*"=>nil', '')
86
+ end
87
+ end
88
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'barkdog'
2
2
  require 'tempfile'
3
+ require 'rspec/match_fuzzy'
3
4
 
4
5
  BARKDOG_TEST_API_KEY = ENV['BARKDOG_TEST_API_KEY']
5
6
  BARKDOG_TEST_APP_KEY = ENV['BARKDOG_TEST_APP_KEY']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barkdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogapi
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.3.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-match_fuzzy
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Barkdog is a tool to manage Datadog monitors.
112
126
  email:
113
127
  - sgwr_dts@yahoo.co.jp
@@ -139,7 +153,9 @@ files:
139
153
  - lib/barkdog/logger.rb
140
154
  - lib/barkdog/template_helper.rb
141
155
  - lib/barkdog/version.rb
142
- - spec/barkdog_spec.rb
156
+ - spec/barkdog_create_spec.rb
157
+ - spec/barkdog_delete_spec.rb
158
+ - spec/barkdog_update_spec.rb
143
159
  - spec/spec_helper.rb
144
160
  homepage: https://github.com/winebarrel/barkdog
145
161
  licenses:
@@ -166,5 +182,7 @@ signing_key:
166
182
  specification_version: 4
167
183
  summary: Barkdog is a tool to manage Datadog monitors.
168
184
  test_files:
169
- - spec/barkdog_spec.rb
185
+ - spec/barkdog_create_spec.rb
186
+ - spec/barkdog_delete_spec.rb
187
+ - spec/barkdog_update_spec.rb
170
188
  - spec/spec_helper.rb
data/spec/barkdog_spec.rb DELETED
@@ -1,132 +0,0 @@
1
- describe Barkdog::Client do
2
- subject { barkdog_client.export }
3
-
4
- let(:dsl) do
5
- <<-'RUBY'
6
- monitor "my metric check", :type=>"metric alert" do
7
- query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
8
- message "metric check message"
9
- options do
10
- locked false
11
- no_data_timeframe 2
12
- notify_audit false
13
- notify_no_data false
14
- silenced({})
15
- end
16
- end
17
-
18
- monitor "my service check", :type=>"service check" do
19
- query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
20
- message "service check message"
21
- options do
22
- locked false
23
- no_data_timeframe 2
24
- notify_audit false
25
- notify_no_data true
26
- period 15
27
- renotify_interval 0
28
- silenced({})
29
- thresholds "critical"=>1, "ok"=>1, "warning"=>1
30
- timeout_h 0
31
- end
32
- end
33
- RUBY
34
- end
35
-
36
- let(:actual_dsl) { dsl }
37
- let(:expected_dsl) { dsl }
38
-
39
- before { barkdog { actual_dsl } }
40
-
41
- context 'when create monitors' do
42
- it { is_expected.to eq expected_dsl }
43
- end
44
-
45
- context 'when use template monitors' do
46
- let(:actual_dsl) do
47
- <<-'RUBY'
48
- template 'my metric check' do
49
- query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 1"
50
- message "metric check message"
51
- options do
52
- locked false
53
- no_data_timeframe context.no_data_timeframe
54
- notify_audit false
55
- notify_no_data false
56
- silenced({})
57
- end
58
- end
59
-
60
- template "my service check options" do
61
- locked false
62
- no_data_timeframe 2
63
- notify_audit false
64
- notify_no_data true
65
- period context.period
66
- renotify_interval 0
67
- silenced({})
68
- thresholds "critical"=>1, "ok"=>1, "warning"=>1
69
- timeout_h 0
70
- end
71
-
72
- monitor "my metric check", :type=>"metric alert" do
73
- include_template "my metric check", :no_data_timeframe=>2
74
- end
75
-
76
- monitor "my service check", :type=>"service check" do
77
- query "\"datadog.agent.up\".over(\"*\").last(2).count_by_status()"
78
- message "service check message"
79
- options do
80
- context.period = 15
81
- include_template "my service check options"
82
- end
83
- end
84
- RUBY
85
- end
86
-
87
- it { is_expected.to eq expected_dsl }
88
- end
89
-
90
- context 'when delete monitors' do
91
- let(:expected_dsl) { '' }
92
- before { barkdog { expected_dsl } }
93
- it { is_expected.to eq expected_dsl }
94
- end
95
-
96
- context 'when update monitors' do
97
- let(:expected_dsl) do
98
- <<-'RUBY'
99
- monitor "my metric check", :type=>"metric alert" do
100
- query "avg(last_5m):avg:datadog.dogstatsd.packet.count{*} > 2"
101
- message "metric check message2"
102
- options do
103
- locked false
104
- no_data_timeframe 3
105
- notify_audit true
106
- notify_no_data true
107
- silenced "*"=>nil
108
- end
109
- end
110
-
111
- monitor "my service check", :type=>"service check" do
112
- query "\"datadog.agent.up\".over(\"*\").last(3).count_by_status()"
113
- message "service check message2"
114
- options do
115
- locked false
116
- no_data_timeframe 3
117
- notify_audit true
118
- notify_no_data true
119
- period 30
120
- renotify_interval 1
121
- silenced "*"=>nil
122
- thresholds "critical"=>2, "ok"=>2, "warning"=>2
123
- timeout_h 1
124
- end
125
- end
126
- RUBY
127
- end
128
-
129
- before { barkdog { expected_dsl } }
130
- it { is_expected.to eq expected_dsl }
131
- end
132
- end