gazer 0.3.0 → 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 +14 -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 +2 -1
- data/lib/gzr/commands/dashboard/import.rb +12 -1
- data/lib/gzr/commands/dashboard.rb +3 -1
- data/lib/gzr/commands/folder/export.rb +2 -0
- data/lib/gzr/commands/folder.rb +2 -0
- data/lib/gzr/commands/look/cat.rb +1 -0
- data/lib/gzr/commands/look.rb +2 -0
- data/lib/gzr/modules/alert.rb +169 -0
- data/lib/gzr/modules/dashboard.rb +89 -1
- data/lib/gzr/modules/look.rb +18 -1
- 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,19 @@
|
|
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
|
+
|
10
|
+
## [0.3.1](https://github.com/looker-open-source/gzr/compare/v0.3.0...v0.3.1) (2023-04-20)
|
11
|
+
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* Add --trim option for dashboard cat, look cat, and folder export commands ([#178](https://github.com/looker-open-source/gzr/issues/178)) ([3173796](https://github.com/looker-open-source/gzr/commit/317379600803cfb92d223980930c0831fe8c247d))
|
16
|
+
|
3
17
|
## [0.3.0](https://github.com/looker-open-source/gzr/compare/v0.2.60...v0.3.0) (2023-04-13)
|
4
18
|
|
5
19
|
|
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
|