greenhat 0.2.0 → 0.3.3

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/greenhat/accessors/disk.rb +13 -13
  3. data/lib/greenhat/accessors/gitlab.rb +75 -0
  4. data/lib/greenhat/accessors/memory.rb +10 -10
  5. data/lib/greenhat/accessors/process.rb +4 -0
  6. data/lib/greenhat/cli.rb +147 -58
  7. data/lib/greenhat/color.rb +27 -0
  8. data/lib/greenhat/logbot.rb +9 -9
  9. data/lib/greenhat/settings.rb +27 -7
  10. data/lib/greenhat/shell/args.rb +146 -0
  11. data/lib/greenhat/shell/cat.rb +25 -73
  12. data/lib/greenhat/shell/color_string.rb +8 -8
  13. data/lib/greenhat/shell/disk.rb +31 -4
  14. data/lib/greenhat/shell/faststats.rb +103 -56
  15. data/lib/greenhat/shell/field_helper.rb +75 -0
  16. data/lib/greenhat/shell/filter_help.rb +162 -0
  17. data/lib/greenhat/shell/gitlab.rb +61 -2
  18. data/lib/greenhat/shell/help.rb +98 -15
  19. data/lib/greenhat/shell/list.rb +46 -0
  20. data/lib/greenhat/shell/log.rb +118 -104
  21. data/lib/greenhat/shell/page.rb +11 -5
  22. data/lib/greenhat/shell/process.rb +29 -17
  23. data/lib/greenhat/shell/report.rb +37 -47
  24. data/lib/greenhat/shell/shell_helper.rb +661 -0
  25. data/lib/greenhat/shell.rb +23 -9
  26. data/lib/greenhat/thing/file_types.rb +31 -5
  27. data/lib/greenhat/thing/formatters/json_shellwords.rb +0 -3
  28. data/lib/greenhat/thing/formatters/nginx.rb +44 -0
  29. data/lib/greenhat/thing/helpers.rb +4 -4
  30. data/lib/greenhat/thing/kind.rb +9 -2
  31. data/lib/greenhat/thing/spinner.rb +3 -3
  32. data/lib/greenhat/thing.rb +25 -3
  33. data/lib/greenhat/tty/columns.rb +4 -0
  34. data/lib/greenhat/version.rb +1 -1
  35. data/lib/greenhat.rb +15 -14
  36. metadata +38 -18
  37. data/lib/greenhat/shell/filter.rb +0 -128
  38. data/lib/greenhat/shell/helper.rb +0 -584
@@ -3,172 +3,186 @@ module GreenHat
3
3
  module Shell
4
4
  # Logs
5
5
  module Log
6
+ def self.auto_complete(list, word)
7
+ # Argument Parsing
8
+ files, flags, _args = Args.parse(list)
9
+
10
+ # Don't try to autocomplete anything else
11
+ return nil unless word =~ /^-/
12
+
13
+ # Clean Up
14
+ word.delete!('-')
15
+ matches = FieldHelper.filter_flags(word)
16
+
17
+ if matches.count == 1
18
+ "--#{matches.first}"
19
+ elsif matches.count > 1
20
+ puts "#{'Filter Options:'.pastel(:bright_blue)} #{matches.join(' ').pastel(:bright_green)}"
21
+ "--#{Cli.common_substr(matches)}"
22
+ # -----------------------------------
23
+ # TODO: Fix Icky Double Nesting
24
+ elsif files.count.nonzero?
25
+ matches = FieldHelper.fields_find(files, word, flags)
26
+
27
+ return nil if matches.nil?
28
+
29
+ if matches.count == 1
30
+ "--#{matches.first}"
31
+ elsif matches.count > 1
32
+ puts "#{'Field Options:'.pastel(:bright_blue)} #{matches.join(' ').pastel(:bright_green)}"
33
+ "--#{Cli.common_substr(matches.map(&:to_s))}"
34
+ elsif FieldHelper.field_auto_complete?(word)
35
+ FieldHelper.field_auto_complete(word, files, flags)
36
+ end
37
+ # -----------------------------------
38
+ end
39
+ end
40
+
6
41
  def self.help
