greenhat 0.3.6 → 0.4.0

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: d9cc86956963d9d4d6a11b8d84b3a047d66bbbd3ac1c0cbb45f7e9f91d0a55e2
4
- data.tar.gz: c4df69de408709de93713f4e2a98ce6263f15b83c28bc3c353589368bb325efd
3
+ metadata.gz: 4205de8b256423c08291a212511d4d6ecd613d21f232d0d6b4641881779f1303
4
+ data.tar.gz: 695ce3fb852d8a3167b853b3b8c07448f031305e51072f34e7afb3aed75ca50e
5
5
  SHA512:
6
- metadata.gz: 813350d41deb97b978afc55d3aad33e3bf1b383a721ab3a33b8ed56cfdd4b2158ba5c6e7368839d3f7ac74e53614c644e2f92a3a6ccc64608d1b89c5274396a1
7
- data.tar.gz: 78074ff71327905079cbd603d640d09625d4e49bf1dc9e8a7e7823b8ba923d1abb0c69c833a0a956aa6d0e1af92e53bbae97015827d83219d8c384abf8a349b0
6
+ metadata.gz: 6d4653882946a783ddc0e11094205e42b33338afe53334cc9774956047a1b00eb54bca964925efbed47ca4c410e5007d6e5ac79f10376274b50beb1ffaedc8f0
7
+ data.tar.gz: c2002b0458b334799e4b04a446a9ca0193091f264e7077b9eac84c310423e6c0547d79094da45fa5fa9ce475d110756952602d3274b34f97b4162e7ee4226871
data/bin/greenhat CHANGED
@@ -2,11 +2,8 @@
2
2
 
3
3
  require 'greenhat'
4
4
 
5
- # DEV ONLY
6
- require 'pry'
7
-
8
5
  Dir.mktmpdir('greenhat-sauce') do |tmp|
9
6
  $TMP = tmp
10
7
  $STDOUT_CLONE = $stdout.clone
11
- GreenHat::Cli.start ARGV
8
+ GreenHat::Entrypoint.start ARGV
12
9
  end
@@ -7,7 +7,7 @@ module GreenHat
7
7
  Dir.mkdir path
8
8
 
9
9
  # Initially Copy file into tmpdir
10
- FileUtils.cp(archive_path, "#{path}/")
10
+ FileUtils.cp_r(archive_path.to_s, "#{path}/")
11
11
 
12
12
  # Extract Everything
13
13
  loop do
@@ -28,9 +28,6 @@ module GreenHat
28
28
 
29
29
  archive = Archive.new(name: archive_path, path: path)
30
30
  archive.save
31
- # file = list[2]
32
- # thing = archive.things_create(file: file)
33
- # thing.setup
34
31
 
35
32
  list.each do |file|
36
33
  # Ensure Valid Content
@@ -54,8 +51,13 @@ module GreenHat
54
51
  # Handle Different Types of Archives
55
52
  def self.unpack(archive_path, path)
56
53
  case File.extname archive_path
54
+ when '.tgz'
55
+ base_path = archive_path.gsub(File.basename(archive_path), '')
56
+ `bsdtar -xzf "#{archive_path}" -C #{base_path}`
57
+ FileUtils.rm(archive_path)
57
58
  when '.tar'
58
- `bsdtar -xf "#{archive_path}" -C #{path}`
59
+ base_path = archive_path.gsub(File.basename(archive_path), '')
60
+ `bsdtar -xf "#{archive_path}" -C #{base_path}`
59
61
  FileUtils.rm(archive_path)
60
62
  when '.gz'
61
63
  `gzip -d "#{archive_path}"`
@@ -75,7 +77,7 @@ module GreenHat
75
77
  end
76
78
 
77
79
  def self.archive_types
78
- %w[s gz tar]
80
+ %w[s gz tar tgz]
79
81
  end
80
82
  # -- Archive Loader ----------------------------------------------
81
83
  end
data/lib/greenhat/cli.rb CHANGED
@@ -1,8 +1,31 @@
1
1
  # Top level namespace
2
2
  module GreenHat
