gazer 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/gzr/commands/alert/randomize.rb +82 -0
- data/lib/gzr/commands/alert.rb +16 -0
- data/lib/gzr/commands/plan/randomize.rb +72 -0
- data/lib/gzr/commands/plan.rb +16 -0
- data/lib/gzr/modules/alert.rb +10 -0
- data/lib/gzr/modules/cron.rb +51 -0
- data/lib/gzr/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19da88dfdf66e5ee6b7d206b737004e50944ee708320ae299ab3cffa572e93fc
|
4
|
+
data.tar.gz: 5f8e87c4aa8d1c49f72981eb4f31ee8acc7a480279b6ae186130b3f87c82ae97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b314d1e8f9211e4cb169d1f962ce24372c15c8ece2a5c80e18a351ed09f1d00e68123359c5620f366cfb8cf17dd72ff646eb43ffb2d769d2abeb6591fb6d10d
|
7
|
+
data.tar.gz: a99be73907a90200453fc1959ca4fa3de1599704df6e003f908ac0e69c116f6c29be0198a24dde339ea1380c648e5f18c92b37f98b7f68f69ec07623c2203167
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.3.15](https://github.com/looker-open-source/gzr/compare/v0.3.14...v0.3.15) (2024-06-12)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* Alert randomization ([f367d8e](https://github.com/looker-open-source/gzr/commit/f367d8e5e0d164cf5cf1d9b7e79ed93fd2c0ea62))
|
9
|
+
* Plan randomization ([3176fe0](https://github.com/looker-open-source/gzr/commit/3176fe0032c237adcb7b95d821e0f54323e19221))
|
10
|
+
|
3
11
|
## [0.3.14](https://github.com/looker-open-source/gzr/compare/v0.3.13...v0.3.14) (2024-03-11)
|
4
12
|
|
5
13
|
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/alert'
|
26
|
+
require_relative '../../modules/user'
|
27
|
+
require_relative '../../modules/cron'
|
28
|
+
|
29
|
+
module Gzr
|
30
|
+
module Commands
|
31
|
+
class Alert
|
32
|
+
class Randomize < Gzr::Command
|
33
|
+
include Gzr::Alert
|
34
|
+
include Gzr::User
|
35
|
+
include Gzr::Cron
|
36
|
+
def initialize(options)
|
37
|
+
super()
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(input: $stdin, output: $stdout)
|
42
|
+
say_warning(@options) if @options[:debug]
|
43
|
+
|
44
|
+
window = @options[:window]
|
45
|
+
if window < 1 or window > 60
|
46
|
+
say_error("window must be between 1 and 60")
|
47
|
+
raise Gzr::CLI::Error.new()
|
48
|
+
end
|
49
|
+
|
50
|
+
with_session do
|
51
|
+
@me ||= query_me("id")
|
52
|
+
|
53
|
+
req = {}
|
54
|
+
req[:disabled] = false
|
55
|
+
req[:all_owners] = @options[:all] unless @options[:all].nil?
|
56
|
+
alerts = search_alerts(**req)
|
57
|
+
begin
|
58
|
+
say_ok "No alerts found"
|
59
|
+
return nil
|
60
|
+
end unless alerts && alerts.length > 0
|
61
|
+
|
62
|
+
alerts.each do |alert|
|
63
|
+
crontab = alert[:cron]
|
64
|
+
if crontab == ""
|
65
|
+
say_warning("skipping alert #{alert[:id]} with no cron")
|
66
|
+
next
|
67
|
+
end
|
68
|
+
crontab = randomize_cron(crontab, window)
|
69
|
+
begin
|
70
|
+
alert[:cron] = crontab
|
71
|
+
update_alert(alert[:id], alert)
|
72
|
+
rescue LookerSDK::UnprocessableEntity => e
|
73
|
+
say_warning("Skipping invalid entry")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/gzr/commands/alert.rb
CHANGED
@@ -51,6 +51,22 @@ module Gzr
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
desc 'randomize', 'Randomize the scheduled alerts on a server'
|
55
|
+
method_option :help, aliases: '-h', type: :boolean,
|
56
|
+
desc: 'Display usage information'
|
57
|
+
method_option :window, type: :numeric, default: 60,
|
58
|
+
desc: 'Length of window'
|
59
|
+
method_option :all, type: :boolean,
|
60
|
+
desc: 'Randomize all alerts regardless of owner'
|
61
|
+
def randomize(*)
|
62
|
+
if options[:help]
|
63
|
+
invoke :help, ['randomize']
|
64
|
+
else
|
65
|
+
require_relative 'alert/randomize'
|
66
|
+
Gzr::Commands::Alert::Randomize.new(options).execute
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
54
70
|
desc 'cat ALERT_ID', 'Output json information about an alert to screen or file'
|
55
71
|
method_option :help, aliases: '-h', type: :boolean,
|
56
72
|
desc: 'Display usage information'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/plan'
|
26
|
+
require_relative '../../modules/user'
|
27
|
+
require_relative '../../modules/cron'
|
28
|
+
|
29
|
+
module Gzr
|
30
|
+
module Commands
|
31
|
+
class Plan
|
32
|
+
class Randomize < Gzr::Command
|
33
|
+
include Gzr::Plan
|
34
|
+
include Gzr::User
|
35
|
+
include Gzr::Cron
|
36
|
+
def initialize(options)
|
37
|
+
super()
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(input: $stdin, output: $stdout)
|
42
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
43
|
+
|
44
|
+
window = @options[:window]
|
45
|
+
if window < 1 or window > 60
|
46
|
+
say_error("window must be between 1 and 60")
|
47
|
+
raise Gzr::CLI::Error.new()
|
48
|
+
end
|
49
|
+
|
50
|
+
with_session do
|
51
|
+
@me ||= query_me("id")
|
52
|
+
|
53
|
+
plans = query_all_scheduled_plans( @options[:all]?'all':@me[:id] )
|
54
|
+
plans.each do |plan|
|
55
|
+
crontab = plan[:crontab]
|
56
|
+
if crontab == ""
|
57
|
+
say_warning("skipping plan #{plan[:id]} with no crontab")
|
58
|
+
next
|
59
|
+
end
|
60
|
+
crontab = randomize_cron(crontab, window)
|
61
|
+
begin
|
62
|
+
update_scheduled_plan(plan[:id], { crontab: crontab })
|
63
|
+
rescue LookerSDK::UnprocessableEntity => e
|
64
|
+
say_warning("Skipping invalid entry")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/gzr/commands/plan.rb
CHANGED
@@ -144,6 +144,22 @@ module Gzr
|
|
144
144
|
Gzr::Commands::Plan::Ls.new(options).execute
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
desc 'randomize', 'Randomize the scheduled plans on a server'
|
149
|
+
method_option :help, aliases: '-h', type: :boolean,
|
150
|
+
desc: 'Display usage information'
|
151
|
+
method_option :window, type: :numeric, default: 60,
|
152
|
+
desc: 'Length of window'
|
153
|
+
method_option :all, type: :boolean,
|
154
|
+
desc: 'Randomize all plans regardless of owner'
|
155
|
+
def randomize(*)
|
156
|
+
if options[:help]
|
157
|
+
invoke :help, ['randomize']
|
158
|
+
else
|
159
|
+
require_relative 'plan/randomize'
|
160
|
+
Gzr::Commands::Plan::Randomize.new(options).execute
|
161
|
+
end
|
162
|
+
end
|
147
163
|
end
|
148
164
|
end
|
149
165
|
end
|
data/lib/gzr/modules/alert.rb
CHANGED
@@ -178,5 +178,15 @@ module Gzr
|
|
178
178
|
raise
|
179
179
|
end
|
180
180
|
end
|
181
|
+
|
182
|
+
def update_alert(alert_id,req)
|
183
|
+
begin
|
184
|
+
@sdk.update_alert(alert_id,req).to_attrs
|
185
|
+
rescue LookerSDK::Error => e
|
186
|
+
say_error "Error calling update_alert(#{alert_id}, #{JSON.pretty_generate(req)})"
|
187
|
+
say_error e
|
188
|
+
raise
|
189
|
+
end
|
190
|
+
end
|
181
191
|
end
|
182
192
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
module Gzr
|
25
|
+
module Cron
|
26
|
+
def randomize_cron(crontab, window=60)
|
27
|
+
cronfields = crontab.split(%r{\s+})
|
28
|
+
minute = cronfields[0].to_i
|
29
|
+
hour = cronfields[1].to_i
|
30
|
+
factor = rand(window) - (window/2)
|
31
|
+
minute = minute + factor
|
32
|
+
if minute < 0
|
33
|
+
hour = hour - 1
|
34
|
+
minute = minute + 60
|
35
|
+
end
|
36
|
+
if hour < 0
|
37
|
+
hour = 23
|
38
|
+
end
|
39
|
+
if minute > 59
|
40
|
+
hour = hour + 1
|
41
|
+
minute = minute - 60
|
42
|
+
end
|
43
|
+
if hour > 23
|
44
|
+
hour = 0
|
45
|
+
end
|
46
|
+
cronfields[0] = minute
|
47
|
+
cronfields[1] = hour
|
48
|
+
return cronfields.join(' ')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/gzr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gazer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike DeAngelo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-reader
|
@@ -299,6 +299,7 @@ files:
|
|
299
299
|
- lib/gzr/commands/alert/import.rb
|
300
300
|
- lib/gzr/commands/alert/ls.rb
|
301
301
|
- lib/gzr/commands/alert/notifications.rb
|
302
|
+
- lib/gzr/commands/alert/randomize.rb
|
302
303
|
- lib/gzr/commands/alert/read.rb
|
303
304
|
- lib/gzr/commands/alert/threshold.rb
|
304
305
|
- lib/gzr/commands/alert/unfollow.rb
|
@@ -365,6 +366,7 @@ files:
|
|
365
366
|
- lib/gzr/commands/plan/failures.rb
|
366
367
|
- lib/gzr/commands/plan/import.rb
|
367
368
|
- lib/gzr/commands/plan/ls.rb
|
369
|
+
- lib/gzr/commands/plan/randomize.rb
|
368
370
|
- lib/gzr/commands/plan/rm.rb
|
369
371
|
- lib/gzr/commands/plan/run.rb
|
370
372
|
- lib/gzr/commands/project.rb
|
@@ -405,6 +407,7 @@ files:
|
|
405
407
|
- lib/gzr/modules/alert.rb
|
406
408
|
- lib/gzr/modules/attribute.rb
|
407
409
|
- lib/gzr/modules/connection.rb
|
410
|
+
- lib/gzr/modules/cron.rb
|
408
411
|
- lib/gzr/modules/dashboard.rb
|
409
412
|
- lib/gzr/modules/filehelper.rb
|
410
413
|
- lib/gzr/modules/folder.rb
|