7
- puts "\u2500".colorize(:cyan) * 20
8
- puts "#{'Logs'.colorize(:yellow)} find stuff"
9
- puts "\u2500".colorize(:cyan) * 20
42
+ puts "\u2500".pastel(:cyan) * 20
43
+ puts "#{'Logs'.pastel(:yellow)} find stuff"
44
+ puts "\u2500".pastel(:cyan) * 20
45
+
46
+ puts 'Command Summary'.pastel(:blue)
47
+ puts ' filter'.pastel(:green)
48
+ puts " Primary way for log searching within greenhat. See #{'filter_help'.pastel(:blue)}"
49
+ puts ' Time, round, slice/except, and/or, stats, uniq, sort'
50
+ puts
10
51
 
11
- puts 'Command Summary'.colorize(:blue)
12
- puts ' show'.colorize(:green)
52
+ puts ' show'.pastel(:green)
13
53
  puts ' Just print selected logs'
14
- puts ' filter'.colorize(:green)
15
- puts ' Key/Field Filtering'
16
- puts ' - See `filter_help`'
17
- puts ' search'.colorize(:green)
18
- puts ' General text by entry searching'
19
- puts ' - See `search_help`'
20
- puts ' ls'.colorize(:green)
21
- puts ' List available files'
22
54
  puts
23
- end
24
-
25
- def self.filter_help
26
- ShellHelper::Filter.help
27
- end
28
-
29
- # List Files Helpers
30
- def self.list(args = [])
31
- all = false
32
- all = true if args.include?('-a') || args.include?('--all')
33
55
 
34
- files = ShellHelper::Log.list
56
+ puts ' search'.pastel(:green)
57
+ puts " General full text by file searching. See #{'search_help'.pastel(:blue)}"
58
+ puts
35
59
 
36
- # Sort
37
- files.sort_by!(&:name)
60
+ puts ShellHelper::List.help
38
61
 
39
- # Short & Uniq
40
- files.uniq!(&:name) unless all
62
+ puts "See #{'examples'.pastel(:bright_blue)} for query examples"
63
+ end
41
64
 
42
- # Print
43
- files.each do |log|
44
- if all
45
- puts "- #{log.friendly_name}"
46
- else
47
- puts "- #{log.name.colorize(:yellow)}"
48
- end
49
- end
65
+ def self.filter_help
66
+ ShellHelper::Filter.help
50
67
  end
51
68
 
52
69
  def self.ls(args = [])
53
- list(args)
70
+ ShellHelper::List.list(args, ShellHelper::Log.list)
54
71
  end
55
72
 
56
- def self.show(log_list)
57
- # Prepare Log List
58
- log_list = ShellHelper.prepare_list(log_list)
59
-
60
- # Convert to Things
61
- logs = ShellHelper.find_things(log_list)
73
+ def self.show(raw = {})
74
+ # Extract Args
75
+ files_list, flags, _args = Args.parse(raw)
62
76
 
63
- logs.map!(&:data)
77
+ # Collect Files
78
+ files = ShellHelper.files(files_list, Thing.all, flags)
64
79
 
65
- ShellHelper.show logs.flatten
80
+ ShellHelper.show files.map(&:data).flatten
66
81
  end
67
82
 
68
83
  # ========================================================================
69
- # Filter
84
+ # Filter (See Filter Help)
70
85
  # ========================================================================
71
- # Supported Params
72
- # --or (Filter OR instead of AND)
73
- # --total Total Count Entries Only
74
- # --project=thingy --exclude_this!=asdf *
75
- # --slice: only grab specific fields --slice=path (slice multiple with comma)
76
- # --slice=time,path (E.g. log filter --path='mirror/pull' --slice=path,time )
77
- # --except: Exclude specific fields (except multiple with comma)
78
- # Example: log filter --path='mirror/pull' --except=params
79
86
  def self.default(raw_list)
80
87
  filter(raw_list)
81
88
  end
82
89
 
83
- def self.filter(raw_list)
90
+ def self.filter(raw)
84
91
  # Print Helper
85
- if raw_list == ['help']
92
+ if raw == ['help']
86
93
  filter_help
87
94
  return true
88
95
  end
89
96
 
90
- # Extract Args
91
- log_list, opts, args = ShellHelper.param_parse(raw_list)
97
+ # Argument Parsing
98
+ files, flags, args = Args.parse(raw)
92
99
 
93
100
  # Prepare Log List
