greenhat 0.3.1 → 0.3.5

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,
@@ -87,6 +94,12 @@ module GreenHat
87
94
  /getenforce/
88
95
  ]
89
96
  },
97
+ 'geo-logcursor/current' => {
98
+ format: :raw,
99
+ pattern: [
100
+ %r{geo-logcursor/current}
101
+ ]
102
+ },
90
103
  'gitaly/current' => {
91
104
  format: :json_shell,
92
105
  log: true,
@@ -225,7 +238,8 @@ module GreenHat
225
238
  format: :json,
226
239
  log: true,
227
240
  pattern: [
228
- %r{gitlab-rails/audit_json.log}
241
+ %r{gitlab-rails/audit_json.log},
242
+ %r{webservice.log/audit_json.log}
229
243
  ]
230
244
  },
231
245
  'gitlab-rails/auth.log' => {
@@ -336,6 +350,13 @@ module GreenHat
336
350
  %r{nginx/current}
337
351
  ]
338
352
  },
353
+ 'nginx-ingress.log' => {
354
+ format: :kube_nginx,
355
+ log: true,
356
+ pattern: [
357
+ /nginx-ingress.log/
358
+ ]
359
+ },
339
360
  'nginx/gitlab_pages_access.log' => {
340
361
  format: :nginx,
341
362
  log: true,
@@ -422,7 +443,7 @@ module GreenHat
422
443
  ]
423
444
  },
424
445
  'registry/current' => {
425
- format: :time_shellwords,
446
+ format: :time_registry,
426
447
  log: true,
427
448
  pattern: [
428
449
  %r{registry/current},
@@ -444,16 +465,18 @@ module GreenHat
444
465
  },
445
466
  'puma/puma_stderr.log' => {
446
467
  format: :raw,
447
- log: true,
468
+ log: false,
448
469
  pattern: [
449
- %r{puma/puma_stderr.log}
470
+ %r{puma/puma_stderr.log},
471
+ %r{webservice.log/puma.stderr.log}
450
472
  ]
451
473
  },
452
474
  'puma/puma_stdout.log' => {
453
475
  format: :json,
454
476
  log: true,
455
477
  pattern: [
456
- %r{puma/puma_stdout.log}
478
+ %r{puma/puma_stdout.log},
479
+ %r{webservice.log/puma.stdout.log}
457
480
  ]
458
481
  },
459
482
  'gitlab-pages/current' => {
@@ -745,13 +768,15 @@ module GreenHat
745
768
  'gitlab-rails/application.log' => {
746
769
  format: :raw,
747
770
  pattern: [
748
- %r{gitlab-rails/application.log}
771
+ %r{gitlab-rails/application.log},
772
+ %r{webservice.log/application.log}
749
773
  ]
750
774
  },
751
775
  'gitlab-rails/production.log' => {
752
776
  format: :raw,
753
777
  pattern: [
754
- %r{gitlab-rails/production.log}
778
+ %r{gitlab-rails/production.log},
779
+ %r{webservice.log/production.log}
755
780
  ]
756
781
  },
757
782
  'gitlab/version-manifest.txt' => {
@@ -765,6 +790,72 @@ module GreenHat
765
790
  pattern: [
766
791
  %r{sidekiq/perf.data}
767
792
  ]
793
+ },
794
+
795
+ # ======================================================================
796
+ # KubeSoS TODO Section
797
+ # Things I am going to shortcut and set to raw for now
798
+ # ======================================================================
799
+ # Attempted Parsing
800
+ 'kubesos_json' => {
801
+ log: true,
802
+ format: :kube_json,
803
+ pattern: [
804
+ /gitaly.log/
805
+ ]
806
+ },
807
+
808
+ 'kube_webservice' => {
809
+ log: false,
810
+ format: :kube_webservice,
811
+ pattern: [
812
+ /^webservice\.log$/
813
+ ]
814
+ },
815
+
816
+ 'kubesos' => {
817
+ format: :raw,
818
+ pattern: [
819
+ /all_values.yaml/,
820
+ %r{webservice.log/sidekiq_client.log},
821
+ /chart-version/,
822
+ /configmaps/,
823
+ /describe_deployments/,
824
+ /describe_ingress/,
825
+ /describe_nodes/,
826
+ /describe_pods/,
827
+ /describe_pv/,
828
+ /describe_pvc/,
829
+ /events/,
830
+ /get_deployments/,
831
+ /get_endpoints/,
832
+ /get_jobs/,
833
+ /get_pods/,
834
+ /get_pv/,
835
+ /get_pvc/,
836
+ /get_services/,
837
+ /gitaly.log/,
838
+ /gitlab-exporter.log/,
839
+ /gitlab-pages.log/,
840
+ /gitlab-shell.log/,
841
+ /grafana.log/,
842
+ /helm-version/,
843
+ /kubectl-check/,
844
+ /migrations.log/,
845
+ /minio.log/,
846
+ /nfs-client-provisioner.log/,
847
+ /operator.log/,
848
+ /postgresql.log/,
849
+ /prometheus.log/,
850
+ /redis.log/,
851
+ /registry.log/,
852
+ /secrets/,
853
+ /sidekiq.log/,
854
+ /task-runner.log/,
855
+ /top_nodes/,
856
+ /top_pods/,
857
+ /user_supplied_values.yaml/
858
+ ]
768
859
  }
769
860
  }
770
861
  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
@@ -34,10 +34,10 @@ module GreenHat
34
34
  :ok
35
35
  end
36
36
 
37
- # rubocop:disable Metrics/LineLength
37
+ # rubocop:disable Layout/LineLength
38
38
  # NGINX Conf: /var/opt/gitlab/nginx/conf/nginx.conf
39
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 Metrics/LineLength
40
+ # rubocop:enable Layout/LineLength
41
41
 
42
42
  # ==========================================================================
43
43
  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.1'.freeze
2
+ VERSION = '0.3.5'.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.1
4
+ version: 0.3.5
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-14 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,9 +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
433
452
  - lib/greenhat/thing/formatters/nginx.rb
434
453
  - lib/greenhat/thing/formatters/raw.rb
454
+ - lib/greenhat/thing/formatters/registry.rb
435
455
  - lib/greenhat/thing/formatters/shellwords.rb
436
456
  - lib/greenhat/thing/formatters/syslog.rb
437
457
  - lib/greenhat/thing/formatters/table.rb