dogwatch 1.0.3 → 1.0.4

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: f8bfbcdfb0801515397ad4fab5704b91553df293
4
- data.tar.gz: aebfc2813f248bd6c059433e45cf0e44aabb974f
3
+ metadata.gz: f80269f35dd247c32ccb1374d0eaedce141a7cc8
4
+ data.tar.gz: ed05ffaa074d3e0601ccf05a45d0ae7964b290f9
5
5
  SHA512:
6
- metadata.gz: 394be276eb74c9c143511fa8a18d9a72deb5b4a06cfebcfddb7ea0e63b2aa0d5a83fe471bfdcaa7f616d5feb551fedcecd185e19c8a797fae370253d9abee821
7
- data.tar.gz: 02a830c39d3011a0ed3ac23a4e2977803b481161651d9883ec7ec838b4dae0d961e6b123d4dbe783b58267cb450878d1262cdec543946e1f3cd083da0a9ad2c9
6
+ metadata.gz: 34e1af8b2a7dec826c40e73da89758d9ede5e58c7f36fab4764a304067ad9e5934ba7f1f643f1c1b325139cdd8ed28a2af0212335f9cffec9582ff9fd0edf331
7
+ data.tar.gz: 9219b3221a629b8d60f4ed27893057db5cd105e681a80aa508f7d98df847b765e77cda98ee5f3a39929c57534aa62bb304bf4c3fc8d91278850086eb1e62022c
data/.rubocop.yml CHANGED
@@ -11,6 +11,7 @@ AllCops:
11
11
  Exclude:
12
12
  - example/**/*