94
- log_list = ShellHelper.prepare_list(log_list)
101
+ files = ShellHelper.prepare_list(files, ShellHelper::Log.list, flags)
95
102
 
96
- # AND / OR Filtering
97
- filter_type = args.or ? :any? : :all?
103
+ results = ShellHelper.filter_start(files, flags, args)
98
104
 
99
- results = ShellHelper.filter_start(log_list, filter_type, args, opts)
100
-
101
- # Skipo and Print Total if set
102
- if args.total
105
+ # Skip and Print Total if set
106
+ if flags[:total]
103
107
  ShellHelper.total_count(results)
104
108
  return true
105
109
  end
106
110
 
111
+ # Skip and Print Total if set
112
+ if flags[:fields]
113
+ ShellHelper.fields_print(results)
114
+ return true
115
+ end
116
+
107
117
  # Check Search Results
108
118
  if results.instance_of?(Hash) && results.values.flatten.empty?
109
- puts 'No results'.colorize(:red)
119
+ puts 'No results'.pastel(:red)
110
120
  else
111
121
  # This causes the key 'colorized' output to also be included
112
- ShellHelper.show(results.to_a.compact.flatten, args)
122
+ ShellHelper.show(results.to_a.compact.flatten, flags)
113
123
  end
114
124
 
115
125
  # log filter --path='cloud/gitlab-automation' --path='/pull' --all
116
126
  # log filter --project=thingy --other_filter=asdf *
117
127
  rescue StandardError => e
118
- LogBot.fatal('Filter', message: e.message, backtrace: e.backtrace.first)
128
+ LogBot.fatal('Filter', message: e.message)
129
+ ap e.backtrace
119
130
  end
120
131
  # ========================================================================
121
132
 
122
133
  # rubocop:disable Layout/LineLength
123
134
  # TODO: Add a lot more examples
124
135
  def self.examples
125
- puts 'Find `done` job for sidekiq, sort by duration, only duration, and show longest first'.colorize(:light_green)
136
+ puts 'Find `done` job for sidekiq, sort by duration, only duration, and show longest first'.pastel(:bright_green)
126
137
  puts 'log filter sidekiq/current --job_status=done --sort=duration_s,db_duration_s --slice=duration_s,db_duration_s --reverse'
127
138
  puts
128
- puts 'Find 500s only show exceptions'.colorize(:light_green)
139
+
140
+ puts 'Find 500s only show exceptions'.pastel(:bright_green)
129
141
  puts 'log filter --status=500 --slice=exception.message gitlab-rails/production_json.log'
130
142
  puts
143
+
144
+ puts 'Show unique sidekiq queue namespaces. Exclude Specifics'.pastel(:bright_green)
145
+ puts 'filter sidekiq/current --slice=queue_namespace --uniq=queue_namespace --queue_namespace!=jira_connect --queue_namespace!=hashed_storage'
146
+ puts
147
+
148
+ puts 'Show user,ip from API logs where `meta.user` field is present '.pastel(:bright_green)
149
+ puts 'gitlab-rails/api_json.log --slice=meta.user,meta.remote_ip --exists=meta.user'
150
+ puts
151
+
152
+ puts 'Count/% occurences for both user and remote ip fields'.pastel(:bright_green)
153
+ puts 'gitlab-rails/api_json.log --stats=meta.user,meta.remote_ip --exists=meta.user'
154
+ puts
131
155
  end
132
156
 
133
157
  # rubocop:enable Layout/LineLength
134
158
  # ========================================================================
135
159
  # Search (Full Text / String Search)
136
160
  # ========================================================================
137
- # Supported Params
138
- # --text='asdf'
139
- # --text!='asdf'
140
- # --regex='' # TODO?
141
- # --slice=time,path (E.g. log filter --path='mirror/pull' --slice=path,time )
142
- # --except: Exclude specific fields (except multiple with comma)
143
-
144
- # --total Total Count Entries Only
145
- def self.search(initial_param)
161
+ def self.search(raw)
146
162
  # Extract Args
147
- log_list, opts, args = ShellHelper.param_parse(initial_param)
163
+ files_list, flags, args = Args.parse(raw)
148
164
 
149
165
  # Prepare Log List
150
- log_list = ShellHelper.prepare_list(log_list)
151
-
152
- # AND / OR Filtering
153
- filter_type = args.or ? :any? : :all?
166
+ files = ShellHelper.prepare_list(files_list)
154
167
 
