greenhat 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/greenhat/accessors/grep.rb +66 -0
- data/lib/greenhat/reports/reports/errors.rb +2 -1
- data/lib/greenhat/shell.rb +4 -0
- data/lib/greenhat/thing/file_types.rb +6 -0
- data/lib/greenhat/thing.rb +12 -1
- 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: 0f5d55f92471f7318f9b5ca12026a123dc709ec8ce36cc5d8f5a3646c7336958
|
4
|
+
data.tar.gz: ae8a8173fed36ac95653d000cb6953d2a677043b3b48080e39cfedcaba39c6ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e51373d6828cceeb0f0c80a04fe2c7fc7b02c7832c62b7702911f3a7e0ec4c772ec14ff0937917f5f529972ba1cc1df546052753cdf4660b336c453afac25e4
|
7
|
+
data.tar.gz: 13736483760fb9d6421ed615d02a38015c6dbd31665a60c6906479fe88454bc9fa7cfb144623cff669339392d75fdc76847d460a0495ebd88a2d74eceb2ae8e9
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module GreenHat
|
2
|
+
# Pretending to do grep stuffs
|
3
|
+
module Grep
|
4
|
+
def self.help
|
5
|
+
puts "\u2500".pastel(:cyan) * 20
|
6
|
+
puts "#{'Grep'.pastel(:yellow)} - gimme... GIMME!"
|
7
|
+
puts 'General text searching through all files (logs, parsed, and raw)'
|
8
|
+
puts "\u2500".pastel(:cyan) * 20
|
9
|
+
|
10
|
+
puts 'Usage'.pastel(:blue)
|
11
|
+
puts ' <search term> <optional: files>'.pastel(:green)
|
12
|
+
puts ' Examples:'
|
13
|
+
puts ' grep external_url'
|
14
|
+
puts ' grep external_url gitlab.rb'
|
15
|
+
puts ' grep "spaced terms"'
|
16
|
+
puts ' grep "System clock" timedatectl'
|
17
|
+
puts ' grep "search in two files" nfsiostat nfsstat'
|
18
|
+
puts
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.grep(raw)
|
22
|
+
files, flags, _args = Args.parse(raw)
|
23
|
+
|
24
|
+
if flags.help
|
25
|
+
help
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
# Search Term
|
30
|
+
term = files.shift
|
31
|
+
|
32
|
+
things = find_things(files)
|
33
|
+
|
34
|
+
# Renderer
|
35
|
+
output = []
|
36
|
+
things.each do |thing|
|
37
|
+
results = thing.grep(term)
|
38
|
+
|
39
|
+
next if results.empty?
|
40
|
+
|
41
|
+
output.push("#{thing.friendly_name} #{results.count.to_s.pastel(:bright_black)}")
|
42
|
+
output.concat results
|
43
|
+
output.push ''
|
44
|
+
end
|
45
|
+
|
46
|
+
# Output
|
47
|
+
if output.empty?
|
48
|
+
puts 'No results'.pastel(:red)
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
52
|
+
ShellHelper.show GreenHat::Paper.new(data: output, flags: flags).render
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.find_things(files = [])
|
56
|
+
if files.empty?
|
57
|
+
Thing.all
|
58
|
+
else
|
59
|
+
Thing.all.select { |x| files.any? { |f| x.name.include? f } }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# ------------------
|
64
|
+
end
|
65
|
+
# ------------------
|
66
|
+
end
|
@@ -24,7 +24,8 @@ entries = [
|
|
24
24
|
{ header: 'Sidekiq', base: 'sidekiq/current --severity=error', stats: 'message' },
|
25
25
|
{ header: 'API', base: 'gitlab-rails/api_json.log --severity=error',
|
26
26
|
stats: 'exception.class,exception.message,status' },
|
27
|
-
{ header: 'Gitaly', base: 'gitaly/current --level=error --truncate=99', stats: 'error' }
|
27
|
+
{ header: 'Gitaly', base: 'gitaly/current --level=error --truncate=99', stats: 'error' },
|
28
|
+
{ header: 'Praefect', base: 'praefect/current --level=error --truncate=99', stats: 'error' }
|
28
29
|
]
|
29
30
|
|
30
31
|
# Filter Logic
|
data/lib/greenhat/shell.rb
CHANGED
data/lib/greenhat/thing.rb
CHANGED
@@ -42,6 +42,17 @@ class Thing < Teron
|
|
42
42
|
save!
|
43
43
|
end
|
44
44
|
|
45
|
+
# Helper to make it easier to query through hashed / parsed objects
|
46
|
+
def hash_to_a_query
|
47
|
+
data.to_a.map { |x| x.join(': ') }
|
48
|
+
end
|
49
|
+
|
50
|
+
def grep(term)
|
51
|
+
selectable = query? ? data : hash_to_a_query
|
52
|
+
|
53
|
+
selectable.select { |r| r.to_s.include?(term) }
|
54
|
+
end
|
55
|
+
|
45
56
|
# Processor
|
46
57
|
def data
|
47
58
|
process unless parsed
|
@@ -91,7 +102,7 @@ class Thing < Teron
|
|
91
102
|
|
92
103
|
# Things that can be queried (Query Helper)
|
93
104
|
def query?
|
94
|
-
data.instance_of?(Array)
|
105
|
+
data.instance_of?(Array) || data.instance_of?(Enumerator)
|
95
106
|
end
|
96
107
|
|
97
108
|
# Helper for all things that can be hash/value filtered
|
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.6.
|
4
|
+
version: 0.6.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: 2022-08-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -471,6 +471,7 @@ files:
|
|
471
471
|
- lib/greenhat.rb
|
472
472
|
- lib/greenhat/accessors/disk.rb
|
473
473
|
- lib/greenhat/accessors/gitlab.rb
|
474
|
+
- lib/greenhat/accessors/grep.rb
|
474
475
|
- lib/greenhat/accessors/logs/production.rb
|
475
476
|
- lib/greenhat/accessors/logs/sidekiq.rb
|
476
477
|
- lib/greenhat/accessors/memory.rb
|