greenhat 0.4.0 → 0.5.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 +4 -4
- data/bin/greenhat +1 -2
- data/lib/greenhat/accessors/gitlab.rb +4 -2
- data/lib/greenhat/archive.rb +5 -1
- data/lib/greenhat/cli.rb +12 -9
- data/lib/greenhat/entrypoint.rb +4 -4
- data/lib/greenhat/settings.rb +29 -7
- data/lib/greenhat/shell/filter_help.rb +216 -183
- data/lib/greenhat/shell/gitlab.rb +1 -0
- data/lib/greenhat/shell/log.rb +11 -21
- data/lib/greenhat/shell/query.rb +378 -0
- data/lib/greenhat/shell/report.rb +2 -0
- data/lib/greenhat/shell/shell_helper.rb +11 -361
- data/lib/greenhat/shell.rb +9 -1
- data/lib/greenhat/thing/file_types.rb +7 -0
- data/lib/greenhat/thing/formatters/api_json.rb +4 -2
- data/lib/greenhat/thing/formatters/bracket_log.rb +1 -1
- data/lib/greenhat/thing/formatters/colon_split_strip.rb +2 -2
- data/lib/greenhat/thing/formatters/dotenv.rb +1 -1
- data/lib/greenhat/thing/formatters/format.rb +0 -11
- data/lib/greenhat/thing/formatters/free_m.rb +2 -2
- data/lib/greenhat/thing/formatters/json.rb +41 -17
- data/lib/greenhat/thing/formatters/json_shellwords.rb +3 -2
- data/lib/greenhat/thing/formatters/kube_json.rb +3 -2
- data/lib/greenhat/thing/formatters/multiline_json.rb +1 -1
- data/lib/greenhat/thing/formatters/nginx.rb +5 -1
- data/lib/greenhat/thing/formatters/table.rb +3 -3
- data/lib/greenhat/thing/helpers.rb +0 -11
- data/lib/greenhat/thing/info_format.rb +4 -4
- data/lib/greenhat/thing/super_log.rb +0 -101
- data/lib/greenhat/thing.rb +20 -25
- data/lib/greenhat/version.rb +1 -1
- metadata +3 -2
@@ -19,9 +19,9 @@ module GreenHat
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Parsing Time
|
22
|
-
|
22
|
+
format_time(result)
|
23
23
|
|
24
|
-
result
|
24
|
+
result
|
25
25
|
rescue StandardError => e
|
26
26
|
# TODO: Background Logger?
|
27
27
|
e.message
|
@@ -31,6 +31,7 @@ module GreenHat
|
|
31
31
|
|
32
32
|
:ok
|
33
33
|
end
|
34
|
+
|
34
35
|
# =========================================================================
|
35
36
|
end
|
36
37
|
end
|
@@ -6,7 +6,9 @@ module GreenHat
|
|
6
6
|
# Formatters
|
7
7
|
# ==========================================================================
|
8
8
|
def format_nginx
|
9
|
-
|
9
|
+
output = raw.map do |row|
|
10
|
+
next if row.chomp.empty?
|
11
|
+
|
10
12
|
conn_data, rest = row.split(' [', 2)
|
11
13
|
ip, _sym, remote_user = conn_data.split(' ', 3)
|
12
14
|
|
@@ -35,6 +37,8 @@ module GreenHat
|
|
35
37
|
{ msg: row }
|
36
38
|
end
|
37
39
|
|
40
|
+
# Remove Empty Entries
|
41
|
+
self.result = output.compact
|
38
42
|
:ok
|
39
43
|
end
|
40
44
|
|
@@ -2,17 +2,17 @@
|
|
2
2
|
module GreenHat
|
3
3
|
# Log
|
4
4
|
module Formatters
|
5
|
-
#
|
5
|
+
# Table Formatting
|
6
6
|
def format_table
|
7
7
|
# Headers to Readable Symbol
|
8
|
-
headers =
|
8
|
+
headers = raw_full.first.split(' ', 6).map(&:downcase).map do |x|
|
9
9
|
x.gsub(/\s+/, '_').gsub(/[^0-9A-Za-z_]/, '')
|
10
10
|
end.map(&:to_sym)
|
11
11
|
|
12
12
|
final = []
|
13
13
|
|
14
14
|
# Put fields into a Hash based on Location/Key
|
15
|
-
|
15
|
+
raw_full.map(&:split)[1..].each do |row|
|
16
16
|
result = {}
|
17
17
|
row.each_with_index do |detail, i|
|
18
18
|
result[headers[i]] = detail
|
@@ -64,15 +64,15 @@ module GreenHat
|
|
64
64
|
conns, sockets = raw.split { |x| x.include? 'Active' }.reject(&:empty?)
|
65
65
|
|
66
66
|
formatted_conns = conns[1..].map do |entry|
|
67
|
-
entry.split(' ', 7).map(&:strip).each_with_index.
|
67
|
+
entry.split(' ', 7).map(&:strip).each_with_index.to_h do |field, idx|
|
68
68
|
[format_netstat_conn_headers[idx], field]
|
69
|
-
end
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|
72
72
|
formatted_sockets = sockets[1..].map do |entry|
|
73
|
-
entry.split(' ').map(&:strip).reject(&:blank?).each_with_index.
|
73
|
+
entry.split(' ').map(&:strip).reject(&:blank?).each_with_index.to_h do |field, idx|
|
74
74
|
[format_netstat_socket_headers[idx], field]
|
75
|
-
end
|
75
|
+
end
|
76
76
|
end
|
77
77
|
|
78
78
|
{
|
@@ -1,102 +1 @@
|
|
1
|
-
# TODO: Deprecate, was used specifically for Elk
|
2
|
-
# rubocop:disable /AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/
|
3
|
-
module GreenHat
|
4
|
-
# Log Identifier
|
5
|
-
module SuperLog
|
6
|
-
def self.log?(kind)
|
7
|
-
[
|
8
|
-
'gitaly/current',
|
9
|
-
'gitaly/gitaly_ruby_json.log',
|
10
|
-
'gitlab-rails/api_json.log',
|
11
|
-
'gitlab-rails/application_json.log',
|
12
|
-
'gitlab-rails/audit_json.log',
|
13
|
-
'gitlab-rails/graphql_json.log',
|
14
|
-
'gitlab-rails/integrations_json.log',
|
15
|
-
'gitlab-rails/production_json.log',
|
16
|
-
'gitlab-rails/sidekiq_client.log',
|
17
|
-
'gitlab-shell/gitlab-shell.log',
|
18
|
-
'gitlab-workhorse/current',
|
19
|
-
'puma/puma_stdout.log',
|
20
|
-
'sidekiq/current',
|
21
|
-
'gitlab-rails/importer.log',
|
22
|
-
'gitlabsos.log',
|
23
|
-
'nginx/gitlab_access.log',
|
24
|
-
'patroni/current'
|
25
|
-
].any? { |x| x.include? kind.to_s }
|
26
1
|
|
27
|
-
true
|
28
|
-
end
|
29
|
-
|
30
|
-
# ==========================================================================
|
31
|
-
# File Pattern Matching
|
32
|
-
# ==========================================================================
|
33
|
-
def self.api_json_format?(path)
|
34
|
-
['rails_api_json_log'].any? { |x| path.include? x }
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.unicorn_stderr_format?(path)
|
38
|
-
%w[
|
39
|
-
unicorn_stderr
|
40
|
-
].any? { |x| path.include? x }
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.reconfigure_format?(path)
|
44
|
-
%w[
|
45
|
-
reconfigure
|
46
|
-
].any? { |x| path.include? x }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.shellwords?(path)
|
50
|
-
%w[
|
51
|
-
gitlab_pages_current
|
52
|
-
alertmanager_current
|
53
|
-
registry_current
|
54
|
-
prometheus_current
|
55
|
-
|
56
|
-
].any? { |x| path.include? x }
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.time_space?(path)
|
60
|
-
%w[
|
61
|
-
postgresql_current
|
62
|
-
redis_current
|
63
|
-
unicorn_current
|
64
|
-
gitlab_monitor_current
|
65
|
-
sidekiq_exporter_log
|
66
|
-
].any? { |x| path.include? x }
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.json_format?(path)
|
70
|
-
%w[
|
71
|
-
production_json_log
|
72
|
-
gitaly_current
|
73
|
-
geo_log
|
74
|
-
sidekiq_current
|
75
|
-
sidekiq_log
|
76
|
-
gitlab_shell_gitlab_shell_log
|
77
|
-
gitlab_rails_audit_json_log
|
78
|
-
gitlab_rails_application_json_log
|
79
|
-
].any? { |x| path.include? x }
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.dmesg_format?(path)
|
83
|
-
%w[
|
84
|
-
dmesg
|
85
|
-
].any? { |x| path.include? x }
|
86
|
-
end
|
87
|
-
# ==========================================================================
|
88
|
-
|
89
|
-
# Identify Formatter
|
90
|
-
def self.type?(path)
|
91
|
-
return :api_json_format if api_json_format?(path)
|
92
|
-
return :unicorn_stderr_format if unicorn_stderr_format?(path)
|
93
|
-
return :reconfigure_format if reconfigure_format?(path)
|
94
|
-
return :shellwords if shellwords?(path)
|
95
|
-
return :time_space if time_space?(path)
|
96
|
-
return :json_format if json_format?(path)
|
97
|
-
return :dmesg_format if dmesg_format?(path)
|
98
|
-
|
99
|
-
nil
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
data/lib/greenhat/thing.rb
CHANGED
@@ -24,8 +24,7 @@ class Thing < Teron
|
|
24
24
|
|
25
25
|
# Preloader Flags
|
26
26
|
field :parsed # Flag for Parsing
|
27
|
-
field :result # Processed Data
|
28
|
-
field :raw_result # Flag for reading raw data
|
27
|
+
field :result, dump: false # Processed Data
|
29
28
|
field :result_fields # All available fields
|
30
29
|
|
31
30
|
def friendly_name
|
@@ -57,10 +56,14 @@ class Thing < Teron
|
|
57
56
|
result_fields
|
58
57
|
end
|
59
58
|
|
59
|
+
# Readlines rather than putting whole thing into memory
|
60
60
|
def raw
|
61
|
-
|
61
|
+
File.foreach(file)
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
+
# Where full read is needed
|
65
|
+
def raw_full
|
66
|
+
File.read(file).split("\n")
|
64
67
|
end
|
65
68
|
|
66
69
|
# Filter / Archive Pattern Matching
|
@@ -73,32 +76,27 @@ class Thing < Teron
|
|
73
76
|
data.blank?
|
74
77
|
end
|
75
78
|
|
76
|
-
def raw_read
|
77
|
-
spin_start("Read #{name.pastel(:blue)} #{size.pastel(:bright_black)}")
|
78
|
-
self.raw_result = File.read(file).split("\n")
|
79
|
-
rescue StandardError => e
|
80
|
-
LogBot.fatal('Raw Read', message: e.message, backtrace: e.backtrace.first)
|
81
|
-
self.raw_result = ''
|
82
|
-
ensure
|
83
|
-
spin_done
|
84
|
-
end
|
85
|
-
|
86
79
|
def output(print_it = true)
|
87
80
|
if print_it
|
88
|
-
puts raw.
|
81
|
+
puts raw.map(&:to_s).map(&:chomp)
|
89
82
|
else
|
90
|
-
raw
|
83
|
+
raw.map(&:to_s).map(&:chomp)
|
91
84
|
end
|
92
85
|
end
|
93
86
|
|
94
|
-
#
|
95
|
-
def
|
96
|
-
|
87
|
+
# Hashed values searching
|
88
|
+
def process?
|
89
|
+
kind != :raw && methods.include?(formatter)
|
97
90
|
end
|
98
91
|
|
99
|
-
#
|
100
|
-
def
|
101
|
-
|
92
|
+
# Things that can be queried (Query Helper)
|
93
|
+
def query?
|
94
|
+
data.instance_of?(Array)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Helper for all things that can be hash/value filtered
|
98
|
+
def self.list
|
99
|
+
all.select.select(&:process?)
|
102
100
|
end
|
103
101
|
|
104
102
|
# Helper Formatter Method
|
@@ -107,9 +105,6 @@ class Thing < Teron
|
|
107
105
|
end
|
108
106
|
|
109
107
|
def process
|
110
|
-
# Read First if Needed (Spinner)
|
111
|
-
raw_read if raw_result.nil?
|
112
|
-
|
113
108
|
if methods.include? formatter
|
114
109
|
spin_start("Parse #{name.pastel(:blue)} #{kind.to_s.pastel(:bright_black)} ")
|
115
110
|
begin
|
data/lib/greenhat/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -476,6 +476,7 @@ files:
|
|
476
476
|
- lib/greenhat/shell/pipe.rb
|
477
477
|
- lib/greenhat/shell/platform.rb
|
478
478
|
- lib/greenhat/shell/process.rb
|
479
|
+
- lib/greenhat/shell/query.rb
|
479
480
|
- lib/greenhat/shell/report.rb
|
480
481
|
- lib/greenhat/shell/shell_helper.rb
|
481
482
|
- lib/greenhat/thing.rb
|