155
- results = ShellHelper.search_start(log_list, filter_type, args, opts)
168
+ results = ShellHelper.search_start(files, flags, args)
156
169
 
157
- # Skipo and Print Total if set
158
- if args.total
170
+ # Skip and Print Total if set
171
+ if flags[:total]
159
172
  ShellHelper.total_count(results)
160
173
  return true
161
174
  end
162
175
 
163
176
  # Check Search Results
164
177
  if results.values.flatten.empty?
165
- puts 'No results'.colorize(:red)
178
+ puts 'No results'.pastel(:red)
166
179
  else
167
180
  # This causes the key 'colorized' output to also be included
168
- ShellHelper.show(results.to_a.compact.flatten, args)
181
+ ShellHelper.show(results.to_a.compact.flatten, flags)
169
182
  end
170
183
  rescue StandardError => e
171
- LogBot.fatal('Filter', message: e.message, backtrace: e.backtrace.first)
184
+ LogBot.fatal('Search', message: e.message)
185
+ ap e.backtrace
172
186
  end
173
187
  # ========================================================================
174
188
 
@@ -180,48 +194,48 @@ module GreenHat
180
194
 
181
195
  # rubocop:disable Metrics/MethodLength
182
196
  def self.search_help
183
- puts "\u2500".colorize(:cyan) * 20
184
- puts 'Log Search'.colorize(:yellow)
185
- puts "\u2500".colorize(:cyan) * 20
197
+ puts "\u2500".pastel(:cyan) * 20
198
+ puts 'Log Search'.pastel(:yellow)
199
+ puts "\u2500".pastel(:cyan) * 20
186
200
 
187
201
  puts 'Search will do a full line include or exclude text search'
188
202
 
189
- puts 'Options'.colorize(:blue)
190
- puts '--text'.colorize(:green)
203
+ puts 'Options'.pastel(:blue)
204
+ puts '--text'.pastel(:green)
191
205
  puts ' Primary parameter for searching. Include or ! to exclude'
192
206
  puts ' Ex: --text=BuildHooksWorker --text!=start sidekiq/current'
193
207
  puts
194
208
 
195
- puts '--total'.colorize(:green)
209
+ puts '--total'.pastel(:green)
196
210
  puts ' Print only total count of matching entries'
197
211
  puts
198
212
 
199
- puts '--slice'.colorize(:green)
213
+ puts '--slice'.pastel(:green)
200
214
  puts ' Extract specific fields from entries (slice multiple with comma)'
201
215
  puts ' Ex: --slice=path or --slice=path,params'
202
216
  puts
203
217
 
204
- puts '--except'.colorize(:green)
218
+ puts '--except'.pastel(:green)
205
219
  puts ' Exclude specific fields (except multiple with comma)'
206
220
  puts ' Ex: --except=params --except=params,path'
207
221
  puts
208
222
 
209
- puts '--archive'.colorize(:green)
210
- puts ' Limit to specific archvie name (inclusive). Matching SOS tar.gz name'
223
+ puts '--archive'.pastel(:green)
224
+ puts ' Limit to specific archive name (inclusive). Matching SOS tar.gz name'
211
225
  puts ' Ex: --archive=dev-gitlab_20210622154626, --archive=202106,202107'
212
226
  puts
213
227
 
214
- puts '--limit'.colorize(:green)
228
+ puts '--limit'.pastel(:green)
215
229
  puts ' Limit total number of results. Default to half total screen size'
216
230
  puts ' Ex: --limit; --limit=10'
217
231
  puts
218
232
 
219
- puts 'Search specific logs'.colorize(:blue)
233
+ puts 'Search specific logs'.pastel(:blue)
220
234
  puts ' Any non dash parameters will be the log list to search from'
221
- puts " Ex: log filter --path=api sidekiq/current (hint: use `#{'ls'.colorize(:yellow)}` for log names)"
235
+ puts " Ex: log filter --path=api sidekiq/current (hint: use `#{'ls'.pastel(:yellow)}` for log names)"
222
236
  puts
223
237
 
224
- puts 'Example Queries'.colorize(:blue)
238
+ puts 'Example Queries'.pastel(:blue)
225
239
  puts 'log search --text=BuildHooksWorker --text!=start sidekiq/current --total'
