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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bdaa3adc8b035c2b528472f1176e8104e75e369c0191926f2277a69170759b5
4
- data.tar.gz: 9d5d1811e7efe201a93a2385ec08bb5f280adbf0e00b3e02dc70eab4d6fafe47
3
+ metadata.gz: 0f5d55f92471f7318f9b5ca12026a123dc709ec8ce36cc5d8f5a3646c7336958
4
+ data.tar.gz: ae8a8173fed36ac95653d000cb6953d2a677043b3b48080e39cfedcaba39c6ba
5
5
  SHA512:
6
- metadata.gz: 4bd0b3e175659ff78f984dea7cae51fcd3b5cce01171db9a74e6e77c0c3fd2b5bad48a2e52a8a0941674ed39858893a8035fe7f2582279752d07f25c0db06821
7
- data.tar.gz: 35a342acfbea1e1dbcd70285f458cbed15822668fc06ae77a05ef8658667768be25560a1676bd3536bb2a80945bb9ea87d5b179aefc81c049ba4d951617b6f4f
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
@@ -24,6 +24,10 @@ module GreenHat
24
24
  Log.default(raw_list)
25
25
  end
26
26
 
27
+ def self.grep(raw_list = [])
28
+ Grep.grep(raw_list)
29
+ end
30
+
27
31
  def self.df
28
32
  Disk.df
29
33
  end
@@ -18,6 +18,12 @@ module GreenHat
18
18
  module FileTypes
19
19
  def types
20
20
  {
21
+ 'gitlab_rb' => {
22
+ format: :raw,
23
+ pattern: [
24
+ %r{gitlab/gitlab.rb}
25
+ ]
26
+ },
21
27
  'cpuinfo' => {
22
28
  format: :raw,
23
29
  pattern: [
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GreenHat
2
- VERSION = '0.6.4'.freeze
2
+ VERSION = '0.6.5'.freeze
3
3
  end
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
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-19 00:00:00.000000000 Z
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