doggy 0.1.0 → 0.1.1

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: d45de1eb568f088f9c702bbb55e2961691337c45
4
- data.tar.gz: 733512dea50824d0800967443ab6827e79d155b7
3
+ metadata.gz: b31e6a9cbbd6eff0526a4df39a096933b7671831
4
+ data.tar.gz: 0b7a87bdc2f8ba9215a928e9f4abe49241d94e5b
5
5
  SHA512:
6
- metadata.gz: 60049f997c3552d938fbf8d70e709f525716939658e3f08a2d4101b679fd12b82285d5266355f6349bc8ba6d998d803f56a2c6dbbaed8987fe90bf64f0a6ba21
7
- data.tar.gz: ab72d81d8e5d83561e67c126ad52e0a5320f28ccc4905943e60d529e5d2c7617b862e8ffc677a7e38f42e093e9a2983df385914468a39273ba4e789fa75bb0f6
6
+ metadata.gz: b909f6afb9689da50ad3ae588e6c99e688403e067b9b3a52c53febea1cb229e90a2256c174595afac507a2893f86289e0114bd373f8644d1a37475421668713f
7
+ data.tar.gz: a8f482850619478ab97f5b602891a55a7e0dc688cd90171b0d46587a4d47025f683b846de0f198d6687d34b25a735c09d5d078cad2c540aa6ae96e9097a47cd9
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ doggy (0.1.0)
5
+ dogapi (~> 1.17)
6
+ ejson (~> 1.0)
7
+ thor (~> 0.19)
8
+ thread (~> 0.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ dogapi (1.20.0)
14
+ multi_json
15
+ ejson (1.0.0)
16
+ multi_json (1.11.2)
17
+ rake (10.4.2)
18
+ thor (0.19.1)
19
+ thread (0.2.2)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.9)
26
+ doggy!
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.10.6
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/doggy.gemspec CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "bin"
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.9"
@@ -50,7 +50,10 @@ module Doggy
50
50
  end
51
51
 
52
52
  def raw
53
- @raw ||= Doggy.client.dog.get_dashboard(@id)[1]['dash'].sort.to_h
53
+ @raw ||= begin
54
+ result = Doggy.client.dog.get_dashboard(@id)
55
+ result && result[1]['dash'] && result[1]['dash'].sort.to_h || {}
56
+ end
54
57
  end
55
58
 
56
59
  def raw_local
@@ -59,8 +62,9 @@ module Doggy
59
62
  end
60
63
 
61
64
  def save
62
- puts raw['errors'] and return if raw['errors'] # do now download an item if it doesn't exist
65
+ return if raw['errors'] # do now download an item if it doesn't exist
63
66
  return if raw['title'] =~ Doggy::DOG_SKIP_REGEX
67
+ return if raw.empty?
64
68
  File.write(path, Doggy.serializer.dump(raw))
65
69
  end
66
70
 
@@ -68,9 +72,13 @@ module Doggy
68
72
  return unless File.exists?(path)
69
73
  return if @title =~ Doggy::DOG_SKIP_REGEX
70
74
  if @id
71
- Doggy.client.dog.update_dashboard(@id, @title, @description, @graphs, @template_variables)
75
+ Doggy.with_retry do
76
+ Doggy.client.dog.update_dashboard(@id, @title, @description, @graphs, @template_variables)
77
+ end
72
78
  else
73
- dash = Doggy.client.dog.create_dashboard(@title, @description, @graphs)
79
+ Doggy.with_retry do
80
+ dash = Doggy.client.dog.create_dashboard(@title, @description, @graphs)
81
+ end
74
82
  # FIXME: Remove duplication
75
83
  @id = dash[1]['id']
76
84
  @graphs = dash[1]['graphs']
@@ -58,10 +58,11 @@ module Doggy
58
58
  def raw
59
59
  @raw ||= begin
60
60
  alert = Doggy.client.dog.get_monitor(@id)[1]
61
- alert.delete('state')
62
- alert.delete('overall_state')
63
- alert['options'].delete('silenced')
64
- alert.sort.to_h
61
+ alert.delete('state') # delete unnecessary state
62
+ alert.delete('overall_state') # delete unnecessary state
63
+ alert['options'] && alert['options'].delete('silenced') # delete unnecessary state
64
+ alert['options'] = alert['options'] && alert['options'].sort.to_h # sort option keys; DataDog response is not ordered
65
+ alert && alert.sort.to_h
65
66
  end
66
67
  end
67
68
 
@@ -71,8 +72,9 @@ module Doggy
71
72
  end
72
73
 
73
74
  def save
74
- puts raw['errors'] and return if raw['errors'] # do now download an item if it doesn't exist
75
+ return if raw['errors'] # do now download an item if it doesn't exist
75
76
  return if raw['name'] =~ Doggy::DOG_SKIP_REGEX
77
+ return if raw.empty?
76
78
  File.write(path, Doggy.serializer.dump(raw))
77
79
  end
78
80
 
@@ -89,22 +91,26 @@ module Doggy
89
91
  if @id
90
92
  return unless File.exists?(path)
91
93
 