226
240
  puts 'log search --text=BuildHooksWorker --text!=start --slice=enqueued_at sidekiq/current'
227
241
  puts
@@ -3,14 +3,18 @@ module GreenHat
3
3
  # Helper to organize page check / methods
4
4
  module Page
5
5
  # Check if paging should be skipped
6
- def self.skip?(args, data)
7
- return count_rows(data) unless args[:page]
6
+ # True / False / Not Set
7
+ def self.skip?(flags, data)
8
+ # Pass if Explicitly Set / Inverse for skip
9
+ return !flags[:page] if flags.key? :page
8
10
 
9
- args[:page].first == :false
11
+ LogBot.debug('Page', count_rows(data, flags)) if ENV['DEBUG']
12
+
13
+ count_rows(data, flags)
10
14
  end
11
15
 
12
16
  # Array/Hash and String pagination check. Don't unncessarily loop through everything
13
- def self.count_rows(data)
17
+ def self.count_rows(data, flags)
14
18
  height = TTY::Screen.height
15
19
  size = 0
16
20
 
@@ -19,7 +23,9 @@ module GreenHat
19
23
  when Hash then entry.keys.count
20
24
  when Array then entry.count
21
25
  else
22
- 1
26
+ # Each Boxed Entry is 3 Lines
27
+ flags.key?(:row_size) ? flags[:row_size] : 1
28
+
23
29
  end
24
30
 
25
31
  break if size > height
@@ -11,16 +11,22 @@ module GreenHat
11
11
  end
12
12
 
13
13
  def self.help
14
- puts "\u2500".colorize(:cyan) * 20
15
- puts "#{'Process'.colorize(:yellow)} - ps helper"
16
- puts "\u2500".colorize(:cyan) * 20
14
+ puts "\u2500".pastel(:cyan) * 22
15
+ puts "#{'Process'.pastel(:yellow)} - ps helper"
16
+ puts "\u2500".pastel(:cyan) * 22
17
17
 
18
- puts 'Command Summary'.colorize(:blue)
19
- puts ' ps'.colorize(:green)
18
+ ShellHelper.common_opts
19
+
20
+ puts 'Command Summary'.pastel(:blue)
21
+ puts ' ps'.pastel(:green)
20
22
  puts ' Raw `ps`'
21
- puts ' filter'.colorize(:green)
22
- puts ' Key/Field Filtering'
23
- puts ' - See `filter_help`'
23
+ puts
24
+ puts ' filter'.pastel(:green)
25
+ puts " Key/Field Filtering. See #{'filter_help'.pastel(:blue)}"
26
+ puts ' Examples'
27
+ puts ' filter --sort=mem --reverse'.pastel(:green)
28
+ puts ' filter --user=gitlab'.pastel(:green)
29
+
24
30
  puts
25
31
  end
26
32
 
@@ -29,25 +35,31 @@ module GreenHat
29
35
  end
30
36
 
31
37
  def self.ps(raw = {})
32
- _log_list, _1opts, args = ShellHelper.param_parse(raw)
33
- ShellHelper.file_output GreenHat::Ps.ps(args)
38
+ # Extract Args
39
+ files_list, flags, _args = Args.parse(raw)
40
+
41
+ # Collect Files
42
+ files = ShellHelper.files(files_list, GreenHat::Ps.things, flags)
43
+
44
+ # Output
45
+ ShellHelper.file_output(files, flags)
34
46
  end
35
47
 
36
48
  def self.filter(raw = {})
37
- _log_list, opts, args = ShellHelper.param_parse(raw)
49
+ # Argument Parsing
50
+ files, flags, args = Args.parse(raw)
38
51
 
39
- # AND / OR Filtering
40
- filter_type = args.or ? :any? : :all?
52
+ # Prepare Log List
53
+ file_list = ShellHelper.prepare_list(files, GreenHat::Ps.things)
41
54
 
42
- # ShellHelper.file_output
43
- results = ShellHelper.filter_start(GreenHat::Ps.ps(args).map(&:name), filter_type, args, opts)
55
+ results = ShellHelper.filter_start(file_list, flags, args)
44
56
 
45
57
  # Check Search Results
46
58
  if results.instance_of?(Hash) && results.values.flatten.empty?
47
- puts 'No results'.colorize(:red)
59
+ puts 'No results'.pastel(:red)
48
60
  else
49
61
  # This causes the key 'colorized' output to also be included
50
- ShellHelper.show(results.to_a.compact.flatten, args)
62
+ ShellHelper.show(results.to_a.compact.flatten, flags)
51
63
  end
52
64
  end
53
65
  end
@@ -2,11 +2,17 @@ module GreenHat
2
2
  # Root Level Shell / Report Helper
3
3
  module Shell
4
4
  def self.report(raw)
5
- args = {
6
- raw: raw.include?('--raw')
7
- }
5
+ _files, flags, _args = Args.parse(raw)
8
6
 
9
- ShellHelper.show(Archive.all.map(&:report).map(&:show).flatten, args)
7
+ archives = if flags.archive
8
+ Archive.all.select do |archive|
9
+ flags.archive.any? { |x| archive.name.include? x.to_s }
10
+ end
11
+ else
12
+ Archive.all
13
+ end
14
+
15
+ ShellHelper.show(archives.map(&:report).map(&:show).flatten, flags)
10
16
  end
11
17
  end
12
18
  end
@@ -45,11 +51,11 @@ module GreenHat
45
51
 
46
52
  def show
47
53
  output = [
48
- archive.friendly_name.colorize(:blue)
54
+ archive.friendly_name.pastel(:blue)
49
55
  ]
50
56
 
51
57
  # OS
52
- output << 'OS'.colorize(:light_yellow)
58
+ output << 'OS'.pastel(:bright_yellow)
53
59
  output << hostname if host
54
60
  output << distro if os_release
55
61
  output << selinux if selinux_status
@@ -62,7 +68,7 @@ module GreenHat
62
68
 
63
69
  # Memory
64
70
  if meminfo || free_m
65
- output << 'Memory'.colorize(:light_yellow)
71
+ output << 'Memory'.pastel(:bright_yellow)
66
72
  output << memory_perc if meminfo
67
73
  output << memory_free if free_m
68
74
  output << ''
@@ -75,7 +81,7 @@ module GreenHat
75
81
  end
76
82
 
77
83
  # Gitlab
78
- output << 'GitLab'.colorize(:light_yellow) if gitlab_manifest
84
+ output << 'GitLab'.pastel(:bright_yellow) if gitlab_manifest
79
85
  output << gitlab_version if gitlab_manifest
80
86
  output << gitlab_services if gitlab_status
81
87
  output << title('Errors') if production_log || api_log || application_log || sidekiq_log
@@ -95,8 +101,8 @@ module GreenHat
95
101
  color = count.zero? ? :green : :red
96
102
 
97
103
  [
98
- title(' Production', :light_red, 18),
99
- count.to_s.colorize(color)
104
+ title(' Production', :bright_red, 18),
105
+ count.to_s.pastel(color)
100
106
  ].join
101
107
  end
102
108
 
@@ -105,8 +111,8 @@ module GreenHat
105
111
  color = count.zero? ? :green : :red
106
112
 
107
113
  [
108
- title(' API', :light_red, 18),
109
- count.to_s.colorize(color)
114
+ title(' API', :bright_red, 18),
115
+ count.to_s.pastel(color)
110
116
  ].join
111
117
  end
112
118
 
@@ -115,8 +121,8 @@ module GreenHat
115
121
  color = count.zero? ? :green : :red
116
122
 
117
123
  [
118
- title(' Application', :light_red, 18),
119
- count.to_s.colorize(color)
124
+ title(' Application', :bright_red, 18),
125
+ count.to_s.pastel(color)
120
126
  ].join
121
127
  end
122
128
 
@@ -125,32 +131,16 @@ module GreenHat
125
131
  color = count.zero? ? :green : :red
126
132
 
127
133
  [
128
- title(' Sidekiq', :light_red, 18),
129
- count.to_s.colorize(color)
134
+ title(' Sidekiq', :bright_red, 18),
135
+ count.to_s.pastel(color)
130
136
  ].join
131
137
  end
132
138
 
133
139
  def gitlab_services
