doggy 2.0.17 → 2.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/doggy/cli/pull.rb +42 -18
- data/lib/doggy/model.rb +7 -0
- data/lib/doggy/models/monitor.rb +10 -0
- data/lib/doggy/version.rb +1 -1
- data/lib/doggy.rb +20 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fffcdb181744f9d0f48b41877151bb8c39e4ed9
|
4
|
+
data.tar.gz: 576233b7f36fe9004d89f40caaa84c2dec38e5b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4299cf9f9f02e9649c7c4e5df28f5a32e470e3ba7f49668e4523d51b5816138d972a66446311a1c6affd5562d864f5926c0526221bdb86ac299a33f7e1225dc
|
7
|
+
data.tar.gz: 8ab7493ec5d0c58b8925d393200364b457bc8fe2db40626a85a4f9c5c6e44b09cd405a1e5053d7e77cb970cb0997c54ccf6bd483806e119f971f6b5ba5f0acdb
|
data/Gemfile.lock
CHANGED
data/lib/doggy/cli/pull.rb
CHANGED
@@ -2,37 +2,61 @@
|
|
2
2
|
|
3
3
|
module Doggy
|
4
4
|
class CLI::Pull
|
5
|
-
def initialize(options,
|
6
|
-
@options
|
7
|
-
@
|
8
|
-
@updated_by_last_action = false
|
5
|
+
def initialize(options, ids_or_names)
|
6
|
+
@options = options
|
7
|
+
@ids_or_names = ids_or_names
|
9
8
|
end
|
10
9
|
|
11
10
|
def run
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
if @ids_or_names.empty?
|
12
|
+
pull_resources('dashboards', Models::Dashboard)
|
13
|
+
pull_resources('monitors', Models::Monitor)
|
14
|
+
pull_resources('screens', Models::Screen)
|
15
|
+
return
|
16
|
+
end
|
15
17
|
|
16
|
-
|
18
|
+
@ids_or_names.each do |id_or_name|
|
19
|
+
@local_resources = Doggy::Model.all_local_resources
|
20
|
+
if id_or_name =~ /^\d+$/
|
21
|
+
pull_by_id(id_or_name.to_i)
|
22
|
+
else
|
23
|
+
pull_by_file(id_or_name)
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
private
|
20
29
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
30
|
+
def pull_by_id(id)
|
31
|
+
local_resource = @local_resources.find { |l| l.id == id }
|
32
|
+
if !local_resource
|
33
|
+
remote_resource = [Models::Dashboard, Models::Monitor, Models::Screen].map do |klass|
|
34
|
+
klass.find(id)
|
35
|
+
end.compact.first
|
24
36
|
|
25
|
-
|
26
|
-
if ids.any?
|
27
|
-
Doggy.ui.say "Pulling #{ name }: #{ids.join(', ')}"
|
28
|
-
remote_resources = klass.all.find_all { |m| ids.include?(m.id.to_s) }
|
37
|
+
remote_resource.save_local
|
29
38
|
else
|
30
|
-
|
31
|
-
|
39
|
+
remote_resource = local_resource.class.find(local_resource.id)
|
40
|
+
remote_resource.path = local_resource.path
|
41
|
+
remote_resource.save_local
|
32
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def pull_by_file(file)
|
46
|
+
resolved_path = Doggy.resolve_path(file)
|
47
|
+
local_resource = @local_resources.find { |l| l.path == resolved_path }
|
48
|
+
|
49
|
+
remote_resource = local_resource.class.find(local_resource.id)
|
50
|
+
remote_resource.path = local_resource.path
|
51
|
+
remote_resource.save_local
|
52
|
+
end
|
53
|
+
|
54
|
+
def pull_resources(name, klass)
|
55
|
+
Doggy.ui.say "Pulling #{ name }..."
|
33
56
|
local_resources = klass.all_local
|
57
|
+
remote_resources = klass.all
|
58
|
+
|
34
59
|
klass.assign_paths(remote_resources, local_resources)
|
35
|
-
@updated_by_last_action = true
|
36
60
|
remote_resources.each(&:save_local)
|
37
61
|
end
|
38
62
|
end
|
data/lib/doggy/model.rb
CHANGED
@@ -56,6 +56,12 @@ module Doggy
|
|
56
56
|
Parallel.map(ids) { |id| find(id) }
|
57
57
|
end
|
58
58
|
|
59
|
+
def all_local_resources
|
60
|
+
@resources ||= [ Models::Dashboard,
|
61
|
+
Models::Monitor,
|
62
|
+
Models::Screen ].flat_map(&:all_local)
|
63
|
+
end
|
64
|
+
|
59
65
|
def all_local(only_changed: false)
|
60
66
|
@all_local ||= begin
|
61
67
|
# TODO: Add serializer support here
|
@@ -176,6 +182,7 @@ module Doggy
|
|
176
182
|
|
177
183
|
def save
|
178
184
|
ensure_managed_emoji!
|
185
|
+
ensure_renotify_interval_valid
|
179
186
|
|
180
187
|
body = JSON.dump(to_h)
|
181
188
|
if !id then
|
data/lib/doggy/models/monitor.rb
CHANGED
@@ -13,6 +13,7 @@ module Doggy
|
|
13
13
|
attribute :no_data_timeframe, Integer
|
14
14
|
attribute :timeout_h, Integer
|
15
15
|
attribute :escalation_message, String
|
16
|
+
attribute :renotify_interval, Integer
|
16
17
|
|
17
18
|
def to_h
|
18
19
|
return super unless monitor.id && monitor.loading_source == :local
|
@@ -58,6 +59,15 @@ module Doggy
|
|
58
59
|
self.name += " \xF0\x9F\x90\xB6"
|
59
60
|
end
|
60
61
|
|
62
|
+
def ensure_renotify_interval_valid
|
63
|
+
return unless options && options.renotify_interval && options.renotify_interval.to_i > 0
|
64
|
+
|
65
|
+
allowed_renotify_intervals = [10,20,30,40,50,60,90,120,180,240,300,360,720,1440] # minutes
|
66
|
+
best_matching_interval = allowed_renotify_intervals.min_by { |x| (x.to_f - options.renotify_interval).abs }
|
67
|
+
puts "WARN: Monitor #{self.id} uses invalid escalation interval (renotify_interval) #{options.renotify_interval}, using #{best_matching_interval} instead"
|
68
|
+
options.renotify_interval = best_matching_interval
|
69
|
+
end
|
70
|
+
|
61
71
|
def mute
|
62
72
|
return unless id
|
63
73
|
request(:post, "#{ resource_url(id) }/mute")
|
data/lib/doggy/version.rb
CHANGED
data/lib/doggy.rb
CHANGED
@@ -57,19 +57,28 @@ module Doggy
|
|
57
57
|
|
58
58
|
def modified(compare_to, all = false)
|
59
59
|
@modified ||= begin
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
mods = Set.new
|
61
|
+
paths = repo.diff(compare_to, 'HEAD').each_delta.map { |delta| delta.new_file[:path] }
|
62
|
+
paths.each do |path|
|
63
|
+
parts = path.split('/')
|
64
|
+
next unless parts[0] =~ /objects/
|
65
|
+
next unless File.exist?(path)
|
66
|
+
mods << path
|
67
|
+
end
|
68
|
+
mods
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def resolve_path(path)
|
73
|
+
path = Pathname.new(path)
|
74
|
+
curr_dir = Pathname.new(Dir.pwd)
|
75
|
+
resolved = object_root.relative_path_from(curr_dir)
|
76
|
+
|
77
|
+
(curr_dir.expand_path(resolved + path) + path).to_s
|
70
78
|
end
|
71
79
|
|
72
|
-
|
80
|
+
|
81
|
+
protected
|
73
82
|
|
74
83
|
def secrets
|
75
84
|
@secrets ||= begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doggy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Gorodetsky
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|