greenhat 0.3.0 → 0.3.4

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.
@@ -43,6 +43,13 @@ module GreenHat
43
43
  /dmesg/
44
44
  ]
45
45
  },
46
+ 'lets-encrypt/renewal' => {
47
+ format: :bracket_log,
48
+ log: true,
49
+ pattern: [
50
+ %r{lets-encrypt/renewal}
51
+ ]
52
+ },
46
53
  'repmgrd/current' => {
47
54
  format: :bracket_log,
48
55
  log: true,
@@ -225,7 +232,8 @@ module GreenHat
225
232
  format: :json,
226
233
  log: true,
227
234
  pattern: [
228
- %r{gitlab-rails/audit_json.log}
235
+ %r{gitlab-rails/audit_json.log},
236
+ %r{webservice.log/audit_json.log}
229
237
  ]
230
238
  },
231
239
  'gitlab-rails/auth.log' => {
@@ -336,15 +344,22 @@ module GreenHat
336
344
  %r{nginx/current}
337
345
  ]
338
346
  },
347
+ 'nginx-ingress.log' => {
348
+ format: :kube_nginx,
349
+ log: true,
350
+ pattern: [
351
+ /nginx-ingress.log/
352
+ ]
353
+ },
339
354
  'nginx/gitlab_pages_access.log' => {
340
- format: :raw,
355
+ format: :nginx,
341
356
  log: true,
342
357
  pattern: [
343
358
  %r{nginx/gitlab_pages_access.log}
344
359
  ]
345
360
  },
346
361
  'nginx/gitlab_access.log' => {
347
- format: :raw,
362
+ format: :nginx,
348
363
  log: true,
349
364
  pattern: [
350
365
  %r{nginx/gitlab_access.log}
@@ -422,7 +437,7 @@ module GreenHat
422
437
  ]
423
438
  },
424
439
  'registry/current' => {
425
- format: :time_shellwords,
440
+ format: :time_registry,
426
441
  log: true,
427
442
  pattern: [
428
443
  %r{registry/current},
@@ -444,16 +459,18 @@ module GreenHat
444
459
  },
445
460
  'puma/puma_stderr.log' => {
446
461
  format: :raw,
447
- log: true,
462
+ log: false,
448
463
  pattern: [
449
- %r{puma/puma_stderr.log}
464
+ %r{puma/puma_stderr.log},
465
+ %r{webservice.log/puma.stderr.log}
450
466
  ]
451
467
  },
452
468
  'puma/puma_stdout.log' => {
453
469
  format: :json,
454
470
  log: true,
455
471
  pattern: [
456
- %r{puma/puma_stdout.log}
472
+ %r{puma/puma_stdout.log},
473
+ %r{webservice.log/puma.stdout.log}
457
474
  ]
458
475
  },
459
476
  'gitlab-pages/current' => {
@@ -489,7 +506,8 @@ module GreenHat
489
506
  %r{pgbouncer-exporter/config},
490
507
  %r{repmgrd/config},
491
508
  %r{sentinel/config},
492
- %r{consul/config}
509
+ %r{consul/config},
510
+ %r{mailroom/current}
493
511
  ]
494
512
  },
495
513
  'redis/current' => {
@@ -500,7 +518,6 @@ module GreenHat
500
518
  %r{redis/@.*}
501
519
  ]
502
520
  },
503
-
504
521
  'nginx/gitlab_error.log' => {
505
522
  format: :time_space,
506
523
  log: true,
@@ -508,6 +525,13 @@ module GreenHat
508
525
  %r{nginx/gitlab_error.log}
509
526
  ]
510
527
  },
528
+ 'nginx/error.log' => {
529
+ format: :raw,
530
+ log: false,
531
+ pattern: [
532
+ %r{nginx/error.log}
533
+ ]
534
+ },
511
535
  'nginx/gitlab_registry_error.log' => {
512
536
  format: :time_space,
513
537
  log: true,
@@ -529,7 +553,7 @@ module GreenHat
529
553
  ]
530
554
  },