13
13
  - test/data/*
14
+ TargetRubyVersion: 2.2
14
15
 
15
16
  Encoding:
16
17
  Enabled: false
@@ -21,4 +22,4 @@ HashSyntax:
21
22
  SpaceInsideStringInterpolation:
22
23
  Enabled: false
23
24
  DoubleNegation:
24
- Enabled: false
25
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,19 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-12-11 13:32:10 -0500 using RuboCop version 0.35.1.
3
+ # on 2016-06-01 14:50:11 +0100 using RuboCop version 0.40.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 4
10
- # Configuration parameters: AllowURI, URISchemes.
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
11
+ # URISchemes: http, https
11
12
  Metrics/LineLength:
12
13
  Max: 90
14
+
15
+ # Offense count: 1
16
+ # Cop supports --auto-correct.
17
+ Performance/RedundantBlockCall:
18
+ Exclude:
19
+ - 'lib/dogwatch/dogfile.rb'
data/README.md CHANGED
@@ -26,6 +26,8 @@ $ gem install dogwatch
26
26
  Generate both an api key and an app key and either place them in a file named `~/.dogwatch/credentials` or pass them via the command line.
27
27
 
28
28
  A sample credentials file is provided in the `example` directory.
29
+
30
+ In order to generate these keys, log into your Datadog account. From there, click on 'Integrations->APIs'. Keep in mind, your org may be allowed only five API Keys.
29
31
  ## Usage
30
32
 
31
33
  DogWatch is a thin DSL over the [DataDog ruby client](https://github.com/DataDog/dogapi-rb) that handles generating DataDog monitors.
@@ -36,7 +38,7 @@ DogWatch.monitor do
36
38
  ## Create a new monitor - monitor name is REQUIRED
37
39
  monitor 'MONITOR NAME' do
38
40
  type :metric_alert # REQUIRED: One of [:metric_alert | :service_check | :event_alert]
39
- query 'QUERY' # REQUIRED
41
+ query 'time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator' # REQUIRED
40
42
  message 'MESSAGE'
41
43
  tags %w(A list of tags to associate with your monitor)
42
44
 
@@ -52,6 +54,18 @@ DogWatch.monitor do
52
54
  end
53
55
  end
54
56
  ```
57
+ Queries are the combination of several items including a time aggregator (over a window of time), space aggregator (avg, sum, min, or max), a set of tags and an optional order by, and an operator.
58
+
59
+ From the Datadog documentation:
60
+
61
+ ```
62
+ time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator
63
+ ```
64
+ An example of a query:
65
+
66
+ ```
67
+ avg(last_15m):avg:system.disk.used{region:us-east-1,some-tag:some-tag-value,device:/dev/xvdb} by {cluster} * 100 > 55
68
+ ```
55
69
 
56
70
  Monitors that already exist are matched by name and updated accordingly. If the name isn't matched exactly, DogWatch assumes you want a new monitor.
57
71
 
@@ -61,4 +75,4 @@ For a full list of options and a description of each parameter, see [DataDog's A
61
75
 
62
76
  ## TO DO
63
77
  * More descriptive errors
64
- * Better error handling if a monitor fails local validation
78
+ * Better error handling if a monitor fails local validation
@@ -11,7 +11,7 @@ module DogWatch
11
11
  metric_alert: 'metric alert',
12
12
  service_check: 'service check',
13
13
  event_alert: 'event alert'
14
- }
14
+ }.freeze
15
15
 
16
16
  attr_reader :name
17
17
  attr_reader :attributes
@@ -26,6 +26,7 @@ module DogWatch
26
26
  # @param [Symbol] type
27
27
  # @return [String]
28
28
  def type(type)
29
+ @monitor_type = type
29
30
  @attributes.type = TYPE_MAP[type]
30
31
  end
31
32
 
@@ -50,7 +51,7 @@ module DogWatch
50
51
  # @param [Proc] block
51
52
  # @return [Hash]
52
53
  def options(&block)
53
- opts = DogWatch::Model::Options.new
54
+ opts = DogWatch::Model::Options.new(@monitor_type)
54
55
  opts.instance_eval(&block)
55
56
  @attributes.options = opts.render
56
57
  end
@@ -6,10 +6,19 @@ module DogWatch
6
6
  # Handles the options block methods
7
7
  ##
8
8
  class Options
9
+ MONITOR_TYPE_OPTIONS_MAP = {
10
+ :metric_alert => [:thresholds].freeze,
11
+ :service_check => [:thresholds].freeze
12
+ }.freeze
13
+
9
14
  attr_reader :attributes
10
15
 
11
- def initialize
16
+ # @param [Symbol] monitor_type the monitor type of monitor these
17
+ # options belong to. This is used to validate monitor type
18
+ # specific options such as thresholds.
19
+ def initialize(monitor_type = nil)
12
20
  @attributes = OpenStruct.new
21
+ @monitor_type = monitor_type
13
22
  end
14
23
 
15
24
  def render
@@ -55,6 +64,24 @@ module DogWatch
55
64
  def include_tags(include = true)
56
65
  @attributes.include_tags = !!include
57
66
  end
67
+
68
+ # @param [Hash{String=>Fixnum}] thresholds
69
+ def thresholds(thresholds)
70
+ validate_monitor_type_specific_option!(:thresholds)
71
+ @attributes.thresholds = thresholds
72
+ end
73
+
74
+ private
75
+
76
+ def validate_monitor_type_specific_option!(option)
77
+ options = Array(MONITOR_TYPE_OPTIONS_MAP[@monitor_type])
78
+ return true if options.include?(option)
79
+
80
+ # rubocop:disable Metrics/LineLength
81
+ message = "The #{@monitor_type.inspect} monitor type does not support #{option.inspect}."
82
+ message << " Did you mean one of #{options.join(', ')}?" if options.any?
83
+ raise NotImplementedError, message
84
+ end
58
85
  end
59
86
  end
60
87
  end
@@ -8,14 +8,13 @@ module DogWatch
8
8
  class Response
9
9
  extend Mixin::Colorize
10
10
 
11
- ERROR = '400'
12
- CREATED = '200'
13
- ACCEPTED = '202'
11
+ ERROR = '400'.freeze
12
+ CREATED = '200'.freeze
13
+ ACCEPTED = '202'.freeze
14
14
  colorize(:action,
15
15
  :green => [:created, :accepted, :updated],
16
16
  :yellow => [],
17
- :red => [:error]
18
- )
17
+ :red => [:error])
19
18
 
20
19
  attr_accessor :response
21
20
 
@@ -1,6 +1,7 @@
1
1
  # nodoc
2
2
  module DogWatch
3
3
  VERSION = IO.read(File.expand_path('../../../VERSION', __FILE__)) rescue '0.0.1'
4
- SUMMARY = 'A DSL to create DataDog Monitors'
4
+ SUMMARY = 'A DSL to create DataDog Monitors'.freeze
5
5
  DESCRIPTION = 'DogWatch provides a simple method for creating DataDog monitors in Ruby.'
6
+ .freeze
6
7
  end
@@ -13,7 +13,7 @@ class TestClient < Minitest::Test
13
13
  type: 'metric alert',
14
14
  query: 'test query'
15
15
  ]
16
- ]
16
+ ].freeze
17
17
 
18
18
  UPDATED_RESPONSE = [
19
19
  '200',
@@ -22,7 +22,7 @@ class TestClient < Minitest::Test
22
22
  type: :metric_alert,
23
23
  query: 'scheduled maintenance query'
24
24
  ]
25
- ]
25
+ ].freeze
26
26
 
27
27
  def setup
28
28
  config = DogWatch::Model::Config.new('foo', 'bar')
@@ -11,7 +11,7 @@ class TestOptions < Minitest::Test
11
11
  escalation_message: 'foobar',
12
12
  notify_audit: true,
13
13
  include_tags: false
14
- }
14
+ }.freeze
15
15
 
16
16
  # rubocop:disable Metrics/AbcSize
17
17
  def setup
@@ -78,4 +78,25 @@ class TestOptions < Minitest::Test
78
78
  assert_equal OPTS, @options.render
79
79
  assert_kind_of Hash, @options.render
80
80
  end
81
+
82
+ def test_invalid_monitor_type_specific_option
83
+ @options = DogWatch::Model::Options.new(:event_alert)
84
+
85
+ assert_raises NotImplementedError do
86
+ @options.thresholds('critical' => 90, 'warning' => 80)
87
+ end
88
+ end
89
+
90
+ def test_valid_monitor_type_specific_option
91
+ @options = DogWatch::Model::Options.new(:metric_alert)
92
+
93
+ @options.thresholds('critical' => 90, 'warning' => 80)
94
+
95
+ actual = @options.attributes.thresholds
96
+ assert_includes actual, 'critical'
97
+ assert_equal actual['critical'], 90
98
+
99
+ assert_includes actual, 'warning'
100
+ assert_equal actual['warning'], 80
101
+ end
81
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Greene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogapi