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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d1acd7b3c698127214711199399e78d7b72f4762d8beb575fb2ac1d3e2ae1b
|
4
|
+
data.tar.gz: 011d2f2e27b278a06f87605d13809f3472b5223f39937e6fed55ecc28476ea00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b253023196cc698fc9022455e1a43e6add8fae2e63512e946fb207619e7e29c83783e9b9a265e1f77ce3dcbcb81be270b7bb3896a0822c6bad06c51dec8571f
|
7
|
+
data.tar.gz: 850d05cc4ea5d95e53e289c4781232af8719286c9b3c1165cf9afeac25bf19122a79249bc290ddad9cc4b00767d4c5396052fe5c7e9c43b9b7742f9c15eb1c7f
|
data/bin/greenhat
CHANGED
@@ -35,11 +35,13 @@ module GreenHat
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Show GitLab Services in a grid / include versions
|
38
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
38
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
39
39
|
def self.services(archive, indent = 0)
|
40
40
|
manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
|
41
41
|
gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }
|
42
42
|
|
43
|
+
# Dont' show invalid
|
44
|
+
return nil if gitlab_status.data.to_s.include? "Could not find 'bundler'"
|
43
45
|
return nil unless gitlab_status
|
44
46
|
|
45
47
|
list = gitlab_status.data.keys.sort.map do |service|
|
@@ -73,7 +75,7 @@ module GreenHat
|
|
73
75
|
|
74
76
|
table.render(:unicode, padding: [0, 1, 0, 1], indent: indent)
|
75
77
|
end
|
76
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
78
|
+
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
77
79
|
|
78
80
|
def self.services_markdown(archive)
|
79
81
|
# manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
|
data/lib/greenhat/archive.rb
CHANGED
@@ -61,6 +61,10 @@ module GreenHat
|
|
61
61
|
FileUtils.rm(archive_path)
|
62
62
|
when '.gz'
|
63
63
|
`gzip -d "#{archive_path}"`
|
64
|
+
when '.zip'
|
65
|
+
`unzip -o -d "#{base_path}" #{archive_path}`
|
66
|
+
when '.bz2'
|
67
|
+
`bzip2 -d #{archive_path}`
|
64
68
|
when '.s'
|
65
69
|
# Find Original Directory, Split Path, Rename to .gz
|
66
70
|
base_path = archive_path.gsub(File.basename(archive_path), '')
|
@@ -77,7 +81,7 @@ module GreenHat
|
|
77
81
|
end
|
78
82
|
|
79
83
|
def self.archive_types
|
80
|
-
%w[s gz tar tgz]
|
84
|
+
%w[s gz tar tgz zip bz2]
|
81
85
|
end
|
82
86
|
# -- Archive Loader ----------------------------------------------
|
83
87
|
end
|
data/lib/greenhat/cli.rb
CHANGED
@@ -109,19 +109,19 @@ module GreenHat
|
|
109
109
|
if submodule?
|
110
110
|
submodule!
|
111
111
|
reader.breaker = true
|
112
|
-
|
112
|
+
# Only one Match!
|
113
113
|
elsif matches.count == 1
|
114
114
|
auto_update(matches.first, word)
|
115
115
|
|
116
|
-
|
116
|
+
# Print List of Options
|
117
117
|
elsif matches.count > 1
|
118
118
|
puts matches.join("\t").pastel(:bright_green)
|
119
119
|
|
120
|
-
|
120
|
+
# General Filename Matching
|
121
121
|
elsif !file_matches(word).empty?
|
122
122
|
auto_files(file_matches(word), word)
|
123
123
|
|
124
|
-
|
124
|
+
# Submodule Autocompletion
|
125
125
|
elsif current_methods.include?('auto_complete')
|
126
126
|
update_text = current_location.auto_complete(@list, word)
|
127
127
|
auto_update(update_text, word) unless update_text.blank?
|
@@ -133,7 +133,7 @@ module GreenHat
|
|
133
133
|
if matches.count == 1
|
134
134
|
auto_update(matches.first, word)
|
135
135
|
|
136
|
-
|
136
|
+
# Print List of Options
|
137
137
|
elsif matches.count > 1
|
138
138
|
auto_update(common_substr(matches), word)
|
139
139
|
puts matches.join("\t").pastel(:bright_green)
|
@@ -245,12 +245,11 @@ module GreenHat
|
|
245
245
|
run!
|
246
246
|
|
247
247
|
return true # End Early
|
248
|
-
|
249
248
|
elsif current_submodule?
|
250
249
|
@list.shift
|
251
250
|
elsif submodule?
|
252
251
|
submodule!
|
253
|
-
|
252
|
+
# Prepend Default if exists
|
254
253
|
elsif default?
|
255
254
|
@list.unshift 'default'
|
256
255
|
else
|
@@ -284,7 +283,6 @@ module GreenHat
|
|
284
283
|
|
285
284
|
puts "=> #{item.to_s.pastel(:blue)}"
|
286
285
|
end
|
287
|
-
|
288
286
|
end
|
289
287
|
|
290
288
|
puts ''
|
@@ -366,8 +364,12 @@ module GreenHat
|
|
366
364
|
@quiet
|
367
365
|
end
|
368
366
|
|
369
|
-
# Toggle Quiet Settings
|
370
367
|
def self.quiet!
|
368
|
+
@quiet = true
|
369
|
+
end
|
370
|
+
|
371
|
+
# Toggle Quiet Settings
|
372
|
+
def self.quiet_toggle
|
371
373
|
@quiet = !@quiet
|
372
374
|
end
|
373
375
|
|
@@ -427,5 +429,6 @@ module GreenHat
|
|
427
429
|
exit 1
|
428
430
|
end
|
429
431
|
end
|
432
|
+
|
430
433
|
# rubocop:enable Metrics/ModuleLength
|
431
434
|
end
|
data/lib/greenhat/entrypoint.rb
CHANGED
@@ -36,7 +36,7 @@ module GreenHat
|
|
36
36
|
Settings.settings[:assume_raw] = false if flags?(%i[prompt p], flags)
|
37
37
|
|
38
38
|
# Quiet Flag
|
39
|
-
|
39
|
+
Cli.quiet! if flags?(%i[quiet q], flags)
|
40
40
|
|
41
41
|
if flags?(%i[load-local ll], flags)
|
42
42
|
# Hook in loading local
|
@@ -60,17 +60,17 @@ module GreenHat
|
|
60
60
|
|
61
61
|
# Run report and exit / Don't Clear for reports
|
62
62
|
if flags?(%i[report r], flags)
|
63
|
-
|
63
|
+
Cli.quiet!
|
64
64
|
# Don't Use Pagination
|
65
65
|
GreenHat::Shell.report(['--raw'])
|
66
66
|
exit 0
|
67
67
|
elsif flags?(%i[full-report f], flags)
|
68
|
-
|
68
|
+
Cli.quiet!
|
69
69
|
# Don't Use Pagination
|
70
70
|
GreenHat::Shell.report(['--raw', '--full'])
|
71
71
|
exit 0
|
72
72
|
elsif flags?(%i[markdown m], flags)
|
73
|
-
|
73
|
+
Cli.quiet!
|
74
74
|
# Don't Use Pagination
|
75
75
|
GreenHat::Shell.markdown_report(['--raw'])
|
76
76
|
exit 0
|
data/lib/greenhat/settings.rb
CHANGED
@@ -3,20 +3,42 @@ module GreenHat
|
|
3
3
|
# Helper for all things user environment / settings / history
|
4
4
|
module Settings
|
5
5
|
def self.settings
|
6
|
+
# round: [2],
|
7
|
+
# page: [:true] Automatic,
|
6
8
|
@settings ||= {
|
7
|
-
history: [],
|
8
9
|
assume_json: true,
|
9
|
-
assume_raw: false,
|
10
10
|
fuzzy_file_match: true,
|
11
|
-
|
12
|
-
#
|
13
|
-
# page: [:true] Automatic,
|
14
|
-
truncate: TTY::Screen.width * 4,
|
11
|
+
assume_raw: false,
|
12
|
+
truncate: TTY::Screen.width * 4, # Dynamic Setting
|
15
13
|
color: true
|
16
|
-
|
17
14
|
}
|
18
15
|
end
|
19
16
|
|
17
|
+
def self.configure_choices
|
18
|
+
[
|
19
|
+
|
20
|
+
{ name: 'Assume JSON - auto injest json', value: :assume_json },
|
21
|
+
{ name: 'Assume Raw - do not attempt unknown parsing', value: :assume_raw },
|
22
|
+
{ name: 'Fuzzy File Match - all partial matching', value: :fuzzy_file_match },
|
23
|
+
{ name: 'Color Output', value: :color }
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure_settings
|
28
|
+
puts 'Current Settings'.pastel(:green)
|
29
|
+
ap @settings.except(:truncate)
|
30
|
+
puts
|
31
|
+
|
32
|
+
prompt = TTY::Prompt.new
|
33
|
+
choice = prompt.select('Change Which Setting?', configure_choices, filter: true)
|
34
|
+
|
35
|
+
setting = configure_choices.find { |x| x.value == choice }
|
36
|
+
value = prompt.yes?("#{setting[:name]} (Y/n)")
|
37
|
+
@settings[choice] = value
|
38
|
+
|
39
|
+
File.write(settings_file, Oj.dump(@settings.except(:truncate)))
|
40
|
+
end
|
41
|
+
|
20
42
|
def self.assume_json?
|
21
43
|
settings.assume_json
|
22
44
|
end
|
@@ -2,191 +2,205 @@ module GreenHat
|
|
2
2
|
# CLI Helper
|
3
3
|
module ShellHelper
|
4
4
|
# Unify Filter / Filter Help
|
5
|
-
# rubocop:disable Metrics/MethodLength,
|
5
|
+
# rubocop:disable Metrics/MethodLength,Layout/LineLength
|
6
6
|
module Filter
|
7
|
-
def self.help
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
puts ' E.g. --page (default to true), --page=true, --page=false'
|
20
|
-
puts
|
21
|
-
|
22
|
-
puts '--round'.pastel(:green)
|
23
|
-
puts ' Attempt to round all integers. Default: 2.'
|
24
|
-
puts ' E.g. --round, --round=3, --round=0'
|
25
|
-
puts
|
26
|
-
|
27
|
-
puts '--limit'.pastel(:green)
|
28
|
-
puts ' Limit total output lines. Disabled by default. Default without value is based on screen height'
|
29
|
-
puts ' E.g. --limit, --limit=5'
|
30
|
-
puts
|
31
|
-
|
32
|
-
puts '--json'.pastel(:green)
|
33
|
-
puts ' Print output back into JSON'
|
34
|
-
puts
|
35
|
-
|
36
|
-
puts '--or'.pastel(:green)
|
37
|
-
puts ' Filters will use OR instead of AND (all match vs any match)'
|
38
|
-
puts
|
39
|
-
|
40
|
-
puts '--total'.pastel(:green)
|
41
|
-
puts ' Show total count, duration, start/end time for matching entries'
|
42
|
-
puts
|
43
|
-
|
44
|
-
puts '--fields'.pastel(:green)
|
45
|
-
puts ' Print only Available fields for selected files'
|
46
|
-
puts
|
47
|
-
|
48
|
-
puts '--slice'.pastel(:green)
|
49
|
-
puts ' Extract specific fields from entries (slice multiple with comma)'
|
50
|
-
puts ' Ex: --slice=path or --slice=path,params'
|
51
|
-
puts
|
52
|
-
|
53
|
-
puts '--except'.pastel(:green)
|
54
|
-
puts ' Exclude specific fields (except multiple with comma)'
|
55
|
-
puts ' Ex: --except=params --except=params,path'
|
56
|
-
puts
|
57
|
-
|
58
|
-
puts '--exists'.pastel(:green)
|
59
|
-
puts ' Ensure field exists regardless of contents'
|
60
|
-
puts ' Ex: --exists=params --exists=params,path'
|
61
|
-
puts
|
62
|
-
|
63
|
-
puts '--stats'.pastel(:green)
|
64
|
-
puts ' Order/Count occurrances by field. Combine with `truncate` for key names'
|
65
|
-
puts ' Ex: --stats=params --except=params,path'
|
66
|
-
puts
|
67
|
-
|
68
|
-
puts '--uniq'.pastel(:green)
|
69
|
-
puts ' Show unique values only'
|
70
|
-
puts ' Ex: --uniq=params --uniq=params,path'
|
71
|
-
puts
|
72
|
-
|
73
|
-
puts '--pluck'.pastel(:green)
|
74
|
-
puts ' Extract values from entries'
|
75
|
-
puts ' Ex: --pluck=params --pluck=params,path'
|
76
|
-
puts
|
77
|
-
|
78
|
-
puts '--archive'.pastel(:green)
|
79
|
-
puts ' Limit to specific archvie name (partial matching /inclusive). Matching SOS tar.gz name'
|
80
|
-
puts ' Ex: --archive=dev-gitlab_20210622154626, --archive=202106,202107'
|
81
|
-
puts
|
82
|
-
|
83
|
-
puts '--sort'.pastel(:green)
|
84
|
-
puts ' Sort by multiple fields'
|
85
|
-
puts ' Ex: --sort=duration_s,db_duration_s'
|
86
|
-
puts
|
87
|
-
|
88
|
-
puts '--reverse'.pastel(:green)
|
89
|
-
puts ' Reverse all results'
|
90
|
-
puts ' Ex: --reverse'
|
91
|
-
puts
|
92
|
-
|
93
|
-
puts '--combine'.pastel(:green)
|
94
|
-
puts ' Omit archive identifier dividers. Useful with sort or time filters'
|
95
|
-
puts ' Ex: --combine'
|
96
|
-
puts
|
97
|
-
|
98
|
-
puts '--case'.pastel(:green)
|
99
|
-
puts ' Exact case match. Defaults to case insensitive'
|
100
|
-
puts ' Ex: --case; --name=Jon, --name=jane --case'
|
101
|
-
puts
|
102
|
-
|
103
|
-
puts '--exact'.pastel(:green)
|
104
|
-
puts ' Exact parameter/value match. Defaults to partial match'
|
105
|
-
puts ' Ex: --field=CommonPartial --exact'
|
106
|
-
puts
|
107
|
-
|
108
|
-
puts '--start'.pastel(:green)
|
109
|
-
puts ' Show events after specified time. Filtered by the `time` field'
|
110
|
-
puts ' Use with `--end` for between selections'
|
111
|
-
puts ' Ex: log filter --start="2021-06-22 14:44 UTC" --end="2021-06-22 14:45 UTC"'
|
112
|
-
puts
|
113
|
-
|
114
|
-
puts '--end'.pastel(:green)
|
115
|
-
puts ' Show events before specified time. Filtered by the `time` field'
|
116
|
-
puts ' Use with `--start` for between selections'
|
117
|
-
puts ' Ex: log filter --end="2021-06-22"'
|
118
|
-
puts
|
119
|
-
|
120
|
-
puts '--time_zone'.pastel(:green)
|
121
|
-
puts ' Manipulate the `time` field into a specific timezone'
|
122
|
-
puts ' Ex: log filter --time_zone=EDT'
|
123
|
-
puts
|
124
|
-
|
125
|
-
puts '--text'.pastel(:green)
|
126
|
-
puts ' Full entry text searching (slow)'
|
127
|
-
puts ' --text="anything here"'
|
128
|
-
puts
|
129
|
-
|
130
|
-
puts '--table_style'.pastel(:green)
|
131
|
-
puts ' Renderer used for formatted output. basic, ascii, or unicode(default)'
|
132
|
-
puts ' Ex: log filter --table_style=base'
|
133
|
-
puts
|
134
|
-
|
135
|
-
puts '--truncate'.pastel(:green)
|
136
|
-
puts ' Truncate field length. On by default (4 rows). Performance issues!'
|
137
|
-
puts ' Disable with --truncate=0'.pastel(:bright_red)
|
138
|
-
puts ' Ex: --truncate=200, --truncate=2048"'
|
139
|
-
puts
|
140
|
-
|
141
|
-
puts 'Search specific logs'.pastel(:blue)
|
142
|
-
puts ' Any non dash parameters will be the log list to search from'
|
143
|
-
puts " Ex: log filter --path=api sidekiq/current (hint: use `#{'ls'.pastel(:yellow)}` for log names"
|
144
|
-
puts
|
145
|
-
|
146
|
-
puts 'General (Field) Searching'.pastel(:blue)
|
147
|
-
puts " There are different ways filter within specific keys/fields within log. The baseline is #{'--[key]=[value]'.pastel(:green)}"
|
148
|
-
puts ' This will, by default, select any entries with any partial match (case insensitive) of [value] in the entry [key]'
|
149
|
-
puts ' Example: --path=mirror/pull'
|
150
|
-
puts
|
151
|
-
|
152
|
-
puts " You can modify logic with params like: #{'case'.pastel(:green)}, #{'exact'.pastel(:green)}"
|
153
|
-
puts ' Ex Case turn on case sensitivity, exact will change from the inclusive to only exact matching.'
|
154
|
-
puts
|
155
|
-
|
156
|
-
puts " You can also use multiple #{'--[key]=[value]'.pastel(:green)} to narrow down, or combine it with #{'or'.pastel(:green)} to be more inclusive"
|
157
|
-
puts ' Ex nginx/gitlab_access.log --http_user_agent=gitlab-runner --path=/api/v4/jobs/request'
|
158
|
-
puts ' This will look through the access logs for anything that is a runner (user agent) and hitting the request endpoint'
|
159
|
-
puts
|
160
|
-
|
161
|
-
puts " You can also modify whether a field search excluded or a integer (and technically string) comparison by changing the operator: #{'(!= >= <=)'.pastel(:green)}"
|
162
|
-
puts ' Ex "nginx/gitlab_access.log --http_user_agent=gitlab-runner --http_user_agent!=13.12.0" will exclude any entries with 13.12.0/13.12 runners'
|
163
|
-
puts ' Ex "sidekiq/current --duration_s>=5 --class!=LdapSyncWorker" Duration over 5 that is not an ldap job'
|
164
|
-
puts
|
165
|
-
|
166
|
-
puts 'Pipe to Shell'.pastel(:blue)
|
167
|
-
puts ' This is very experimental! The idea is to take all the output from the search and allow a pipe into a traditional shell command.'
|
168
|
-
puts ' Due to the arg parsing its not a straight send to the terminal. You may need to escape quotes.'
|
169
|
-
puts ' Order is relevant, no arguments after the pipe'
|
170
|
-
puts
|
171
|
-
puts ' <files> <params> | grep path'
|
172
|
-
puts
|
173
|
-
|
174
|
-
puts 'Example Queries'.pastel(:blue)
|
175
|
-
puts " Also see #{'examples'.pastel(:bright_blue)} for even more examples"
|
176
|
-
puts ' log filter --class=BuildFinishedWorker sidekiq/current --slice=time,message'
|
177
|
-
puts ' log filter gitlab-rails/api_json.log --slice=ua --uniq=ua --ua=gitlab-runner'
|
178
|
-
|
179
|
-
puts
|
7
|
+
def self.help(args = '')
|
8
|
+
if args.blank?
|
9
|
+
help_index.values.map { |x| x.push '' }
|
10
|
+
else
|
11
|
+
list = help_index.select do |k, _v|
|
12
|
+
k.to_s.include? args
|
13
|
+
end
|
14
|
+
|
15
|
+
list.values
|
16
|
+
end
|
17
|
+
|
18
|
+
# .map { |x| x.join("\n") }.join("\n\n")
|
180
19
|
end
|
181
20
|
|
21
|
+
# TODO: Confirm Remove
|
22
|
+
# def self.legacy
|
23
|
+
# puts "\u2500".pastel(:cyan) * 20
|
24
|
+
# puts 'Filter'.pastel(:yellow)
|
25
|
+
# puts "\u2500".pastel(:cyan) * 20
|
26
|
+
|
27
|
+
# puts 'Options'.pastel(:blue)
|
28
|
+
# puts '--raw'.pastel(:green)
|
29
|
+
# puts ' Disable formatting and page/less'
|
30
|
+
# puts
|
31
|
+
|
32
|
+
# puts '--page'.pastel(:green)
|
33
|
+
# puts ' Specifically enable or disable paging'
|
34
|
+
# puts ' E.g. --page (default to true), --page=true, --page=false'
|
35
|
+
# puts
|
36
|
+
|
37
|
+
# puts '--round'.pastel(:green)
|
38
|
+
# puts ' Attempt to round all integers. Default: 2.'
|
39
|
+
# puts ' E.g. --round, --round=3, --round=0'
|
40
|
+
# puts
|
41
|
+
|
42
|
+
# puts '--limit'.pastel(:green)
|
43
|
+
# puts ' Limit total output lines. Disabled by default. Default without value is based on screen height'
|
44
|
+
# puts ' E.g. --limit, --limit=5'
|
45
|
+
# puts
|
46
|
+
|
47
|
+
# puts '--json'.pastel(:green)
|
48
|
+
# puts ' Print output back into JSON'
|
49
|
+
# puts
|
50
|
+
|
51
|
+
# puts '--or'.pastel(:green)
|
52
|
+
# puts ' Filters will use OR instead of AND (all match vs any match)'
|
53
|
+
# puts
|
54
|
+
|
55
|
+
# puts '--total'.pastel(:green)
|
56
|
+
# puts ' Show total count, duration, start/end time for matching entries'
|
57
|
+
# puts
|
58
|
+
|
59
|
+
# puts '--fields'.pastel(:green)
|
60
|
+
# puts ' Print only Available fields for selected files'
|
61
|
+
# puts
|
62
|
+
|
63
|
+
# puts '--slice'.pastel(:green)
|
64
|
+
# puts ' Extract specific fields from entries (slice multiple with comma)'
|
65
|
+
# puts ' Ex: --slice=path or --slice=path,params'
|
66
|
+
# puts
|
67
|
+
|
68
|
+
# puts '--except'.pastel(:green)
|
69
|
+
# puts ' Exclude specific fields (except multiple with comma)'
|
70
|
+
# puts ' Ex: --except=params --except=params,path'
|
71
|
+
# puts
|
72
|
+
|
73
|
+
# puts '--exists'.pastel(:green)
|
74
|
+
# puts ' Ensure field exists regardless of contents'
|
75
|
+
# puts ' Ex: --exists=params --exists=params,path'
|
76
|
+
# puts
|
77
|
+
|
78
|
+
# puts '--stats'.pastel(:green)
|
79
|
+
# puts ' Order/Count occurrances by field. Combine with `truncate` for key names'
|
80
|
+
# puts ' Ex: --stats=params --except=params,path'
|
81
|
+
# puts
|
82
|
+
|
83
|
+
# puts '--uniq'.pastel(:green)
|
84
|
+
# puts ' Show unique values only'
|
85
|
+
# puts ' Ex: --uniq=params --uniq=params,path'
|
86
|
+
# puts
|
87
|
+
|
88
|
+
# puts '--pluck'.pastel(:green)
|
89
|
+
# puts ' Extract values from entries'
|
90
|
+
# puts ' Ex: --pluck=params --pluck=params,path'
|
91
|
+
# puts
|
92
|
+
|
93
|
+
# puts '--archive'.pastel(:green)
|
94
|
+
# puts ' Limit to specific archvie name (partial matching /inclusive). Matching SOS tar.gz name'
|
95
|
+
# puts ' Ex: --archive=dev-gitlab_20210622154626, --archive=202106,202107'
|
96
|
+
# puts
|
97
|
+
|
98
|
+
# puts '--sort'.pastel(:green)
|
99
|
+
# puts ' Sort by multiple fields'
|
100
|
+
# puts ' Ex: --sort=duration_s,db_duration_s'
|
101
|
+
# puts
|
102
|
+
|
103
|
+
# puts '--reverse'.pastel(:green)
|
104
|
+
# puts ' Reverse all results'
|
105
|
+
# puts ' Ex: --reverse'
|
106
|
+
# puts
|
107
|
+
|
108
|
+
# puts '--combine'.pastel(:green)
|
109
|
+
# puts ' Omit archive identifier dividers. Useful with sort or time filters'
|
110
|
+
# puts ' Ex: --combine'
|
111
|
+
# puts
|
112
|
+
|
113
|
+
# puts '--case'.pastel(:green)
|
114
|
+
# puts ' Exact case match. Defaults to case insensitive'
|
115
|
+
# puts ' Ex: --case; --name=Jon, --name=jane --case'
|
116
|
+
# puts
|
117
|
+
|
118
|
+
# puts '--exact'.pastel(:green)
|
119
|
+
# puts ' Exact parameter/value match. Defaults to partial match'
|
120
|
+
# puts ' Ex: --field=CommonPartial --exact'
|
121
|
+
# puts
|
122
|
+
|
123
|
+
# puts '--start'.pastel(:green)
|
124
|
+
# puts ' Show events after specified time. Filtered by the `time` field'
|
125
|
+
# puts ' Use with `--end` for between selections'
|
126
|
+
# puts ' Ex: log filter --start="2021-06-22 14:44 UTC" --end="2021-06-22 14:45 UTC"'
|
127
|
+
# puts
|
128
|
+
|
129
|
+
# puts '--end'.pastel(:green)
|
130
|
+
# puts ' Show events before specified time. Filtered by the `time` field'
|
131
|
+
# puts ' Use with `--start` for between selections'
|
132
|
+
# puts ' Ex: log filter --end="2021-06-22"'
|
133
|
+
# puts
|
134
|
+
|
135
|
+
# puts '--time_zone'.pastel(:green)
|
136
|
+
# puts ' Manipulate the `time` field into a specific timezone'
|
137
|
+
# puts ' Ex: log filter --time_zone=EDT'
|
138
|
+
# puts
|
139
|
+
|
140
|
+
# puts '--text'.pastel(:green)
|
141
|
+
# puts ' Full entry text searching (slow)'
|
142
|
+
# puts ' --text="anything here"'
|
143
|
+
# puts
|
144
|
+
|
145
|
+
# puts '--table_style'.pastel(:green)
|
146
|
+
# puts ' Renderer used for formatted output. basic, ascii, or unicode(default)'
|
147
|
+
# puts ' Ex: log filter --table_style=base'
|
148
|
+
# puts
|
149
|
+
|
150
|
+
# puts '--truncate'.pastel(:green)
|
151
|
+
# puts ' Truncate field length. On by default (4 rows). Performance issues!'
|
152
|
+
# puts ' Disable with --truncate=0'.pastel(:bright_red)
|
153
|
+
# puts ' Ex: --truncate=200, --truncate=2048"'
|
154
|
+
# puts
|
155
|
+
|
156
|
+
# puts 'Search specific logs'.pastel(:blue)
|
157
|
+
# puts ' Any non dash parameters will be the log list to search from'
|
158
|
+
# puts " Ex: log filter --path=api sidekiq/current (hint: use `#{'ls'.pastel(:yellow)}` for log names"
|
159
|
+
# puts
|
160
|
+
|
161
|
+
# puts 'General (Field) Searching'.pastel(:blue)
|
162
|
+
# puts " There are different ways filter within specific keys/fields within log. The baseline is #{'--[key]=[value]'.pastel(:green)}"
|
163
|
+
# puts ' This will, by default, select any entries with any partial match (case insensitive) of [value] in the entry [key]'
|
164
|
+
# puts ' Example: --path=mirror/pull'
|
165
|
+
# puts
|
166
|
+
|
167
|
+
# puts " You can modify logic with params like: #{'case'.pastel(:green)}, #{'exact'.pastel(:green)}"
|
168
|
+
# puts ' Ex Case turn on case sensitivity, exact will change from the inclusive to only exact matching.'
|
169
|
+
# puts
|
170
|
+
|
171
|
+
# puts " You can also use multiple #{'--[key]=[value]'.pastel(:green)} to narrow down, or combine it with #{'or'.pastel(:green)} to be more inclusive"
|
172
|
+
# puts ' Ex nginx/gitlab_access.log --http_user_agent=gitlab-runner --path=/api/v4/jobs/request'
|
173
|
+
# puts ' This will look through the access logs for anything that is a runner (user agent) and hitting the request endpoint'
|
174
|
+
# puts
|
175
|
+
|
176
|
+
# puts " You can also modify whether a field search excluded or a integer (and technically string) comparison by changing the operator: #{'(!= >= <=)'.pastel(:green)}"
|
177
|
+
# puts ' Ex "nginx/gitlab_access.log --http_user_agent=gitlab-runner --http_user_agent!=13.12.0" will exclude any entries with 13.12.0/13.12 runners'
|
178
|
+
# puts ' Ex "sidekiq/current --duration_s>=5 --class!=LdapSyncWorker" Duration over 5 that is not an ldap job'
|
179
|
+
# puts
|
180
|
+
|
181
|
+
# puts 'Pipe to Shell'.pastel(:blue)
|
182
|
+
# puts ' This is very experimental! The idea is to take all the output from the search and allow a pipe into a traditional shell command.'
|
183
|
+
# puts ' Due to the arg parsing its not a straight send to the terminal. You may need to escape quotes.'
|
184
|
+
# puts ' Order is relevant, no arguments after the pipe'
|
185
|
+
# puts
|
186
|
+
# puts ' <files> <params> | grep path'
|
187
|
+
# puts
|
188
|
+
|
189
|
+
# puts 'Example Queries'.pastel(:blue)
|
190
|
+
# puts " Also see #{'examples'.pastel(:bright_blue)} for even more examples"
|
191
|
+
# puts ' log filter --class=BuildFinishedWorker sidekiq/current --slice=time,message'
|
192
|
+
# puts ' log filter gitlab-rails/api_json.log --slice=ua --uniq=ua --ua=gitlab-runner'
|
193
|
+
|
194
|
+
# puts
|
195
|
+
# end
|
196
|
+
|
182
197
|
def self.help_index
|
183
198
|
{
|
184
199
|
title: [
|
185
200
|
"\u2500".pastel(:cyan) * 20,
|
186
201
|
'Filter'.pastel(:yellow),
|
187
|
-
"\u2500".pastel(:cyan) * 20
|
188
|
-
|
189
|
-
options: [
|
202
|
+
"\u2500".pastel(:cyan) * 20,
|
203
|
+
'',
|
190
204
|
'Options'.pastel(:blue)
|
191
205
|
],
|
192
206
|
|
@@ -357,11 +371,30 @@ module GreenHat
|
|
357
371
|
' Ex: --truncate=200, --truncate=2048"'
|
358
372
|
],
|
359
373
|
|
360
|
-
|
361
|
-
'Field Searching'.pastel(:blue),
|
362
|
-
'
|
363
|
-
'
|
364
|
-
' Example: --path=mirror/pull'
|
374
|
+
field_search: [
|
375
|
+
'General (Field) Searching'.pastel(:blue),
|
376
|
+
" There are different ways filter within specific keys/fields within log. The baseline is #{'--[key]=[value]'.pastel(:green)}",
|
377
|
+
' This will, by default, select any entries with any partial match (case insensitive) of [value] in the entry [key]',
|
378
|
+
' Example: --path=mirror/pull',
|
379
|
+
'',
|
380
|
+
" You can modify logic with params like: #{'case'.pastel(:green)}, #{'exact'.pastel(:green)}",
|
381
|
+
' Ex Case turn on case sensitivity, exact will change from the inclusive to only exact matching.',
|
382
|
+
'',
|
383
|
+
" You can also use multiple #{'--[key]=[value]'.pastel(:green)} to narrow down, or combine it with #{'or'.pastel(:green)} to be more inclusive",
|
384
|
+
' Ex nginx/gitlab_access.log --http_user_agent=gitlab-runner --path=/api/v4/jobs/request',
|
385
|
+
' This will look through the access logs for anything that is a runner (user agent) and hitting the request endpoint',
|
386
|
+
'',
|
387
|
+
" You can also modify whether a field search excluded or a integer (and technically string) comparison by changing the operator: #{'(!= >= <=)'.pastel(:green)}",
|
388
|
+
' Ex "nginx/gitlab_access.log --http_user_agent=gitlab-runner --http_user_agent!=13.12.0" will exclude any entries with 13.12.0/13.12 runners',
|
389
|
+
' Ex "sidekiq/current --duration_s>=5 --class!=LdapSyncWorker" Duration over 5 that is not an ldap job'
|
390
|
+
],
|
391
|
+
|
392
|
+
pipe_to_shell: [
|
393
|
+
'Pipe to Shell'.pastel(:blue),
|
394
|
+
' This is very experimental! The idea is to take all the output from the search and allow a pipe into a traditional shell command.',
|
395
|
+
' Due to the arg parsing its not a straight send to the terminal. You may need to escape quotes.',
|
396
|
+
' Order is relevant, no arguments after the pipe',
|
397
|
+
' <files> <params> | grep path'
|
365
398
|
],
|
366
399
|
|
367
400
|
ls: [
|
@@ -379,7 +412,7 @@ module GreenHat
|
|
379
412
|
|
380
413
|
}
|
381
414
|
end
|
382
|
-
# rubocop:enable Metrics/MethodLength,
|
415
|
+
# rubocop:enable Metrics/MethodLength,Layout/LineLength
|
383
416
|
end
|
384
417
|
end
|
385
418
|
end
|