531
555
  'nginx/gitlab_registry_access.log' => {
532
- format: :raw,
556
+ format: :nginx,
533
557
  log: true,
534
558
  pattern: [
535
559
  %r{nginx/gitlab_registry_access.log}
@@ -738,13 +762,15 @@ module GreenHat
738
762
  'gitlab-rails/application.log' => {
739
763
  format: :raw,
740
764
  pattern: [
741
- %r{gitlab-rails/application.log}
765
+ %r{gitlab-rails/application.log},
766
+ %r{webservice.log/application.log}
742
767
  ]
743
768
  },
744
769
  'gitlab-rails/production.log' => {
745
770
  format: :raw,
746
771
  pattern: [
747
- %r{gitlab-rails/production.log}
772
+ %r{gitlab-rails/production.log},
773
+ %r{webservice.log/production.log}
748
774
  ]
749
775
  },
750
776
  'gitlab/version-manifest.txt' => {
@@ -758,6 +784,72 @@ module GreenHat
758
784
  pattern: [
759
785
  %r{sidekiq/perf.data}
760
786
  ]
787
+ },
788
+
789
+ # ======================================================================
790
+ # KubeSoS TODO Section
791
+ # Things I am going to shortcut and set to raw for now
792
+ # ======================================================================
793
+ # Attempted Parsing
794
+ 'kubesos_json' => {
795
+ log: true,
796
+ format: :kube_json,
797
+ pattern: [
798
+ /gitaly.log/
799
+ ]
800
+ },
801
+
802
+ 'kube_webservice' => {
803
+ log: false,
804
+ format: :kube_webservice,
805
+ pattern: [
806
+ /^webservice\.log$/
807
+ ]
808
+ },
809
+
810
+ 'kubesos' => {
811
+ format: :raw,
812
+ pattern: [
813
+ /all_values.yaml/,
814
+ %r{webservice.log/sidekiq_client.log},
815
+ /chart-version/,
816
+ /configmaps/,
817
+ /describe_deployments/,
818
+ /describe_ingress/,
819
+ /describe_nodes/,
820
+ /describe_pods/,
821
+ /describe_pv/,
822
+ /describe_pvc/,
823
+ /events/,
824
+ /get_deployments/,
825
+ /get_endpoints/,
826
+ /get_jobs/,
827
+ /get_pods/,
828
+ /get_pv/,
829
+ /get_pvc/,
830
+ /get_services/,
831
+ /gitaly.log/,
832
+ /gitlab-exporter.log/,
833
+ /gitlab-pages.log/,
834
+ /gitlab-shell.log/,
835
+ /grafana.log/,
836
+ /helm-version/,
837
+ /kubectl-check/,
838
+ /migrations.log/,
839
+ /minio.log/,
840
+ /nfs-client-provisioner.log/,
841
+ /operator.log/,
842
+ /postgresql.log/,
843
+ /prometheus.log/,
844
+ /redis.log/,
845
+ /registry.log/,
846
+ /secrets/,
847
+ /sidekiq.log/,
848
+ /task-runner.log/,
849
+ /top_nodes/,
850
+ /top_pods/,
851
+ /user_supplied_values.yaml/
852
+ ]
761
853
  }
762
854
  }
763
855
  end
@@ -0,0 +1,36 @@
1
+ # Top
2
+ module GreenHat
3
+ # Log
4
+ module Formatters
5
+ # ==========================================================================
6
+ # K8s logs seem to have a lot of non-json entries
7
+ # Extract all json, ignore everything else
8
+ # ==========================================================================
9
+ def format_kube_json
10
+ self.result = raw.map do |row|
11
+ # Skip all non-json
12
+ next unless row.first == '{'
13
+
14
+ result = begin
15
+ Oj.load row
16
+ rescue EncodingError
17
+ puts
18
+ next
19
+ end
20
+
21
+ # Parsing Time
22
+ format_json_traverse result
23
+
24
+ result.sort.to_h
25
+ rescue StandardError => e
26
+ # TODO: Background Logger?
27
+ e.message
28
+ LogBot.warn('JSON Parse', e.message)
29
+ next
30
+ end.compact
31
+
32
+ :ok
33
+ end
34
+ # =========================================================================
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ # Top
2
+ module GreenHat
3
+ # Log
4
+ module Formatters
5
+ # ==========================================================================
6
+ # Formatters
7
+ # ==========================================================================
8
+ def format_kube_nginx
9
+ self.result = raw.map do |row|
10
+ ip, _sym, remote_user, rest = row.split(' ', 4)
11
+
12
+ time, rest = rest.split(']', 2)
13
+ time = Time.strptime(time, '[%d/%b/%Y:%H:%M:%S %z')
14
+
15
+ verb, status, bytes, http_referer, http_user_agent, gzip_ratio = Shellwords.split(rest)
16
+
17
+ method, path, http_version = verb.split
18
+
19
+ {
20
+ remote_addr: ip,
21
+ remote_user: remote_user,
22
+ method: method,
23
+ path: path,
24
+ status: status,
25
+ bytes: bytes,
26
+ http_version: http_version,
27
+ http_referer: http_referer,
28
+ http_user_agent: http_user_agent,
29
+ gzip_ratio: gzip_ratio,
30
+ time: time
31
+ }
32
+
33
+ # Fall back for malformed logs
34
+ rescue StandardError
35
+ { message: row }
36
+ end
37
+
38
+ :ok
39
+ end
40
+
41
+ # rubocop:disable Layout/LineLength
42
+ # NGINX Conf: /var/opt/gitlab/nginx/conf/nginx.conf
43
+ # log_format gitlab_access '$remote_addr - $remote_user [$time_local] "$request_method $filtered_request_uri $server_protocol" $status $body_bytes_sent "$filtered_http_referer" "$http_user_agent" $gzip_ratio';
44
+ # rubocop:enable Layout/LineLength
45
+
46
+ # ==========================================================================
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ # Top
2
+ module GreenHat
3
+ # Log
4
+ module Formatters
5
+ # ==========================================================================
6
+ # Gitlab Tail Formatter
7
+ # ==========================================================================
8
+ def format_kube_webservice
9
+ # Revert to raw for cats
10
+ self.kind = :raw
11
+
12
+ output = {}
13
+ current_log = nil
14
+
15
+ raw.each do |line|
16
+ next if line.blank?
17
+
18
+ if line.include? '*** '
19
+ current_log = /\*\*\* (.+?) \*\*\*/.match(line).captures.first
20
+ else
21
+ output[current_log] ||= [] unless current_log.nil?
22
+ output[current_log].push line unless current_log.nil?
23
+ end
24
+ end
25
+
26
+ # Remove Empty Entries
27
+ output.reject { |_k, v| v.empty? }
28
+
29
+ # Root Dir
30
+ root_dir = "#{$TMP}/#{name}"
31
+ Dir.mkdir(root_dir)
32
+
33
+ # Write Files / Create Things
34
+ output.each do |k, v|
35
+ file_name = k.gsub('/var/log/gitlab/', '')
36
+
37
+ dir = "#{root_dir}/gitlab-rails"
38
+ Dir.mkdir(dir) unless File.exist?(dir)
39
+
40
+ File.write("#{root_dir}/#{file_name}", v.join("\n"))
41
+
42
+ # Thing Setup
43
+ archive.things_create(file: "#{root_dir}/#{file_name}").setup
44
+ end
45
+
46
+ # Link
47
+ self.result = raw
48
+ end
49
+ # ==========================================================================
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ # Top
2
+ module GreenHat
3
+ # Log
4
+ module Formatters
5
+ # ==========================================================================
6
+ # Formatters
7
+ # ==========================================================================
8
+ def format_nginx
9
+ self.result = raw.map do |row|
10
+ ip, _sym, remote_user, rest = row.split(' ', 4)
11
+
12
+ time, rest = rest.split(']', 2)
13
+ time = Time.strptime(time, '[%d/%b/%Y:%H:%M:%S %z')
14
+
15
+ verb, status, bytes, http_referer, http_user_agent, gzip_ratio = Shellwords.split(rest)
16
+
17
+ method, path, http_version = verb.split
18
+
19
+ {
20
+ remote_addr: ip,
21
+ remote_user: remote_user,
22
+ method: method,
23
+ path: path,
24
+ status: status,
25
+ bytes: bytes,
26
+ http_version: http_version,
27
+ http_referer: http_referer,
28
+ http_user_agent: http_user_agent,
29
+ gzip_ratio: gzip_ratio,
30
+ time: time
31
+ }
32
+ end
33
+
34
+ :ok
35
+ end
36
+
37
+ # rubocop:disable Layout/LineLength
38
+ # NGINX Conf: /var/opt/gitlab/nginx/conf/nginx.conf
39
+ # log_format gitlab_access '$remote_addr - $remote_user [$time_local] "$request_method $filtered_request_uri $server_protocol" $status $body_bytes_sent "$filtered_http_referer" "$http_user_agent" $gzip_ratio';
40
+ # rubocop:enable Layout/LineLength
41
+
42
+ # ==========================================================================
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ # Top
2
+ module GreenHat
3
+ # Log
4
+ module Formatters
5
+ # ==========================================================================
6
+ # Registry Split
7
+ # ==========================================================================
8
+ # https://docs.docker.com/registry/configuration/#log
9
+ # Formatters text, json
10
+ # registry['log_formatter'] = "json"
11
+ # TODO: Logstash (Not working in 14.3)
12
+
13
+ def format_time_registry
14
+ self.result = raw.map do |row|
15
+ result = row[0] == '{' ? registry_json(row) : registry_shell_words(row)
16
+
17
+ # Timestamp Parsing
18
+ result.ts = Time.parse result.ts if result.key? 'ts'
19
+ result.time = Time.parse(result.time)
20
+
21
+ result
22
+ end
23
+ end
24
+
25
+ def registry_shell_words(row)
26
+ time, msg = row.split(' ', 2)
27
+
28
+ output = Shellwords.split(msg).each_with_object({}) do |x, h|
29
+ key, value = x.split('=')
30
+ next if value.nil?
31
+
32
+ h[key.to_sym] = value.numeric? ? value.to_f : value
33
+ end
34
+
35
+ output[:time] = time
36
+
37
+ output
38
+ end
39
+
40
+ def registry_json(msg)
41
+ Oj.load(msg)
42
+ rescue EncodingError
43
+ { message: msg }
44
+ end
45
+ # ==========================================================================
46
+ end
47
+ end
@@ -26,6 +26,7 @@ class Thing < Teron
26
26
  field :parsed # Flag for Parsing
27
27
  field :result # Processed Data
28
28
  field :raw_result # Flag for reading raw data
29
+ field :result_fields # All available fields
29
30
 
30
31
  def friendly_name
31
32
  "#{archive.friendly_name.pastel(:blue)} #{name.pastel(:green)}"
@@ -49,6 +50,13 @@ class Thing < Teron
49
50
  result
50
51
  end
51
52
 
53
+ # Processor
54
+ def fields
55
+ process unless parsed
56
+
57
+ result_fields
58
+ end
59
+
52
60
  def raw
53
61
  raw_read if raw_result.nil?
54
62
 
@@ -116,6 +124,20 @@ class Thing < Teron
116
124
 
117
125
  self.parsed = true
118
126
 
127
+ self.result_fields = field_processing
128
+
119
129
  save!
120
130
  end
131
+
132
+ def field_processing
133
+ if data.instance_of?(Array)
134
+ data.select { |x| x.instance_of?(Hash) }.map(&:keys).flatten.uniq
135
+ else
136
+ []
137
+ end
138
+ rescue StandardError => e
139
+ LogBot.fatal('Process', message: e.message, backtrace: e.backtrace.first)
140
+
141
+ []
142
+ end
121
143
  end
@@ -1,3 +1,3 @@
1
1
  module GreenHat
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.4'.freeze
3
3
  end
data/lib/greenhat.rb CHANGED
@@ -21,6 +21,7 @@ require 'tty-prompt'
21
21
  require 'tty-reader'
22
22
  require 'tty-spinner'
23
23
  require 'tty-table'
24
+ require 'tty-which'
24
25
  require 'warning'
25
26
 
26
27
  # Custom Gem
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.0
4
+ version: 0.3.4
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-09-01 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -360,6 +360,20 @@ dependencies:
360
360
  - - "~>"
361
361
  - !ruby/object:Gem::Version
362
362
  version: '0.12'
363
+ - !ruby/object:Gem::Dependency
364
+ name: tty-which
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - "~>"
368
+ - !ruby/object:Gem::Version
369
+ version: '0.5'
370
+ type: :runtime
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - "~>"
375
+ - !ruby/object:Gem::Version
376
+ version: '0.5'
363
377
  - !ruby/object:Gem::Dependency
364
378
  name: warning
365
379
  requirement: !ruby/object:Gem::Requirement
@@ -405,11 +419,13 @@ files:
405
419
  - lib/greenhat/shell/color_string.rb
406
420
  - lib/greenhat/shell/disk.rb
407
421
  - lib/greenhat/shell/faststats.rb
422
+ - lib/greenhat/shell/field_helper.rb
408
423
  - lib/greenhat/shell/filter_help.rb
409
424
  - lib/greenhat/shell/gitlab.rb
410
425
  - lib/greenhat/shell/help.rb
411
426
  - lib/greenhat/shell/list.rb
412
427
  - lib/greenhat/shell/log.rb
428
+ - lib/greenhat/shell/markdown.rb
413
429
  - lib/greenhat/shell/memory.rb
414
430
  - lib/greenhat/shell/network.rb
415
431
  - lib/greenhat/shell/page.rb
@@ -429,8 +445,13 @@ files:
429
445
  - lib/greenhat/thing/formatters/gitlab_status.rb
430
446
  - lib/greenhat/thing/formatters/json.rb
431
447
  - lib/greenhat/thing/formatters/json_shellwords.rb
448
+ - lib/greenhat/thing/formatters/kube_json.rb
449
+ - lib/greenhat/thing/formatters/kube_nginx.rb
450
+ - lib/greenhat/thing/formatters/kube_webservice.rb
432
451
  - lib/greenhat/thing/formatters/multiline_json.rb
452
+ - lib/greenhat/thing/formatters/nginx.rb
433
453
  - lib/greenhat/thing/formatters/raw.rb
454
+ - lib/greenhat/thing/formatters/registry.rb
434
455
  - lib/greenhat/thing/formatters/shellwords.rb
435
456
  - lib/greenhat/thing/formatters/syslog.rb
436
457
  - lib/greenhat/thing/formatters/table.rb