gazer 0.3.1 → 0.3.2
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/gzr/cli.rb +4 -1
- data/lib/gzr/command.rb +73 -1
- data/lib/gzr/commands/alert/cat.rb +52 -0
- data/lib/gzr/commands/alert/chown.rb +48 -0
- data/lib/gzr/commands/alert/delete.rb +47 -0
- data/lib/gzr/commands/alert/disable.rb +48 -0
- data/lib/gzr/commands/alert/enable.rb +47 -0
- data/lib/gzr/commands/alert/follow.rb +47 -0
- data/lib/gzr/commands/alert/import.rb +65 -0
- data/lib/gzr/commands/alert/ls.rb +76 -0
- data/lib/gzr/commands/alert/notifications.rb +74 -0
- data/lib/gzr/commands/alert/read.rb +49 -0
- data/lib/gzr/commands/alert/threshold.rb +48 -0
- data/lib/gzr/commands/alert/unfollow.rb +47 -0
- data/lib/gzr/commands/alert.rb +200 -0
- data/lib/gzr/commands/dashboard/cat.rb +1 -1
- data/lib/gzr/commands/dashboard/import.rb +12 -1
- data/lib/gzr/modules/alert.rb +169 -0
- data/lib/gzr/modules/dashboard.rb +23 -2
- data/lib/gzr/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e630fbc5e90c7e94aab072a64ab725a78478dac8d6009b1b61c753af0146d13e
|
4
|
+
data.tar.gz: 4c2f9b5227addbc40bc59f813f0139bcb4b56622f87ba71d975c8ab9f7c7040c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ed72435dbf7192b52d45c67bf3180f27d3b3a1bef4575748ea28762df6c63449712256b9313a4456f4ee2d60835f1a727490fc699d86930db3bfdccfd5d92ef
|
7
|
+
data.tar.gz: 7b0998e2ffe58768867e66fc345450bd0e365de1936a09d8de4cb56f689ee283896b326dc27dc5ab3ac49a9f79a1c7d5364cbff152be0335d8e3c3d206fada63
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.3.2](https://github.com/looker-open-source/gzr/compare/v0.3.1...v0.3.2) (2023-04-21)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* Alerts management through gazer ([#180](https://github.com/looker-open-source/gzr/issues/180)) ([74d0307](https://github.com/looker-open-source/gzr/commit/74d0307d63602df5efad98e7c8e92b91740a4afc))
|
9
|
+
|
3
10
|
## [0.3.1](https://github.com/looker-open-source/gzr/compare/v0.3.0...v0.3.1) (2023-04-20)
|
4
11
|
|
5
12
|
|
data/Gemfile.lock
CHANGED
data/lib/gzr/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -58,6 +58,9 @@ module Gzr
|
|
58
58
|
map %w(--version -v) => :version
|
59
59
|
map space: :folder # Alias space command to folder
|
60
60
|
|
61
|
+
require_relative 'commands/alert'
|
62
|
+
register Gzr::Commands::Alert, 'alert', 'alert [SUBCOMMAND]', 'Command description...'
|
63
|
+
|
61
64
|
require_relative 'commands/attribute'
|
62
65
|
register Gzr::Commands::Attribute, 'attribute', 'attribute [SUBCOMMAND]', 'Command description...'
|
63
66
|
|
data/lib/gzr/command.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT icense (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -52,6 +52,18 @@ module Gzr
|
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
+
def get_user_by_id(user_id, req=nil)
|
56
|
+
user = nil
|
57
|
+
begin
|
58
|
+
user = @sdk.user(user_id, req)
|
59
|
+
rescue LookerSDK::Error => e
|
60
|
+
say_error "Error querying get_user_by_id(#{user_id})"
|
61
|
+
say_error e
|
62
|
+
raise
|
63
|
+
end
|
64
|
+
user
|
65
|
+
end
|
66
|
+
|
55
67
|
def query(query_id)
|
56
68
|
data = nil
|
57
69
|
begin
|
@@ -389,6 +401,66 @@ module Gzr
|
|
389
401
|
parts.join('&.')
|
390
402
|
end
|
391
403
|
|
404
|
+
|
405
|
+
# This version of field names yields an expression that can be evaluated against a hash structure
|
406
|
+
# like this one...
|
407
|
+
#
|
408
|
+
# data&.fetch(:a,nil)
|
409
|
+
# val1
|
410
|
+
# data&.fetch(:b,nil)
|
411
|
+
# val2
|
412
|
+
# data&.fetch(:c,nil)&.fetch(:d,nil)
|
413
|
+
# val3
|
414
|
+
# data&.fetch(:c,nil)&.fetch(:e,nil)&.fetch(:f,nil)
|
415
|
+
# val4
|
416
|
+
# data&.fetch(:c,nil)&.fetch(:e,nil)&.fetch(:g,nil)
|
417
|
+
# val5
|
418
|
+
# data&.fetch(:h,nil)
|
419
|
+
# val6
|
420
|
+
#
|
421
|
+
# data =
|
422
|
+
# {
|
423
|
+
# a: "val",
|
424
|
+
# b: "val",
|
425
|
+
# c: {
|
426
|
+
# d: "val",
|
427
|
+
# e: {
|
428
|
+
# f: "val",
|
429
|
+
# g: "val"
|
430
|
+
# }
|
431
|
+
# },
|
432
|
+
# h: "val"
|
433
|
+
# }
|
434
|
+
#
|
435
|
+
# field_names_hash(fields).each do |field|
|
436
|
+
# puts "data#{field}"
|
437
|
+
# puts eval "data#{field}"
|
438
|
+
# end
|
439
|
+
|
440
|
+
def field_names_hash(opt_fields)
|
441
|
+
fields = []
|
442
|
+
token_stack = []
|
443
|
+
last_token = false
|
444
|
+
tokens = opt_fields.split /(\(|,|\))/
|
445
|
+
tokens << nil
|
446
|
+
tokens.each do |t|
|
447
|
+
if t == '(' then
|
448
|
+
token_stack.push(last_token)
|
449
|
+
elsif t.nil? || t == ',' then
|
450
|
+
fields << "&.fetch(:#{(token_stack + [last_token]).join(',nil)&.fetch(:')},nil)" if last_token
|
451
|
+
elsif t.empty? then
|
452
|
+
next
|
453
|
+
elsif t == ')' then
|
454
|
+
fields << "&.fetch(:#{(token_stack + [last_token]).join(',nil)&.fetch(:')},nil)" if last_token
|
455
|
+
token_stack.pop
|
456
|
+
last_token = false
|
457
|
+
else
|
458
|
+
last_token = t
|
459
|
+
end
|
460
|
+
end
|
461
|
+
fields
|
462
|
+
end
|
463
|
+
|
392
464
|
##
|
393
465
|
# This method will accept two arrays, a and b, and create a third array
|
394
466
|
# like [ [a[0],b[0]], [a[1],b[1]], [a[2],b[2]], ...].
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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/filehelper'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Alert
|
31
|
+
class Cat < Gzr::Command
|
32
|
+
include Gzr::Alert
|
33
|
+
include Gzr::FileHelper
|
34
|
+
def initialize(alert_id,options)
|
35
|
+
super()
|
36
|
+
@alert_id = alert_id
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(input: $stdin, output: $stdout)
|
41
|
+
say_warning(@options) if @options[:debug]
|
42
|
+
with_session do
|
43
|
+
alert = get_alert(@alert_id)
|
44
|
+
write_file(@options[:dir] ? "Alert_#{alert.id}_#{alert.field.name}.json" : nil, @options[:dir],nil, output) do |f|
|
45
|
+
f.puts JSON.pretty_generate(alert.to_attrs)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Chown < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id,owner_id,options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@owner_id = owner_id
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
update_alert_field(@alert_id, owner_id: @owner_id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Delete < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id,options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
delete_alert(@alert_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Disable < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id, disabled_reason, options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@disabled_reason = disabled_reason
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
update_alert_field(@alert_id, is_disabled: true, disabled_reason: @disabled_reason)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Enable < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id,options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
update_alert_field(@alert_id, is_disabled: false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Follow < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id,options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
follow_alert(@alert_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 '../../../gzr'
|
25
|
+
require_relative '../../command'
|
26
|
+
require_relative '../../modules/alert'
|
27
|
+
require_relative '../../modules/user'
|
28
|
+
require_relative '../../modules/filehelper'
|
29
|
+
|
30
|
+
module Gzr
|
31
|
+
module Commands
|
32
|
+
class Alert
|
33
|
+
class Import < Gzr::Command
|
34
|
+
include Gzr::Alert
|
35
|
+
include Gzr::User
|
36
|
+
include Gzr::FileHelper
|
37
|
+
def initialize(file, dashboard_element_id, options)
|
38
|
+
super()
|
39
|
+
@file = file
|
40
|
+
@dashboard_element_id = dashboard_element_id
|
41
|
+
@options = options
|
42
|
+
end
|
43
|
+
|
44
|
+
def execute(input: $stdin, output: $stdout)
|
45
|
+
say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
|
46
|
+
with_session do
|
47
|
+
|
48
|
+
@me ||= query_me("id")
|
49
|
+
|
50
|
+
read_file(@file) do |data|
|
51
|
+
data.select! do |k,v|
|
52
|
+
keys_to_keep('create_alert').include? k
|
53
|
+
end
|
54
|
+
data[:owner_id] = @me[:id]
|
55
|
+
data[:dashboard_element_id] = @dashboard_element_id if @dashboard_element_id
|
56
|
+
alert = create_alert(data)
|
57
|
+
output.puts "Imported alert #{alert[:id]}" unless @options[:plain]
|
58
|
+
output.puts alert[:id] if @options[:plain]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 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 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Alert
|
31
|
+
class Ls < Gzr::Command
|
32
|
+
include Gzr::Alert
|
33
|
+
def initialize(options)
|
34
|
+
super()
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
req = {}
|
42
|
+
req[:fields] = @options[:fields] unless @options[:fields].nil?
|
43
|
+
req[:disabled] = @options[:disabled] unless @options[:disabled].nil?
|
44
|
+
req[:all_owners] = @options[:all] unless @options[:all].nil?
|
45
|
+
data = search_alerts(**req)
|
46
|
+
begin
|
47
|
+
say_ok "No alerts found"
|
48
|
+
return nil
|
49
|
+
end unless data && data.length > 0
|
50
|
+
|
51
|
+
table_hash = Hash.new
|
52
|
+
fields = field_names(@options[:fields])
|
53
|
+
table_hash[:header] = fields unless @options[:plain]
|
54
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
55
|
+
table_hash[:rows] = data.map do |row|
|
56
|
+
expressions.collect do |e|
|
57
|
+
eval "row.#{e}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
table = TTY::Table.new(table_hash)
|
61
|
+
alignments = fields.collect do |k|
|
62
|
+
(k =~ /id$/) ? :right : :left
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
if @options[:csv] then
|
66
|
+
output.puts render_csv(table)
|
67
|
+
else
|
68
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
|
69
|
+
end
|
70
|
+
end if table
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Alert
|
31
|
+
class Notifications < Gzr::Command
|
32
|
+
include Gzr::Alert
|
33
|
+
def initialize(options)
|
34
|
+
super()
|
35
|
+
@options = options
|
36
|
+
@fields = "notification_id,alert_condition_id,user_id,is_read,field_value,threshold_value,ran_at,alert(title,alert_id,investigative_content_id,dashboard_name,dashboard_id,query_slug)"
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
data = alert_notifications()
|
43
|
+
|
44
|
+
begin
|
45
|
+
puts "No notifications returned"
|
46
|
+
return nil
|
47
|
+
end unless data && data.length > 0
|
48
|
+
|
49
|
+
table_hash = Hash.new
|
50
|
+
fields = field_names(@fields)
|
51
|
+
table_hash[:header] = fields unless @options[:plain]
|
52
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
53
|
+
table_hash[:rows] = data.map do |row|
|
54
|
+
expressions.collect do |e|
|
55
|
+
eval "row.#{e}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
table = TTY::Table.new(table_hash)
|
59
|
+
alignments = fields.collect do |k|
|
60
|
+
(k =~ /id$/) ? :right : :left
|
61
|
+
end
|
62
|
+
begin
|
63
|
+
if @options[:csv] then
|
64
|
+
output.puts render_csv(table)
|
65
|
+
else
|
66
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
|
67
|
+
end
|
68
|
+
end if table
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Read < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(notification_id,options)
|
33
|
+
super()
|
34
|
+
@notification_id = notification_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
data = read_alert_notification(@notification_id)
|
42
|
+
output.puts JSON.pretty_generate(data) unless (data.nil? || data.empty?)
|
43
|
+
output.puts "No notification found" if (data.nil? || data.empty?)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Threshold < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id, threshold, options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@threshold = threshold
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
update_alert_field(@alert_id, threshold: @threshold)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Alert
|
30
|
+
class Unfollow < Gzr::Command
|
31
|
+
include Gzr::Alert
|
32
|
+
def initialize(alert_id,options)
|
33
|
+
super()
|
34
|
+
@alert_id = alert_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
unfollow_alert(@alert_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 'thor'
|
25
|
+
|
26
|
+
module Gzr
|
27
|
+
module Commands
|
28
|
+
class Alert < Thor
|
29
|
+
|
30
|
+
namespace :alert
|
31
|
+
|
32
|
+
desc 'ls', 'list alerts'
|
33
|
+
method_option :help, aliases: '-h', type: :boolean,
|
34
|
+
desc: 'Display usage information'
|
35
|
+
method_option :fields, type: :string, default: 'id,field(title,name),comparison_type,threshold,cron,custom_title,dashboard_element_id,description',
|
36
|
+
desc: 'Fields to display'
|
37
|
+
method_option :disabled, type: :boolean, default: nil,
|
38
|
+
desc: 'return disabled alerts'
|
39
|
+
method_option :all, type: :boolean, default: nil,
|
40
|
+
desc: 'return alerts from all users (must be admin)'
|
41
|
+
method_option :plain, type: :boolean, default: false,
|
42
|
+
desc: 'print without any extra formatting'
|
43
|
+
method_option :csv, type: :boolean, default: false,
|
44
|
+
desc: 'output in csv format per RFC4180'
|
45
|
+
def ls(*)
|
46
|
+
if options[:help]
|
47
|
+
invoke :help, ['ls']
|
48
|
+
else
|
49
|
+
require_relative 'alert/ls'
|
50
|
+
Gzr::Commands::Alert::Ls.new(options).execute
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'cat ALERT_ID', 'Output json information about an alert to screen or file'
|
55
|
+
method_option :help, aliases: '-h', type: :boolean,
|
56
|
+
desc: 'Display usage information'
|
57
|
+
method_option :dir, type: :string,
|
58
|
+
desc: 'Directory to store output file'
|
59
|
+
def cat(alert_id)
|
60
|
+
if options[:help]
|
61
|
+
invoke :help, ['cat']
|
62
|
+
else
|
63
|
+
require_relative 'alert/cat'
|
64
|
+
Gzr::Commands::Alert::Cat.new(alert_id,options).execute
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'follow ALERT_ID', 'Start following the alert given by ALERT_ID'
|
69
|
+
method_option :help, aliases: '-h', type: :boolean,
|
70
|
+
desc: 'Display usage information'
|
71
|
+
def follow_alert(alert_id)
|
72
|
+
if options[:help]
|
73
|
+
invoke :help, ['follow']
|
74
|
+
else
|
75
|
+
require_relative 'alert/follow'
|
76
|
+
Gzr::Commands::Alert::Follow.new(alert_id,options).execute
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'unfollow ALERT_ID', 'Stop following the alert given by ALERT_ID'
|
81
|
+
method_option :help, aliases: '-h', type: :boolean,
|
82
|
+
desc: 'Display usage information'
|
83
|
+
def unfollow_alert(alert_id)
|
84
|
+
if options[:help]
|
85
|
+
invoke :help, ['unfollow']
|
86
|
+
else
|
87
|
+
require_relative 'alert/unfollow'
|
88
|
+
Gzr::Commands::Alert::Unfollow.new(alert_id,options).execute
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'enable ALERT_ID', 'Enable the alert given by ALERT_ID'
|
93
|
+
method_option :help, aliases: '-h', type: :boolean,
|
94
|
+
desc: 'Display usage information'
|
95
|
+
def enable(alert_id)
|
96
|
+
if options[:help]
|
97
|
+
invoke :help, ['enable']
|
98
|
+
else
|
99
|
+
require_relative 'alert/enable'
|
100
|
+
Gzr::Commands::Alert::Enable.new(alert_id,options).execute
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'disable ALERT_ID REASON', 'Disable the alert given by ALERT_ID'
|
105
|
+
method_option :help, aliases: '-h', type: :boolean,
|
106
|
+
desc: 'Display usage information'
|
107
|
+
def disable(alert_id,reason)
|
108
|
+
if options[:help]
|
109
|
+
invoke :help, ['disable']
|
110
|
+
else
|
111
|
+
require_relative 'alert/disable'
|
112
|
+
Gzr::Commands::Alert::Disable.new(alert_id,reason,options).execute
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
desc 'threshold ALERT_ID THRESHOLD', 'Change the threshold of the alert given by ALERT_ID'
|
117
|
+
method_option :help, aliases: '-h', type: :boolean,
|
118
|
+
desc: 'Display usage information'
|
119
|
+
def threshold(alert_id,threshold)
|
120
|
+
if options[:help]
|
121
|
+
invoke :help, ['threshold']
|
122
|
+
else
|
123
|
+
require_relative 'alert/threshold'
|
124
|
+
Gzr::Commands::Alert::Threshold.new(alert_id,threshold,options).execute
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
desc 'rm ALERT_ID', 'Delete the alert given by ALERT_ID'
|
129
|
+
method_option :help, aliases: '-h', type: :boolean,
|
130
|
+
desc: 'Display usage information'
|
131
|
+
def rm(alert_id)
|
132
|
+
if options[:help]
|
133
|
+
invoke :help, ['delete']
|
134
|
+
else
|
135
|
+
require_relative 'alert/delete'
|
136
|
+
Gzr::Commands::Alert::Delete.new(alert_id,options).execute
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
desc 'chown ALERT_ID OWNER_ID', 'Change the owner of the alert given by ALERT_ID to OWNER_ID'
|
141
|
+
method_option :help, aliases: '-h', type: :boolean,
|
142
|
+
desc: 'Display usage information'
|
143
|
+
def chown(alert_id, owner_id)
|
144
|
+
if options[:help]
|
145
|
+
invoke :help, ['chown']
|
146
|
+
else
|
147
|
+
require_relative 'alert/chown'
|
148
|
+
Gzr::Commands::Alert::Chown.new(alert_id,owner_id,options).execute
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
desc 'notifications', 'Get notifications'
|
153
|
+
method_option :help, aliases: '-h', type: :boolean,
|
154
|
+
desc: 'Display usage information'
|
155
|
+
method_option :plain, type: :boolean, default: false,
|
156
|
+
desc: 'print without any extra formatting'
|
157
|
+
method_option :csv, type: :boolean, default: false,
|
158
|
+
desc: 'output in csv format per RFC4180'
|
159
|
+
def notifications(*)
|
160
|
+
if options[:help]
|
161
|
+
invoke :help, ['notifications']
|
162
|
+
else
|
163
|
+
require_relative 'alert/notifications'
|
164
|
+
Gzr::Commands::Alert::Notifications.new(options).execute
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
desc 'read NOTIFICATION_ID', 'Read notification id'
|
169
|
+
method_option :help, aliases: '-h', type: :boolean,
|
170
|
+
desc: 'Display usage information'
|
171
|
+
method_option :plain, type: :boolean, default: false,
|
172
|
+
desc: 'print without any extra formatting'
|
173
|
+
method_option :csv, type: :boolean, default: false,
|
174
|
+
desc: 'output in csv format per RFC4180'
|
175
|
+
def read(notification_id)
|
176
|
+
if options[:help]
|
177
|
+
invoke :help, ['read']
|
178
|
+
else
|
179
|
+
require_relative 'alert/read'
|
180
|
+
Gzr::Commands::Alert::Read.new(notification_id,options).execute
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
desc 'import FILE [DASHBOARD_ELEMENT_ID]', 'Import an alert from a file'
|
185
|
+
method_option :help, aliases: '-h', type: :boolean,
|
186
|
+
desc: 'Display usage information'
|
187
|
+
method_option :plain, type: :boolean,
|
188
|
+
desc: 'Provide minimal response information'
|
189
|
+
def import(file,dashboard_element_id=nil)
|
190
|
+
if options[:help]
|
191
|
+
invoke :help, ['import']
|
192
|
+
else
|
193
|
+
require_relative 'alert/import'
|
194
|
+
Gzr::Commands::Alert::Import.new(file, dashboard_element_id, options).execute
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -89,6 +89,17 @@ module Gzr
|
|
89
89
|
element[:result_maker] = result_maker if result_maker
|
90
90
|
dashboard_element = create_dashboard_element(element)
|
91
91
|
say_warning "dashboard_element #{dashboard_element.inspect}" if @options[:debug]
|
92
|
+
if new_element[:alerts]
|
93
|
+
new_element[:alerts].each do |a|
|
94
|
+
a.select! do |k,v|
|
95
|
+
(keys_to_keep('create_alert') - [:owner_id, :dashboard_element_id]).include? k
|
96
|
+
end
|
97
|
+
a[:dashboard_element_id] = dashboard_element[:id]
|
98
|
+
a[:owner_id] = @me[:id]
|
99
|
+
new_alert = create_alert(a)
|
100
|
+
say_warning "alert #{JSON.pretty_generate(new_alert)}" if @options[:debug]
|
101
|
+
end
|
102
|
+
end
|
92
103
|
dashboard[:dashboard_elements].push dashboard_element
|
93
104
|
[new_element[:id], dashboard_element.id]
|
94
105
|
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 Alert
|
26
|
+
def get_alert(alert_id)
|
27
|
+
data = nil
|
28
|
+
begin
|
29
|
+
data = @sdk.get_alert(alert_id)
|
30
|
+
rescue LookerSDK::NotFound => e
|
31
|
+
# do nothing
|
32
|
+
rescue LookerSDK::Error => e
|
33
|
+
say_error "Error querying get_alert(#{alert_id})"
|
34
|
+
say_error e
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
if data[:owner_id]
|
38
|
+
owner = get_user_by_id(data[:owner_id])
|
39
|
+
data[:owner] = owner.to_attrs.select do |k,v|
|
40
|
+
[:email,:last_name,:first_name].include?(k) && !(v.nil? || v.empty?)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
data
|
44
|
+
end
|
45
|
+
|
46
|
+
def search_alerts(group_by: nil, fields: nil, disabled: nil, frequency: nil, condition_met: nil, last_run_start: nil, last_run_end: nil, all_owners: nil)
|
47
|
+
data = []
|
48
|
+
begin
|
49
|
+
req = {}
|
50
|
+
req[:group_by] = group_by unless group_by.nil?
|
51
|
+
req[:fields] = fields unless fields.nil?
|
52
|
+
req[:disabled] = disabled unless disabled.nil?
|
53
|
+
req[:frequency] = frequency unless frequency.nil?
|
54
|
+
req[:condition_met] = condition_met unless condition_met.nil?
|
55
|
+
req[:last_run_start] = last_run_start unless last_run_start.nil?
|
56
|
+
req[:last_run_end] = last_run_end unless last_run_end.nil?
|
57
|
+
req[:all_owners] = all_owners unless all_owners.nil?
|
58
|
+
req[:limit] = 64
|
59
|
+
loop do
|
60
|
+
page = @sdk.search_alerts(req)
|
61
|
+
data+=page
|
62
|
+
break unless page.length == req[:limit]
|
63
|
+
req[:offset] = (req[:offset] || 0) + req[:limit]
|
64
|
+
end
|
65
|
+
rescue LookerSDK::NotFound => e
|
66
|
+
# do nothing
|
67
|
+
rescue LookerSDK::Error => e
|
68
|
+
say_error "Error querying search_alerts(#{JSON.pretty_generate(req)})"
|
69
|
+
say_error e
|
70
|
+
raise
|
71
|
+
end
|
72
|
+
data
|
73
|
+
end
|
74
|
+
|
75
|
+
def follow_alert(alert_id)
|
76
|
+
begin
|
77
|
+
@sdk.follow_alert(alert_id)
|
78
|
+
rescue LookerSDK::Error => e
|
79
|
+
say_error "Error following alert(#{alert_id})"
|
80
|
+
say_error e
|
81
|
+
raise
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def unfollow_alert(alert_id)
|
86
|
+
begin
|
87
|
+
@sdk.unfollow_alert(alert_id)
|
88
|
+
rescue LookerSDK::Error => e
|
89
|
+
say_error "Error following alert(#{alert_id})"
|
90
|
+
say_error e
|
91
|
+
raise
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def update_alert_field(alert_id, owner_id: nil, is_disabled: nil, disabled_reason: nil, is_public: nil, threshold: nil)
|
96
|
+
req = {}
|
97
|
+
req[:owner_id] = owner_id unless owner_id.nil?
|
98
|
+
req[:is_disabled] = is_disabled unless is_disabled.nil?
|
99
|
+
req[:disabled_reason] = disabled_reason unless disabled_reason.nil?
|
100
|
+
req[:is_public] = is_public unless is_public.nil?
|
101
|
+
req[:threshold] = threshold unless threshold.nil?
|
102
|
+
data = nil
|
103
|
+
begin
|
104
|
+
data = @sdk.update_alert_field(alert_id, req)
|
105
|
+
rescue LookerSDK::Error => e
|
106
|
+
say_error "Error calling update_alert_field(#{alert_id},#{JSON.pretty_generate(req)})"
|
107
|
+
say_error e
|
108
|
+
raise
|
109
|
+
end
|
110
|
+
data
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete_alert(alert_id)
|
114
|
+
begin
|
115
|
+
@sdk.delete_alert(alert_id)
|
116
|
+
rescue LookerSDK::Error => e
|
117
|
+
say_error "Error calling delete_alert(#{alert_id})"
|
118
|
+
say_error e
|
119
|
+
raise
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def alert_notifications()
|
124
|
+
data = []
|
125
|
+
req = {}
|
126
|
+
begin
|
127
|
+
req[:limit] = 64
|
128
|
+
loop do
|
129
|
+
page = @sdk.alert_notifications(req)
|
130
|
+
data+=page
|
131
|
+
break unless page.length == req[:limit]
|
132
|
+
req[:offset] = (req[:offset] || 0) + req[:limit]
|
133
|
+
end
|
134
|
+
rescue LookerSDK::NotFound => e
|
135
|
+
# do nothing
|
136
|
+
rescue LookerSDK::Error => e
|
137
|
+
say_error "Error querying alert_notifications()"
|
138
|
+
say_error e
|
139
|
+
raise
|
140
|
+
end
|
141
|
+
data
|
142
|
+
end
|
143
|
+
|
144
|
+
def read_alert_notification(notification_id)
|
145
|
+
data = nil
|
146
|
+
begin
|
147
|
+
data = @sdk.read_alert_notification(notification_id)
|
148
|
+
rescue LookerSDK::Error => e
|
149
|
+
say_error "Error calling read_alert_notification(#{notification_id})"
|
150
|
+
say_error e
|
151
|
+
raise
|
152
|
+
end
|
153
|
+
data.to_attrs
|
154
|
+
end
|
155
|
+
|
156
|
+
def create_alert(req)
|
157
|
+
data = nil
|
158
|
+
begin
|
159
|
+
data = @sdk.create_alert(req)
|
160
|
+
rescue LookerSDK::Error => e
|
161
|
+
say_error "Error calling create_alert(#{JSON.pretty_generate(req)})"
|
162
|
+
say_error e
|
163
|
+
raise
|
164
|
+
end
|
165
|
+
data.to_attrs
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -20,9 +20,12 @@
|
|
20
20
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
# frozen_string_literal: true
|
23
|
+
require_relative 'alert'
|
23
24
|
|
24
25
|
module Gzr
|
25
26
|
module Dashboard
|
27
|
+
include Gzr::Alert
|
28
|
+
|
26
29
|
def query_dashboard(dashboard_id)
|
27
30
|
data = nil
|
28
31
|
begin
|
@@ -249,6 +252,17 @@ module Gzr
|
|
249
252
|
rewrite_color_palette!(o,default_colors)
|
250
253
|
end
|
251
254
|
end
|
255
|
+
alerts = search_alerts(fields: 'id,dashboard_element_id', group_by: 'dashboard', all_owners: true)
|
256
|
+
alerts.map!{|v| v.to_attrs}
|
257
|
+
say_warning alerts if @options[:debug]
|
258
|
+
data[:dashboard_elements].each do |e|
|
259
|
+
alerts_found = alerts.select { |a| a[:dashboard_element_id] == e[:id]}
|
260
|
+
say_warning "Found alerts #{alerts_found}" if @options[:debug]
|
261
|
+
alerts_entries = alerts_found.map { |a| get_alert(a[:id]).to_attrs }
|
262
|
+
say_warning "Looked up alerts entries #{alerts_entries}" if @options[:debug]
|
263
|
+
e[:alerts] = alerts_entries
|
264
|
+
end
|
265
|
+
|
252
266
|
merge_result = merge_query(element[:merge_result_id])&.to_attrs if element[:merge_result_id]
|
253
267
|
if merge_result
|
254
268
|
merge_result[:source_queries].each_index do |j|
|
@@ -274,7 +288,7 @@ module Gzr
|
|
274
288
|
|
275
289
|
trimmed[:dashboard_elements] = data[:dashboard_elements].map do |de|
|
276
290
|
new_de = de.select do |k,v|
|
277
|
-
(keys_to_keep('update_dashboard_element') + [:id,:look,:query,:merge_result]).include? k
|
291
|
+
(keys_to_keep('update_dashboard_element') + [:id,:look,:query,:merge_result,:alerts]).include? k
|
278
292
|
end
|
279
293
|
if de[:look]
|
280
294
|
new_de[:look] = de[:look].select do |k,v|
|
@@ -301,6 +315,13 @@ module Gzr
|
|
301
315
|
end
|
302
316
|
end
|
303
317
|
end
|
318
|
+
if de[:alerts]
|
319
|
+
new_de[:alerts] = de[:alerts].map do |a|
|
320
|
+
a.select do |k,v|
|
321
|
+
(keys_to_keep('update_alert') + [:id,:owner]).include? k
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
304
325
|
new_de
|
305
326
|
end
|
306
327
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike DeAngelo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-reader
|
@@ -269,6 +269,19 @@ files:
|
|
269
269
|
- lib/gzr/cli.rb
|
270
270
|
- lib/gzr/command.rb
|
271
271
|
- lib/gzr/commands/.gitkeep
|
272
|
+
- lib/gzr/commands/alert.rb
|
273
|
+
- lib/gzr/commands/alert/cat.rb
|
274
|
+
- lib/gzr/commands/alert/chown.rb
|
275
|
+
- lib/gzr/commands/alert/delete.rb
|
276
|
+
- lib/gzr/commands/alert/disable.rb
|
277
|
+
- lib/gzr/commands/alert/enable.rb
|
278
|
+
- lib/gzr/commands/alert/follow.rb
|
279
|
+
- lib/gzr/commands/alert/import.rb
|
280
|
+
- lib/gzr/commands/alert/ls.rb
|
281
|
+
- lib/gzr/commands/alert/notifications.rb
|
282
|
+
- lib/gzr/commands/alert/read.rb
|
283
|
+
- lib/gzr/commands/alert/threshold.rb
|
284
|
+
- lib/gzr/commands/alert/unfollow.rb
|
272
285
|
- lib/gzr/commands/attribute.rb
|
273
286
|
- lib/gzr/commands/attribute/cat.rb
|
274
287
|
- lib/gzr/commands/attribute/create.rb
|
@@ -335,6 +348,7 @@ files:
|
|
335
348
|
- lib/gzr/commands/user/enable.rb
|
336
349
|
- lib/gzr/commands/user/ls.rb
|
337
350
|
- lib/gzr/commands/user/me.rb
|
351
|
+
- lib/gzr/modules/alert.rb
|
338
352
|
- lib/gzr/modules/attribute.rb
|
339
353
|
- lib/gzr/modules/connection.rb
|
340
354
|
- lib/gzr/modules/dashboard.rb
|