92
- Doggy.client.dog.update_monitor(@id, @query || raw_local['query'], {
93
- name: @name || raw_local['name'],
94
- timeout_h: @timeout_h || raw_local['timeout_h'],
95
- message: @message || raw_local['message'],
96
- notify_audit: @notify_audit || raw_local['notify_audit'],
97
- notify_no_data: @notify_no_data || raw_local['notify_no_data'],
98
- renotify_interval: @renotify_interval || raw_local['renotify_interval'],
99
- escalation_message: @escalation_message || raw_local['escalation_message'],
100
- no_data_timeframe: @no_data_timeframe || raw_local['no_data_timeframe'],
101
- silenced_timeout_ts: @silenced_timeout_ts || raw_local['silenced_timeout_ts'],
102
- options: {
103
- silenced: mute_state_for(@id),
104
- },
105
- })
94
+ Doggy.with_retry do
95
+ Doggy.client.dog.update_monitor(@id, @query || raw_local['query'], {
96
+ name: @name || raw_local['name'],
97
+ timeout_h: @timeout_h || raw_local['timeout_h'],
98
+ message: @message || raw_local['message'],
99
+ notify_audit: @notify_audit || raw_local['notify_audit'],
100
+ notify_no_data: @notify_no_data || raw_local['notify_no_data'],
101
+ renotify_interval: @renotify_interval || raw_local['renotify_interval'],
102
+ escalation_message: @escalation_message || raw_local['escalation_message'],
103
+ no_data_timeframe: @no_data_timeframe || raw_local['no_data_timeframe'],
104
+ silenced_timeout_ts: @silenced_timeout_ts || raw_local['silenced_timeout_ts'],
105
+ options: {
106
+ silenced: mute_state_for(@id),
107
+ },
108
+ })
109
+ end
106
110
  else
107
- result = Doggy.client.dog.monitor('metric alert', @query, name: @name)
111
+ Doggy.with_retry do
112
+ result = Doggy.client.dog.monitor('metric alert', @query, name: @name)
113
+ end
108
114
  @id = result[1]['id']
109
115
  end
110
116
  end
@@ -37,7 +37,10 @@ module Doggy
37
37
  end
38
38
 
39
39
  def raw
40
- @raw ||= Doggy.client.dog.get_screenboard(@id)[1].sort.to_h
40
+ @raw ||= begin
41
+ result = Doggy.client.dog.get_screenboard(@id)
42
+ result && result[1] && result[1].sort.to_h
43
+ end
41
44
  end
42
45
 
43
46
  def raw_local
@@ -46,17 +49,22 @@ module Doggy
46
49
  end
47
50
 
48
51
  def save
49
- puts raw['errors'] and return if raw['errors'] # do now download an item if it doesn't exist
52
+ return if raw['errors'] # do now download an item if it doesn't exist
50
53
  return if raw['board_title'] =~ Doggy::DOG_SKIP_REGEX
54
+ return if raw.empty?
51
55
  File.write(path, Doggy.serializer.dump(raw))
52
56
  end
53
57
 
54
58
  def push
55
59
  return if @description =~ Doggy::DOG_SKIP_REGEX
56
60
  if @id
57
- Doggy.client.dog.update_screenboard(@id, @description)
61
+ Doggy.with_retry do
62
+ Doggy.client.dog.update_screenboard(@id, @description)
63
+ end
58
64
  else
59
- result = Doggy.client.dog.create_screenboard(@description)
65
+ Doggy.with_retry do
66
+ result = Doggy.client.dog.create_screenboard(@description)
67
+ end
60
68
  @id = result[1]['id']
61
69
  @description = result[1]
62
70
  end
data/lib/doggy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Doggy
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/doggy.rb CHANGED
@@ -16,6 +16,7 @@ require 'doggy/model/screen'
16
16
  module Doggy
17
17
  DOG_SKIP_REGEX = /\[dog\s+skip\]/i.freeze
18
18
  DEFAULT_SERIALIZER_CLASS = Doggy::Serializer::Json
19
+ MAX_TRIES = 5
19
20
 
20
21
  class DoggyError < StandardError
21
22
  def self.status_code(code)
@@ -93,6 +94,23 @@ module Doggy
93
94
  puts "Exception: #{e.message}"
94
95
  end
95
96
 
97
+ def with_retry(times: MAX_TRIES, reraise: false)
98
+ tries = 0
99
+ while tries < times
100
+ begin
101
+ yield
102
+ break
103
+ rescue => e
104
+ error "Caught error in create_record! attempt #{tries}..."
105
+ error "#{e.class.name}: #{e.message}"
106
+ error "#{e.backtrace.join("\n")}"
107
+ tries += 1
108
+
109
+ raise e if tries >= times && reraise
110
+ end
111
+ end
112
+ end
113
+
96
114
  def current_version
97
115
  now = Time.now.to_i
98
116
  month_ago = now - 3600 * 24 * 30
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Gorodetsky
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,13 +97,13 @@ dependencies:
97
97
  description: Syncs DataDog dashboards, alerts, screenboards, and monitors.
98
98
  email:
99
99
  - v@gor.io
100
- executables:
101
- - doggy
100
+ executables: []
102
101
  extensions: []
103
102
  extra_rdoc_files: []
104
103
  files:
105
104
  - ".gitignore"
106
105
  - Gemfile
106
+ - Gemfile.lock
107
107
  - LICENSE.txt
108
108
  - README.md
109
109
  - Rakefile