3
- # CLI Methods
3
+ # CLI Methods / Shell Specific COmmands
4
4
  # rubocop:disable Metrics/ModuleLength
5
5
  module Cli
6
+ # CLI Start
7
+ def self.start
8
+ value ||= '' # Empty Start
9
+
10
+ loop do
11
+ line = reader.read_line(readline_notch, value: value)
12
+ value = '' # Remove Afterwards
13
+
14
+ if reader.breaker
15
+ value = line
16
+ puts ''
17
+ next
18
+ end
19
+
20
+ break if line =~ /^exit/i
21
+
22
+ Settings.cmd_add(line) unless line.blank?
23
+
24
+ process
25
+ run
26
+ end
27
+ end
28
+
6
29
  def self.cursor
7
30
  @cursor = TTY::Cursor
8
31
  end
@@ -348,154 +371,6 @@ module GreenHat
348
371
  @quiet = !@quiet
349
372
  end
350
373
 
351
- # rubocop:disable Metrics/MethodLength
352
- def self.cli_help
353
- Shell.version
354
- puts
355
- puts 'Usage'.pastel(:yellow)
356
- puts ' greenhat <sos-archive.tgz> <sos-archive2.tgz> '
357
- puts ' greenhat <sos-archive.tgz> -q --command=df'
358
- puts
359
-
360
- puts 'Options'.pastel(:yellow)
361
- puts ' --report, -r'.pastel(:green)
362
- puts ' Run `report` against archives and exit'
363
- puts
364
-
365
- puts ' --full-report, -f'.pastel(:green)
366
- puts ' Run `report` with all details. e.g. include fast-stats top/errors'
367
- puts
368
-
369
- puts ' --markdown, -m'.pastel(:green)
370
- puts ' Run `markdown_report` against archives and exit'
371
- puts
372
-
373
- puts ' --quiet, -r'.pastel(:green)
374
- puts ' Surpress GreenHat logging output'
375
- puts
376
-
377
- puts ' --load, -l'.pastel(:green)
378
- puts ' Automatically attempt to read/parse/preload all included files'
379
- puts
380
-
381
- puts ' --command, -c'.pastel(:green)
382
- puts ' Run and then exit a GreenHat Shell command'
383
- puts
384
-
385
- puts ' --web, -w'.pastel(:green)
386
- puts ' Start Sinatra Webservice on load (4567)'
387
- puts
388
-
389
- puts ' --no-color, -n'.pastel(:green)
390
- puts ' Disable color output'
391
- puts
392
-
393
- puts ' --version, -v'.pastel(:green)
394
- puts ' Print version and exit'
395
- puts
396
- end
397
- # rubocop:enable Metrics/MethodLength
398
-
399
- # Arguments before general processing
400
- def self.pre_args(flags, files)
401
- # Help
402
- if flags?(%i[help h], flags)
403
- cli_help
404
- exit 0
405
- end
406
-
407
- # Version
408
- if flags?(%i[version v], flags)
409
- Shell.version
410
- exit 0
411
- end
412
-
413
- # Quiet Flag
414
- @quiet = true if flags?(%i[quiet q], flags)
415
-
416
- # rubocop:disable Style/GuardClause
417
- # MIA Files
418
- if files.empty? || files.count { |x| File.exist? x }.zero?
419
- puts "No arguments or files don't exist".pastel(:red)
420
- puts 'Usage: greenhat <sos-archive.tgz> <sos-archive2.tgz>'
421
- cli_help
422
- Shell.version
423
- end
424
- # rubocop:enable Style/GuardClause
425
- end
426
-
427
- # Arguments to be handled after general processing
428
- def self.post_args(flags)
429
- # Supress Color
430
- GreenHat::Settings.settings[:color] = false if flags?(%i[no-color n], flags)
431
-
432
- # Run report and exit / Don't Clear for reports
433
- if flags?(%i[report r], flags)
434
- @quiet = true
435
- # Don't Use Pagination
436
- GreenHat::Shell.report(['--raw'])
437
- exit 0
438
- elsif flags?(%i[full-report f], flags)
439
- @quiet = true
440
- # Don't Use Pagination
441
- GreenHat::Shell.report(['--raw', '--full'])
442
- exit 0
443
- elsif flags?(%i[markdown m], flags)
444
- @quiet = true
445
- # Don't Use Pagination
446
- GreenHat::Shell.markdown_report(['--raw'])
447
- exit 0
448
- else
449
- clear_screen
450
- end
451
- end
452
-
453
- def self.post_setup(flags)
454
- # CTL Tails need to be parsed for new 'things'
455
- Thing.where(kind: :gitlab_tail)&.map(&:process)
456
- Thing.where(kind: :kube_webservice)&.map(&:process)
457
-
458
- Thing.all.each(&:process) if flags?(%i[load l], flags)
459
-
460
- Shell.web if flags?(%i[web w], flags)
461
- end
462
-
463
- # Helper to Simplify checking flags
464
- def self.flags?(list = [], flags = {})
465
- list.any? { |x| flags.key? x }
466
- end
467
-
468
- # If no arguments Supplied Print and quit - rather than nasty exception
469
- def self.start(raw)
470
- Settings.start
471
- files, flags, args = Args.parse(raw)
472
- pre_args(flags, files)
473
- load_files files
474
- run_command(args) if args.any? { |arg| run_command?(arg) }
475
- post_args(flags)
476
- post_setup(flags)
477
-
478
- value ||= '' # Empty Start
479
-
480
- loop do
481
- line = reader.read_line(readline_notch, value: value)
482
- value = '' # Remove Afterwards
483
-
484
- if reader.breaker
485
- value = line
486
- puts ''
487
- next
488
- end
489
-
490
- break if line =~ /^exit/i
491
-
492
- Settings.cmd_add(line) unless line.blank?
493
-
494
- process
495
- run
496
- end
497
- end
498
-
499
374
  def self.run_command?(arg)
