gazer 0.3.14 → 0.3.16

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
  SHA256:
3
- metadata.gz: 9a45bc83d3cc6afb4d179b5d93bf874811b18213f8a8979af419dc5a191f2332
4
- data.tar.gz: 72d270880b6ab6ebc44eed23782280036e16a719af8ed073a2c7acb854b9f418
3
+ metadata.gz: 4f0f256eacac62e394fa8bb882ccee6f8a52d8a0c82581a91c492482b1a2c8c8
4
+ data.tar.gz: d8de023ad0a721adf0dde8efc9114f2f6067a56d64f16f7577e85e2895a52c70
5
5
  SHA512:
6
- metadata.gz: 5f8dab93d6b63873d6681ad3bb748ca62a7402225670cfcd9bec63ace0be0ede5e1a2b7ec51d701086c4a6f3d8bf536c92d1d03f71891a00723d0a2fab741bed
7
- data.tar.gz: 8d347022daaa8e4e4f99144de0b22a1a3cbbe5ac87fe2ca3f36323ba6297742e67504bc54981beb786d2281cac178b7c68f0745117671e6ccced0835ba4e7d4f
6
+ metadata.gz: 9b7cb6713fb821ede6bb0ab3618f3aede193b43e0e5b79b9c7fc0f070f692e3c9c224329167d4ed40e018fd769a573c5a166aef8121ebdc865a1a85624b05d5d
7
+ data.tar.gz: f7678128d9fc3e418b0aee31ae7902fd2c927183f1ad67f5d32597776e3d6b3d039635c41533ff8868d21f6638ad09a50d6ea0ac7213a9a3c9326855f9f8f6d5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.16](https://github.com/looker-open-source/gzr/compare/v0.3.15...v0.3.16) (2024-06-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * randomize a specific alert by alert_id ([0e9cf40](https://github.com/looker-open-source/gzr/commit/0e9cf401346845d4f740a75379161cecddf1669b))
9
+ * randomize a specific plan by plan_id ([99d30f1](https://github.com/looker-open-source/gzr/commit/99d30f1747eafa81989bfd3bfc728c5a367fc1e3))
10
+
11
+ ## [0.3.15](https://github.com/looker-open-source/gzr/compare/v0.3.14...v0.3.15) (2024-06-12)
12
+
13
+
14
+ ### Features
15
+
16
+ * Alert randomization ([f367d8e](https://github.com/looker-open-source/gzr/commit/f367d8e5e0d164cf5cf1d9b7e79ed93fd2c0ea62))
17
+ * Plan randomization ([3176fe0](https://github.com/looker-open-source/gzr/commit/3176fe0032c237adcb7b95d821e0f54323e19221))
18
+
3
19
  ## [0.3.14](https://github.com/looker-open-source/gzr/compare/v0.3.13...v0.3.14) (2024-03-11)
4
20
 
5
21
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.3.14)
4
+ gazer (0.3.16)
5
5
  faraday (~> 2.7.8)
6
6
  faraday-multipart (~> 1.0)
7
7
  looker-sdk (~> 0.1.6)
@@ -0,0 +1,96 @@
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(alert_id,options)
37
+ super()
38
+ @alert_id = alert_id
39
+ @options = options
40
+ end
41
+
42
+ def execute(input: $stdin, output: $stdout)
43
+ say_warning(@options) if @options[:debug]
44
+
45
+ window = @options[:window]
46
+ if window < 1 or window > 60
47
+ say_error("window must be between 1 and 60")
48
+ raise Gzr::CLI::Error.new()
49
+ end
50
+
51
+ with_session do
52
+ @me ||= query_me("id")
53
+
54
+ if @alert_id
55
+ alert = get_alert(@alert_id)
56
+ if alert
57
+ randomize_alert(alert,window)
58
+ else
59
+ say_warning("Alert #{@alert_id} not found")
60
+ end
61
+ else
62
+ req = {}
63
+ req[:disabled] = false
64
+ req[:all_owners] = @options[:all] unless @options[:all].nil?
65
+ alerts = search_alerts(**req)
66
+ begin
67
+ say_ok "No alerts found"
68
+ return nil
69
+ end unless alerts && alerts.length > 0
70
+
71
+ alerts.each do |alert|
72
+ randomize_alert(alert,window)
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+
79
+ def randomize_alert(alert,window=60)
80
+ crontab = alert[:cron]
81
+ if crontab == ""
82
+ say_warning("skipping alert #{alert[:id]} with no cron")
83
+ return
84
+ end
85
+ crontab = randomize_cron(crontab, window)
86
+ begin
87
+ alert[:cron] = crontab
88
+ update_alert(alert[:id], alert)
89
+ rescue LookerSDK::UnprocessableEntity => e
90
+ say_warning("Skipping invalid entry")
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -51,6 +51,22 @@ module Gzr
51
51
  end
52
52
  end
53
53
 
54
+ desc 'randomize [ALERT_ID]', '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(alert_id=nil)
62
+ if options[:help]
63
+ invoke :help, ['randomize']
64
+ else
65
+ require_relative 'alert/randomize'
66
+ Gzr::Commands::Alert::Randomize.new(alert_id,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,86 @@
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(plan_id,options)
37
+ super()
38
+ @plan_id = plan_id
39
+ @options = options
40
+ end
41
+
42
+ def execute(input: $stdin, output: $stdout)
43
+ say_warning("options: #{@options.inspect}") if @options[:debug]
44
+
45
+ window = @options[:window]
46
+ if window < 1 or window > 60
47
+ say_error("window must be between 1 and 60")
48
+ raise Gzr::CLI::Error.new()
49
+ end
50
+
51
+ with_session do
52
+ @me ||= query_me("id")
53
+
54
+ if @plan_id
55
+ plan = query_scheduled_plan(@plan_id)
56
+ if plan
57
+ randomize_plan(plan,window)
58
+ else
59
+ say_warning("Plan #{@plan_id} not found")
60
+ end
61
+ else
62
+ plans = query_all_scheduled_plans( @options[:all]?'all':@me[:id] )
63
+ plans.each do |plan|
64
+ randomize_plan(plan,window)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def randomize_plan(plan,window=60)
71
+ crontab = plan[:crontab]
72
+ if crontab == ""
73
+ say_warning("skipping plan #{plan[:id]} with no crontab")
74
+ return
75
+ end
76
+ crontab = randomize_cron(crontab, window)
77
+ begin
78
+ update_scheduled_plan(plan[:id], { crontab: crontab })
79
+ rescue LookerSDK::UnprocessableEntity => e
80
+ say_warning("Skipping invalid entry")
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -128,7 +128,7 @@ module Gzr
128
128
  desc 'ls', 'List the scheduled plans on a server'
129
129
  method_option :help, aliases: '-h', type: :boolean,
130
130
  desc: 'Display usage information'
131
- method_option :fields, type: :string, default: 'id,enabled,name,user(id,display_name),look_id,dashboard_id,lookml_dashboard_id',
131
+ method_option :fields, type: :string, default: 'id,enabled,name,user(id,display_name),look_id,dashboard_id,lookml_dashboard_id,crontab',
132
132
  desc: 'Fields to display'
133
133
  method_option :disabled, type: :boolean,
134
134
  desc: 'Retrieve disable plans'
@@ -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 [PLAN_ID]', '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(plan_id = nil)
156
+ if options[:help]
157
+ invoke :help, ['randomize']
158
+ else
159
+ require_relative 'plan/randomize'
160
+ Gzr::Commands::Plan::Randomize.new(plan_id, options).execute
161
+ end
162
+ end
147
163
  end
148
164
  end
149
165
  end
@@ -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 if /^[[:digit:]]+$/.match? cronfields[1]
48
+ return cronfields.join(' ')
49
+ end
50
+ end
51
+ end
data/lib/gzr/version.rb CHANGED
@@ -20,5 +20,5 @@
20
20
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  module Gzr
23
- VERSION = '0.3.14'.freeze
23
+ VERSION = '0.3.16'.freeze
24
24
  end
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.14
4
+ version: 0.3.16
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-03-11 00:00:00.000000000 Z
11
+ date: 2024-06-27 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