134
- list = gitlab_status.data.keys.sort.map do |service|
135
- color = gitlab_status.data.dig(service, 0, :status) == 'run' ? :green : :red
136
- service.colorize(color)
137
- end
138
-
139
- # Keep Alphabetical Sort
140
- groups = list.each_slice((list.size / 3.to_f).round).to_a
141
-
142
- table = TTY::Table.new do |t|
143
- loop do
144
- break if groups.all?(&:empty?)
145
-
146
- t << groups.map(&:shift)
147
- end
148
- end
149
-
150
140
  [
151
141
  title('Services'),
152
142
  "\n ",
153
- table.render(:unicode, padding: [0, 1, 0, 1], indent: 3)
143
+ GitLab.services(archive, 3)
154
144
  ].join
155
145
  rescue StandardError => e
156
146
  LogBot.fatal('GitLab Services', message: e.message, backtrace: e.backtrace.first)
@@ -173,7 +163,7 @@ module GreenHat
173
163
  def distro
174
164
  [
175
165
  title('Distro'),
176
- "[#{os_release.data.ID}] ".colorize(:light_black),
166
+ "[#{os_release.data.ID}] ".pastel(:bright_black),
177
167
  os_release.data.PRETTY_NAME
178
168
  ].join
179
169
  end
@@ -184,7 +174,7 @@ module GreenHat
184
174
 
185
175
  [
186
176
  title('SeLinux'),
187
- status.colorize(status_color),
177
+ status.pastel(status_color),
188
178
  ' (',
189
179
  selinux_status.data['Current mode'],
190
180
  ')'
@@ -204,7 +194,7 @@ module GreenHat
204
194
  [
205
195
  title('Kernel'),
206
196
  value,
207
- " (#{build})".colorize(:light_black)
197
+ " (#{build})".pastel(:bright_black)
208
198
  ].join
209
199
  end
210
200
 
@@ -231,9 +221,9 @@ module GreenHat
231
221
  [
232
222
  title('Sys Time'),
233
223
  timedatectl.data['Local time'],
234
- ' (ntp: '.colorize(:light_black),
235
- ntp_status.colorize(ntp_color),
236
- ')'.colorize(:light_black)
224
+ ' (ntp: '.pastel(:bright_black),
225
+ ntp_status.pastel(ntp_color),
226
+ ')'.pastel(:bright_black)
237
227
  ].join
238
228
  end
239
229
 
@@ -258,14 +248,14 @@ module GreenHat
258
248
  [
259
249
  interval,
260
250
  ' (',
261
- "#{value}%".colorize(color),
251
+ "#{value}%".pastel(color),
262
252
  ')'
263
253
  ].join
264
254
  end
265
255
 
266
256
  [
267
257
  title('LoadAvg'),
268
- "[CPU #{cpu_count}] ".colorize(:light_white),
258
+ "[CPU #{cpu_count}] ".pastel(:bright_white),
269
259
  intervals_text.join(', ')
270
260
  ].join
271
261
  end
@@ -277,11 +267,11 @@ module GreenHat
277
267
 
278
268
  [
279
269
  title('Usage'),
280
- ' ['.colorize(:light_black),
281
- '='.colorize(:green) * (used / 2),
270
+ ' ['.pastel(:bright_black),
271
+ '='.pastel(:green) * (used / 2),
282
272
  ' ' * (50 - used / 2),
283
- ']'.colorize(:light_black),
284
- " #{100 - percent(free, total)}%".colorize(:green) # Inverse
273
+ ']'.pastel(:bright_black),
274
+ " #{100 - percent(free, total)}%".pastel(:green) # Inverse
285
275
  ].join
286
276
  end
287
277
 
@@ -317,7 +307,7 @@ module GreenHat
317
307
 
318
308
  # Preapre / Indent List
319
309
  [
320
- 'Disks(Top % Usage)'.colorize(:light_yellow),
310
+ 'Disks'.pastel(:bright_yellow) + ' (Top % Usage)'.pastel(:bright_black),
321
311
  "\n",
322
312
  disk_list.each { |x| x.prepend(' ' * 4) }.join("\n")
323
313
  ].join
@@ -332,7 +322,7 @@ module GreenHat
332
322
 
333
323
  # Helper to Make Cyan Titles
334
324
  def title(name, color = :cyan, ljust = 12)
335
- " #{name}:".ljust(ljust).colorize(color)
325
+ " #{name}:".ljust(ljust).pastel(color)
336
326
  end
337
327
  end
338
328
  # rubocop:enable Metrics/ClassLength