500
375
  %i[command c].any? do |x|
501
376
  arg[:field] == x
@@ -515,20 +390,6 @@ module GreenHat
515
390
  exit 0
516
391
  end
517
392
 
518
- def self.load_files(files)
519
- # TODO: Web Helpers?
520
- # suppress_output { GreenHat::Web.start }
521
-
522
- # Don't double up on archives / Only Existing files
523
- puts 'Loading Archives'.pastel(:blue) unless Cli.quiet
524
- files.uniq.each do |file|
525
- next unless File.exist?(file)
526
-
527
- puts "- #{file}".pastel(:magenta) unless Cli.quiet
528
- ArchiveLoader.load file
529
- end
530
- end
531
-
532
393
  def self.suppress_output
533
394
  original_stderr = $stderr.clone
534
395
  original_stdout = $stdout.clone
@@ -0,0 +1,170 @@
1
+ # Top level namespace
2
+ module GreenHat
3
+ # Entrypoint Methods
4
+ # Command Line Args / File Parsing etc
5
+ module Entrypoint
6
+ # If no arguments Supplied Print and quit - rather than nasty exception
7
+ def self.start(raw)
8
+ @clear = true # Reset screen by default
9
+ Settings.start
10
+ files, flags, args = Args.parse(raw)
11
+ pre_args(flags, files)
12
+ load_files files
13
+ Cli.run_command(args) if args.any? { |arg| Cli.run_command?(arg) }
14
+ post_args(flags)
15
+ post_setup(flags)
16
+
17
+ Cli.start # Kick over to CLI
18
+ end
19
+
20
+ # Arguments before general processing
21
+ def self.pre_args(flags, files)
22
+ # Help
23
+ if flags?(%i[help h], flags)
24
+ cli_help
25
+ exit 0
26
+ end
27
+
28
+ # Version
29
+ if flags?(%i[version v], flags)
30
+ Shell.version
31
+ exit 0
32
+ end
33
+
34
+ # Assume Raw Setting
35
+ Settings.settings[:assume_raw] = true if flags?(%i[no-prompt np], flags)
36
+ Settings.settings[:assume_raw] = false if flags?(%i[prompt p], flags)
37
+
38
+ # Quiet Flag
39
+ @quiet = true if flags?(%i[quiet q], flags)
40
+
41
+ if flags?(%i[load-local ll], flags)
42
+ # Hook in loading local
43
+ Shell.load_local(false)
44
+ elsif files.empty? || files.count { |x| File.exist? x }.zero?
45
+ # MIA Files
46
+ puts "No arguments or files don't exist".pastel(:red)
47
+ puts 'Usage: greenhat <sos-archive.tgz> <sos-archive2.tgz>'
48
+ puts 'See `--help`'
49
+
50
+ @clear = false # Don't hide messages
51
+
52
+ Shell.version
53
+ end
54
+ end
55
+
56
+ # Arguments to be handled after general processing
57
+ def self.post_args(flags)
58
+ # Supress Color
59
+ GreenHat::Settings.settings[:color] = false if flags?(%i[no-color n], flags)
60
+
61
+ # Run report and exit / Don't Clear for reports
62
+ if flags?(%i[report r], flags)
63
+ @quiet = true
64
+ # Don't Use Pagination
65
+ GreenHat::Shell.report(['--raw'])
66
+ exit 0
67
+ elsif flags?(%i[full-report f], flags)
68
+ @quiet = true
69
+ # Don't Use Pagination
70
+ GreenHat::Shell.report(['--raw', '--full'])
71
+ exit 0
72
+ elsif flags?(%i[markdown m], flags)
73
+ @quiet = true
74
+ # Don't Use Pagination
75
+ GreenHat::Shell.markdown_report(['--raw'])
76
+ exit 0
77
+ elsif @clear
78
+ Cli.clear_screen
79
+ end
80
+ end
81
+
82
+ def self.post_setup(flags)
83
+ # CTL Tails need to be parsed for new 'things'
84
+ Thing.where(kind: :gitlab_tail)&.map(&:process)
85
+ Thing.where(kind: :kube_webservice)&.map(&:process)
86
+
87
+ Thing.all.each(&:process) if flags?(%i[load l], flags)
88
+
89
+ Shell.web if flags?(%i[web w], flags)
90
+ end
91
+
92
+ # Helper to Simplify checking flags
93
+ def self.flags?(list = [], flags = {})
94
+ list.any? { |x| flags.key? x }
95
+ end
96
+
97
+ def self.load_files(files)
98
+ # Don't double up on archives / Only Existing files
99
+ puts 'Loading Archives'.pastel(:blue) unless Cli.quiet
100
+ files.uniq.each do |file|
101
+ next unless File.exist?(file)
102
+
103
+ puts "- #{file}".pastel(:magenta) unless Cli.quiet
104
+ ArchiveLoader.load file
105
+ end
106
+ end
107
+
108
+ # rubocop:disable Metrics/MethodLength
109
+ def self.cli_help
110
+ Shell.version
111
+ puts
112
+ puts 'Usage'.pastel(:yellow)
113
+ puts ' greenhat <sos-archive.tgz> <sos-archive2.tgz> '
114
+ puts ' greenhat <sos-archive.tgz> -q --command=df'
115
+ puts
116
+
117
+ puts 'Options'.pastel(:yellow)
118
+ puts ' --report, -r'.pastel(:green)
119
+ puts ' Run `report` against archives and exit'
120
+ puts
121
+
122
+ puts ' --full-report, -f'.pastel(:green)
123
+ puts ' Run `report` with all details. e.g. include fast-stats top/errors'
124
+ puts
125
+
126
+ puts ' --markdown, -m'.pastel(:green)
127
+ puts ' Run `markdown_report` against archives and exit'
128
+ puts
129
+
130
+ puts ' --quiet, -r'.pastel(:green)
131
+ puts ' Surpress GreenHat logging output'
132
+ puts
133
+
134
+ puts ' --load, -l'.pastel(:green)
135
+ puts ' Automatically attempt to read/parse/preload all included files'
136
+ puts
137
+
138
+ puts ' --load-local, -ll'.pastel(:green)
139
+ puts ' Load log files from locations on an Omnibus install'
140
+ puts
141
+
142
+ puts ' --prompt, -p'.pastel(:green)
143
+ puts ' Override settings / Assume Prompt'
144
+ puts
145
+
146
+ puts ' --no-prompt, -np'.pastel(:green)
147
+ puts ' Do not prompt for file types / Assume Raw or JSON'
148
+ puts
149
+
150
+ puts ' --command, -c'.pastel(:green)
151
+ puts ' Run and then exit a GreenHat Shell command'
152
+ puts
153
+
154
+ puts ' --web, -w'.pastel(:green)
155
+ puts ' Start Sinatra Webservice on load (4567)'
156
+ puts
157
+
158
+ puts ' --no-color, -n'.pastel(:green)
159
+ puts ' Disable color output'
160
+ puts
161
+
162
+ puts ' --version, -v'.pastel(:green)
163
+ puts ' Print version and exit'
164
+ puts
165
+ end
166
+ # rubocop:enable Metrics/MethodLength
167
+
168
+ # ==========================================================
169
+ end
170
+ end
@@ -6,12 +6,14 @@ module GreenHat
6
6
  @settings ||= {
7
7
  history: [],
8
8
  assume_json: true,
9
+ assume_raw: false,
9
10
  fuzzy_file_match: true,
10
11
 
11
12
  # round: [2],
12
13
  # page: [:true] Automatic,
13
14
  truncate: TTY::Screen.width * 4,
14
15
  color: true
16
+
15
17
  }
16
18
  end
17
19
 
@@ -19,6 +21,10 @@ module GreenHat
19
21
  settings.assume_json
20
22
  end
21
23
 
24
+ def self.assume_raw?
25
+ settings.assume_raw
26
+ end
27
+
22
28
  # Allow for future disabling of color output
23
29
  def self.color?
24
30
  settings.color
@@ -55,12 +55,14 @@ module GreenHat
55
55
  # Default Pager
56
56
  TTY::Pager.page do |pager|
57
57
  data.each do |entry|
58
- output = entry_show(flags, entry)
58
+ output = "\n#{entry_show(flags, entry)}"
59
+
60
+ # output += "\n" if flags[:table_style] == 'basic'
59
61
 
60
62
  # Breaks any intentional spaces
61
63
  # next if output.blank?
62
64
 
63
- pager.write("\n#{output}") # write line to the pager
65
+ pager.write(output) # write line to the pager
64
66
  end
65
67
  end
66
68
  end
@@ -126,10 +128,15 @@ module GreenHat
126
128
  table = TTY::Table.new(header: entry.keys, rows: [entry], orientation: :vertical)
127
129
 
128
130
  LogBot.debug('Rendering Entries') if ENV['DEBUG']
129
- table.render(table_style, padding: [0, 1, 0, 1], multiline: true) do |renderer|
131
+ output = table.render(table_style, padding: [0, 1, 0, 1], multiline: true) do |renderer|
130
132
  renderer.border.style = :cyan
131
133
  end
132
134
 
135
+ # Line breaks for basic tables
136
+ output += "\n" if flags[:table_style] == 'basic'
137
+
138
+ output
139
+
133
140
  # LogBot.debug('Finish Render Table') if ENV['DEBUG']
134
141
  # Fall Back to Amazing Inspect
135
142
  rescue StandardError => e
@@ -201,7 +208,8 @@ module GreenHat
201
208
  end
202
209
 
203
210
  def self.calculate_duration(results)
204
- only_with_time = results.select(&:time)
211
+ # Skip for Pluck
212
+ only_with_time = results.select { |x| x.instance_of?(Hash) && x.key?(:time) }
205
213
 
206
214
  # If slice is used ignore
207
215
  return nil if only_with_time.empty?
@@ -30,12 +30,12 @@ module GreenHat
30
30
  Memory.free
31
31
  end
32
32
 
33
- def self.load_local
34
- return false unless TTY::Prompt.new.yes?('Load local Omnibus GitLab Instance files?')
33
+ def self.load_local(prompt = true)
34
+ return false if prompt && !TTY::Prompt.new.yes?('Load local Omnibus GitLab Instance files?')
35
35
 
36
36
  archive_path = "#{$TMP}/#{Time.now.to_i}_local"
37
37
  Dir.mkdir(archive_path)
38
- # archive = Archive.new(name: 'local')
38
+
39
39
  archive = Archive.new(name: archive_path, path: archive_path)
40
40
 
41
41
  file_list = Dir['/var/log/gitlab/*/current'] + Dir['/var/log/gitlab/*/*.log']
@@ -67,7 +67,8 @@ module GreenHat
67
67
  'etc/fstab' => {
68
68
  format: :clean_raw,
69
69
  pattern: [
70
- %r{etc/fstab}
70
+ %r{etc/fstab},
71
+ /fstab/
71
72
  ]
72
73
  },
73
74
  'etc/os-release' => {
@@ -108,6 +109,13 @@ module GreenHat
108
109
  %r{gitaly/@.*}
109
110
  ]
110
111
  },
112
+ 'gitaly/gitaly_hooks.log' => {
113
+ format: :shellwords,
114
+ log: true,
115
+ pattern: [
116
+ %r{gitaly/gitaly_hooks\.log}
117
+ ]
118
+ },
111
119
  'consul/current' => {
112
120
  format: :time_space,
113
121
  log: true,
@@ -803,6 +811,7 @@ module GreenHat
803
811
  'gitlab-rails/production.log' => {
804
812
  format: :raw,
805
813
  pattern: [
814
+ /production.log/,
806
815
  %r{gitlab-rails/production.log},
807
816
  %r{webservice.log/production.log}
808
817
  ]
@@ -73,6 +73,11 @@ module GreenHat
73
73
  end
74
74
  end
75
75
 
76
+ if Settings.assume_raw?
77
+ self.type = 'raw'
78
+ return true
79
+ end
80
+
76
81
  puts "Unable to determine file type for #{name.pastel(:yellow)}"
77
82
  puts "Use '#{'json'.pastel(:cyan)}' or '#{'raw'.pastel(:cyan)}' if there are no matches (see file_types.rb)"
78
83
 
@@ -147,6 +147,7 @@ class Thing < Teron
147
147
  self.name = name
148
148
  self.log = true
149
149
  self.parsed = true
150
+ self.type = 'json'
150
151
  self.result_fields = field_processing
151
152
  save!
152
153
  end
@@ -1,3 +1,3 @@
1
1
  module GreenHat
2
- VERSION = '0.3.6'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
data/lib/greenhat.rb CHANGED
@@ -46,6 +46,7 @@ Hash.hash_dot_use_default = true
46
46
 
47
47
  # Load Required Files
48
48
  require 'greenhat/version'
49
+ require 'greenhat/entrypoint'
49
50
  require 'greenhat/cli'
50
51
  require 'greenhat/archive'
51
52
  require 'greenhat/host'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greenhat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-15 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -451,6 +451,7 @@ files:
451
451
  - lib/greenhat/archive.rb
452
452
  - lib/greenhat/cli.rb
453
453
  - lib/greenhat/color.rb
454
+ - lib/greenhat/entrypoint.rb
454
455
  - lib/greenhat/host.rb
455
456
  - lib/greenhat/logbot.rb
456
457
  - lib/greenhat/pry_helpers.rb
@@ -549,7 +550,8 @@ files:
549
550
  homepage: https://gitlab.com/gitlab-com/support/toolbox/greenhat
550
551
  licenses:
551
552
  - MIT
552
- metadata: {}
553
+ metadata:
554
+ rubygems_mfa_required: 'true'
553
555
  post_install_message:
554
556
  rdoc_options: []
555
557
  require_paths:
@@ -558,14 +560,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
558
560
  requirements:
559
561
  - - ">="
560
562
  - !ruby/object:Gem::Version
561
- version: 2.6.0
563
+ version: 3.0.0
562
564
  required_rubygems_version: !ruby/object:Gem::Requirement
563
565
  requirements:
564
566
  - - ">="
565
567
  - !ruby/object:Gem::Version
566
568
  version: '0'
567
569
  requirements: []
568
- rubygems_version: 3.0.3
570
+ rubygems_version: 3.2.32
569
571
  signing_key:
570
572
  specification_version: 4
571
573
  summary: GitLab SOS Tool