riemann-tools 1.4.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a03d7a3dbe3175c3c9e3ab9af1ff80cf37affafed4af3f8b8c84dd11a91b2d9
4
- data.tar.gz: e789e77e2ceaac35acc00fc3d4136497d3410056d22d4ea1f5c0ab884b05f967
3
+ metadata.gz: ce2307f0dfeaad07e9b904c5f0edf2b0d7a586507c94e8ffb2ff9e3ccf6b3c6f
4
+ data.tar.gz: 8178becee10569b018dfdb54693cfa9e5c5a61dfe62ecdec7ca257004e2365ff
5
5
  SHA512:
6
- metadata.gz: 599e8b4b8923501cad11bce865c3ba9aa6420411d9e515fcd33b349308c3f8ee6200d8db648ad0a8ce1b701fe88e1858dae26a800fb599f5297c7a5175e58f5b
7
- data.tar.gz: a34dbd525e45f4c71ad3fec639f81d339848034aeede60efa6de5081e28d1afd6bc18ceb39d67c4dd223d04a2dba006cc74ddc6f288ce612ea16d454577d6e1c
6
+ metadata.gz: 7588c24abd5c87eb95ced867cc23350697ef893463e939a47c481518209a386c2b0a56e93e9d470e2fe1d9d0a78fa01d5b8d0e3f6af265d014072a00cf44570d
7
+ data.tar.gz: 54bd9df700e67ee112e856e6104018bac1ad54444533186cdd2425416fa2ab9a0939c5bfd7de5446045d4813c9a8fac5e34db9d997ea841c9665ae97f7224b95
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.5.0](https://github.com/riemann/riemann-tools/tree/v1.5.0) (2022-09-08)
4
+
5
+ [Full Changelog](https://github.com/riemann/riemann-tools/compare/v1.4.0...v1.5.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Improve error reporting on parse error [\#242](https://github.com/riemann/riemann-tools/pull/242) ([smortex](https://github.com/smortex))
10
+
11
+ **Fixed bugs:**
12
+
13
+ - Fix `riemann-haproxy` HTTP response processing [\#243](https://github.com/riemann/riemann-tools/pull/243) ([ahoetker-deca](https://github.com/ahoetker-deca))
14
+ - Fix `riemann-md` parsing of mdstat when device is being checked [\#241](https://github.com/riemann/riemann-tools/pull/241) ([smortex](https://github.com/smortex))
15
+
3
16
  ## [v1.4.0](https://github.com/riemann/riemann-tools/tree/v1.4.0) (2022-08-30)
4
17
 
5
18
  [Full Changelog](https://github.com/riemann/riemann-tools/compare/v1.3.0...v1.4.0)
@@ -44,7 +44,7 @@ module Riemann
44
44
  def csv
45
45
  http = ::Net::HTTP.new(@uri.host, @uri.port)
46
46
  http.use_ssl = true if @uri.scheme == 'https'
47
- http.start do |h|
47
+ res = http.start do |h|
48
48
  get = ::Net::HTTP::Get.new(@uri.request_uri)
49
49
  unless @uri.userinfo.nil?
50
50
  userinfo = @uri.userinfo.split(':')
@@ -52,7 +52,7 @@ module Riemann
52
52
  end
53
53
  h.request get
54
54
  end
55
- CSV.parse(http.body.split('# ')[1], { headers: true })
55
+ CSV.parse(res.body.split('# ')[1], { headers: true })
56
56
  end
57
57
  end
58
58
  end
@@ -103,6 +103,8 @@ module Riemann
103
103
  @swap_enabled = true
104
104
  end
105
105
  end
106
+
107
+ invalidate_cache
106
108
  end
107
109
 
108
110
  def alert(service, state, metric, description)
@@ -139,6 +141,8 @@ module Riemann
139
141
  end
140
142
 
141
143
  def report_uptime(uptime)
144
+ return unless uptime
145
+
142
146
  description = uptime_to_human(uptime)
143
147
 
144
148
  if uptime < @limits[:uptime][:critical]
@@ -262,6 +266,13 @@ module Riemann
262
266
 
263
267
  def uptime
264
268
  @cached_data[:uptime] ||= uptime_parser.parse(`uptime`)
269
+ rescue Racc::ParseError => e
270
+ report(
271
+ service: 'uptime',
272
+ description: "Error parsing uptime: #{e.message}",
273
+ state: 'critical',
274
+ )
275
+ @cached_data[:uptime] = {}
265
276
  end
266
277
 
267
278
  def bsd_load
@@ -23,6 +23,12 @@ module Riemann
23
23
  description: status,
24
24
  state: state,
25
25
  )
26
+ rescue Racc::ParseError => e
27
+ report(
28
+ service: 'mdstat',
29
+ description: "Error parsing mdstat: #{e.message}",
30
+ state: 'critical',
31
+ )
26
32
  rescue Errno::ENOENT => e
27
33
  report(
28
34
  service: 'mdstat',
@@ -9,155 +9,171 @@ require 'racc/parser.rb'
9
9
 
10
10
  require 'strscan'
11
11
 
12
+ require 'riemann/tools/utils'
13
+
12
14
  module Riemann
13
15
  module Tools
14
16
  class MdstatParser < Racc::Parser
15
17
 
16
- module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 42)
18
+ module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 49)
17
19
 
18
20
  def parse(text)
19
- s = StringScanner.new(text)
20
- @tokens = []
21
+ s = Utils::StringTokenizer.new(text)
21
22
 
22
23
  until s.eos? do
23
24
  case
24
- when s.scan(/\n/) then # ignore
25
- when s.scan(/\s+/) then # ignore
26
-
27
- when s.scan(/\[=*>.*\]/) then @tokens << [:PROGRESS, s.matched]
28
- when s.scan(/%/) then @tokens << ['%', s.matched]
29
- when s.scan(/,/) then @tokens << [',', s.matched]
30
- when s.scan(/:/) then @tokens << [':', s.matched]
31
- when s.scan(/</) then @tokens << ['<', s.matched]
32
- when s.scan(/=/) then @tokens << ['=', s.matched]
33
- when s.scan(/>/) then @tokens << ['>', s.matched]
34
- when s.scan(/\(/) then @tokens << ['(', s.matched]
35
- when s.scan(/\)/) then @tokens << [')', s.matched]
36
- when s.scan(/\./) then @tokens << ['.', s.matched]
37
- when s.scan(/\//) then @tokens << ['/', s.matched]
38
- when s.scan(/\[/) then @tokens << ['[', s.matched]
39
- when s.scan(/]/) then @tokens << [']', s.matched]
40
- when s.scan(/algorithm/) then @tokens << [:ALGORITHM, s.matched]
41
- when s.scan(/bitmap/) then @tokens << [:BITMAP, s.matched]
42
- when s.scan(/blocks/) then @tokens << [:BLOCKS, s.matched]
43
- when s.scan(/chunk/) then @tokens << [:CHUNK, s.matched]
44
- when s.scan(/finish/) then @tokens << [:FINISH, s.matched]
45
- when s.scan(/level/) then @tokens << [:LEVEL, s.matched]
46
- when s.scan(/min/) then @tokens << [:MIN, s.matched]
47
- when s.scan(/pages/) then @tokens << [:PAGES, s.matched]
48
- when s.scan(/(raid([014-6]|10)|linear|multipath|faulty)\b/) then @tokens << [:PERSONALITY, s.matched]
49
- when s.scan(/Personalities/) then @tokens << [:PERSONALITIES, s.matched]
50
- when s.scan(/recovery/) then @tokens << [:RECOVERY, s.matched]
51
- when s.scan(/speed/) then @tokens << [:SPEED, s.matched]
52
- when s.scan(/super/) then @tokens << [:SUPER, s.matched]
53
- when s.scan(/unused devices/) then @tokens << [:UNUSED_DEVICES, s.matched]
54
- when s.scan(/K\/sec/) then @tokens << [:SPEED_UNIT, s.matched.to_i]
55
- when s.scan(/KB/) then @tokens << [:BYTE_UNIT, s.matched.to_i]
56
- when s.scan(/k/) then @tokens << [:UNIT, s.matched.to_i]
57
- when s.scan(/\d+\.\d+/) then @tokens << [:FLOAT, s.matched.to_i]
58
- when s.scan(/\d+/) then @tokens << [:INTEGER, s.matched.to_i]
59
- when s.scan(/F\b/) then @tokens << [:FAILED, s.matched.to_i]
60
- when s.scan(/\w+/) then @tokens << [:IDENTIFIER, s.matched]
25
+ when s.scan(/\n/) then s.push_token(nil)
26
+ when s.scan(/\s+/) then s.push_token(nil)
27
+
28
+ when s.scan(/\[=*>.*\]/) then s.push_token(:PROGRESS)
29
+ when s.scan(/%/) then s.push_token('%')
30
+ when s.scan(/,/) then s.push_token(',')
31
+ when s.scan(/:/) then s.push_token(':')
32
+ when s.scan(/</) then s.push_token('<')
33
+ when s.scan(/=/) then s.push_token('=')
34
+ when s.scan(/>/) then s.push_token('>')
35
+ when s.scan(/\(/) then s.push_token('(')
36
+ when s.scan(/\)/) then s.push_token(')')
37
+ when s.scan(/\./) then s.push_token('.')
38
+ when s.scan(/\//) then s.push_token('/')
39
+ when s.scan(/\[/) then s.push_token('[')
40
+ when s.scan(/]/) then s.push_token(']')
41
+ when s.scan(/algorithm/) then s.push_token(:ALGORITHM)
42
+ when s.scan(/bitmap/) then s.push_token(:BITMAP)
43
+ when s.scan(/blocks/) then s.push_token(:BLOCKS)
44
+ when s.scan(/check/) then s.push_token(:CHECK)
45
+ when s.scan(/chunk/) then s.push_token(:CHUNK)
46
+ when s.scan(/finish/) then s.push_token(:FINISH)
47
+ when s.scan(/level/) then s.push_token(:LEVEL)
48
+ when s.scan(/min/) then s.push_token(:MIN)
49
+ when s.scan(/pages/) then s.push_token(:PAGES)
50
+ when s.scan(/(raid([014-6]|10)|linear|multipath|faulty)\b/) then s.push_token(:PERSONALITY)
51
+ when s.scan(/Personalities/) then s.push_token(:PERSONALITIES)
52
+ when s.scan(/recovery/) then s.push_token(:RECOVERY)
53
+ when s.scan(/reshape/) then s.push_token(:RESHAPE)
54
+ when s.scan(/resync/) then s.push_token(:RESYNC)
55
+ when s.scan(/speed/) then s.push_token(:SPEED)
56
+ when s.scan(/super/) then s.push_token(:SUPER)
57
+ when s.scan(/unused devices/) then s.push_token(:UNUSED_DEVICES)
58
+ when s.scan(/K\/sec/) then s.push_token(:SPEED_UNIT)
59
+ when s.scan(/KB/) then s.push_token(:BYTE_UNIT)
60
+ when s.scan(/k/) then s.push_token(:UNIT)
61
+ when s.scan(/\d+\.\d+/) then s.push_token(:FLOAT, s.matched.to_f)
62
+ when s.scan(/\d+/) then s.push_token(:INTEGER, s.matched.to_i)
63
+ when s.scan(/F\b/) then s.push_token(:FAILED)
64
+ when s.scan(/\w+/) then s.push_token(:IDENTIFIER)
61
65
  else
62
- raise s.rest
66
+ s.unexpected_token
63
67
  end
64
68
  end
65
69
 
70
+ @tokens = s.tokens
71
+
66
72
  do_parse
67
73
  end
68
74
 
69
75
  def next_token
70
76
  @tokens.shift
71
77
  end
78
+
79
+ def on_error(error_token_id, error_value, value_stack)
80
+ raise(Racc::ParseError, "parse error on value \"#{error_value[:value]}\" (#{token_to_str(error_token_id)}) on line #{error_value[:lineno]}:\n#{error_value[:line]}\n#{' ' * error_value[:pos]}^#{'~' * (error_value[:value].to_s.length - 1)}")
81
+ end
72
82
  ...end mdstat_parser.y/module_eval...
73
83
  ##### State transition tables begin ###
74
84
 
75
85
  racc_action_table = [
76
- 10, 13, 14, 10, 29, 3, 4, 6, 7, 15,
77
- 16, 17, 18, 11, 19, 20, 21, 22, 23, 24,
78
- 10, 27, 28, 31, 32, 33, 35, 37, 38, 39,
79
- 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
80
- 50, 51, 52, 53, 54, 56, 58, 59, 60, 61,
81
- 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
82
- 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
83
- 82, 83, 84, 85, 86, 87, 88 ]
86
+ 10, 13, 14, 60, 10, 29, 3, 4, 6, 7,
87
+ 15, 16, 17, 18, 19, 11, 61, 62, 63, 20,
88
+ 21, 22, 23, 24, 10, 27, 28, 31, 32, 33,
89
+ 35, 37, 38, 39, 40, 41, 42, 43, 44, 45,
90
+ 46, 47, 48, 49, 50, 51, 52, 53, 54, 56,
91
+ 58, 64, 65, 66, 67, 68, 69, 70, 71, 72,
92
+ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
93
+ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92 ]
84
94
 
85
95
  racc_action_check = [
86
- 5, 10, 10, 25, 25, 0, 1, 3, 4, 11,
87
- 12, 13, 14, 5, 15, 16, 17, 18, 19, 20,
88
- 21, 22, 23, 27, 29, 31, 32, 34, 35, 36,
89
- 37, 39, 40, 41, 42, 43, 44, 45, 46, 47,
90
- 48, 49, 50, 51, 52, 53, 55, 56, 58, 59,
91
- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
92
- 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
93
- 80, 81, 82, 84, 85, 86, 87 ]
96
+ 5, 10, 10, 56, 25, 25, 0, 1, 3, 4,
97
+ 11, 12, 13, 14, 15, 5, 56, 56, 56, 16,
98
+ 17, 18, 19, 20, 21, 22, 23, 27, 29, 31,
99
+ 32, 34, 35, 36, 37, 39, 40, 41, 42, 43,
100
+ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
101
+ 55, 58, 59, 64, 65, 66, 67, 68, 69, 70,
102
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
103
+ 81, 82, 83, 84, 85, 86, 87, 89, 90, 91 ]
94
104
 
95
105
  racc_action_pointer = [
96
- -10, 6, nil, -17, 8, -10, nil, nil, nil, nil,
97
- -23, -15, -15, 1, 1, -19, -1, 0, -9, 8,
98
- -7, 10, -7, -12, nil, -7, nil, 16, nil, 20,
99
- nil, -4, 5, nil, 15, 19, 4, 19, nil, 20,
100
- 2, 6, 23, 24, 14, 11, 32, 14, 10, 31,
101
- 40, 17, 33, 42, nil, 29, 23, nil, 30, 38,
102
- 19, 24, 43, 42, 22, 41, 28, 32, 47, 48,
103
- 33, 56, 51, 37, 35, 35, 58, 56, 37, 64,
104
- 61, 65, 59, nil, 54, 43, 64, 56, nil ]
106
+ -10, 7, nil, -19, 9, -11, nil, nil, nil, nil,
107
+ -26, -17, -17, 1, 1, -22, 2, 3, -8, 11,
108
+ -6, 13, -6, -11, nil, -7, nil, 19, nil, 24,
109
+ nil, -3, 6, nil, 18, 22, 5, 22, nil, 23,
110
+ 3, 7, 26, 27, 15, 12, 35, 15, 11, 34,
111
+ 44, 18, 36, 31, nil, 47, -3, nil, 24, 18,
112
+ nil, nil, nil, nil, 41, 44, 25, 21, 45, 27,
113
+ 44, 48, 33, 32, 51, 52, 60, 34, 38, 59,
114
+ 36, 36, 59, 62, 68, 60, 68, 54, nil, 43,
115
+ 66, 56, nil ]
105
116
 
106
117
  racc_action_default = [
107
- -21, -21, -6, -21, -21, -21, -4, 89, -1, -5,
108
- -21, -21, -2, -21, -21, -21, -21, -21, -21, -21,
109
- -21, -21, -11, -21, -3, -21, -9, -21, -20, -21,
110
- -8, -21, -13, -10, -15, -21, -21, -21, -12, -21,
111
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
112
- -21, -21, -21, -17, -14, -19, -21, -7, -21, -21,
113
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
114
- -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
115
- -21, -21, -21, -16, -21, -21, -21, -21, -18 ]
118
+ -25, -25, -6, -25, -25, -25, -4, 93, -1, -5,
119
+ -25, -25, -2, -25, -25, -25, -25, -25, -25, -25,
120
+ -25, -25, -11, -25, -3, -25, -9, -25, -24, -25,
121
+ -8, -25, -13, -10, -15, -25, -25, -25, -12, -25,
122
+ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
123
+ -25, -25, -25, -19, -14, -17, -25, -7, -25, -25,
124
+ -20, -21, -22, -23, -25, -25, -25, -25, -25, -25,
125
+ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
126
+ -25, -25, -25, -25, -25, -25, -25, -25, -16, -25,
127
+ -25, -25, -18 ]
116
128
 
117
129
  racc_goto_table = [
118
130
  9, 1, 2, 5, 8, 12, 25, 34, 36, 55,
119
- 57, nil, nil, nil, nil, nil, 26, nil, nil, nil,
131
+ 57, 59, nil, nil, nil, nil, 26, nil, nil, nil,
120
132
  30 ]
121
133
 
122
134
  racc_goto_check = [
123
135
  6, 1, 2, 3, 4, 5, 7, 8, 9, 10,
124
- 11, nil, nil, nil, nil, nil, 6, nil, nil, nil,
136
+ 11, 12, nil, nil, nil, nil, 6, nil, nil, nil,
125
137
  6 ]
126
138
 
127
139
  racc_goto_pointer = [
128
140
  nil, 1, 2, 1, -1, -1, -5, -15, -25, -26,
129
- -44, -45 ]
141
+ -44, -45, -45 ]
130
142
 
131
143
  racc_goto_default = [
132
144
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
133
- nil, nil ]
145
+ nil, nil, nil ]
134
146
 
135
147
  racc_reduce_table = [
136
148
  0, 0, :racc_error,
137
- 3, 36, :_reduce_1,
138
- 3, 37, :_reduce_none,
139
- 4, 40, :_reduce_none,
140
- 0, 40, :_reduce_none,
141
- 2, 38, :_reduce_5,
142
- 0, 38, :_reduce_6,
143
- 19, 41, :_reduce_7,
144
- 2, 42, :_reduce_none,
145
- 1, 42, :_reduce_none,
146
- 7, 41, :_reduce_none,
147
- 4, 41, :_reduce_none,
148
- 2, 43, :_reduce_none,
149
+ 3, 39, :_reduce_1,
150
+ 3, 40, :_reduce_none,
151
+ 4, 43, :_reduce_none,
149
152
  0, 43, :_reduce_none,
150
- 9, 44, :_reduce_none,
151
- 0, 44, :_reduce_none,
152
- 14, 45, :_reduce_none,
153
- 0, 45, :_reduce_none,
154
- 18, 46, :_reduce_none,
153
+ 2, 41, :_reduce_5,
154
+ 0, 41, :_reduce_6,
155
+ 19, 44, :_reduce_7,
156
+ 2, 45, :_reduce_none,
157
+ 1, 45, :_reduce_none,
158
+ 7, 44, :_reduce_none,
159
+ 4, 44, :_reduce_none,
160
+ 2, 46, :_reduce_none,
155
161
  0, 46, :_reduce_none,
156
- 5, 39, :_reduce_none ]
157
-
158
- racc_reduce_n = 21
159
-
160
- racc_shift_n = 89
162
+ 9, 47, :_reduce_none,
163
+ 0, 47, :_reduce_none,
164
+ 14, 49, :_reduce_none,
165
+ 0, 49, :_reduce_none,
166
+ 18, 48, :_reduce_none,
167
+ 0, 48, :_reduce_none,
168
+ 1, 50, :_reduce_none,
169
+ 1, 50, :_reduce_none,
170
+ 1, 50, :_reduce_none,
171
+ 1, 50, :_reduce_none,
172
+ 5, 42, :_reduce_none ]
173
+
174
+ racc_reduce_n = 25
175
+
176
+ racc_shift_n = 93
161
177
 
162
178
  racc_token_table = {
163
179
  false => 0,
@@ -166,37 +182,40 @@ racc_token_table = {
166
182
  :BITMAP => 3,
167
183
  :BLOCKS => 4,
168
184
  :BYTE_UNIT => 5,
169
- :CHUNK => 6,
170
- :FAILED => 7,
171
- :FINISH => 8,
172
- :FLOAT => 9,
173
- :IDENTIFIER => 10,
174
- :INTEGER => 11,
175
- :LEVEL => 12,
176
- :MIN => 13,
177
- :PAGES => 14,
178
- :PERSONALITIES => 15,
179
- :PERSONALITY => 16,
180
- :PROGRESS => 17,
181
- :RECOVERY => 18,
182
- :SPEED => 19,
183
- :SPEED_UNIT => 20,
184
- :SUPER => 21,
185
- :UNIT => 22,
186
- :UNUSED_DEVICES => 23,
187
- ":" => 24,
188
- "[" => 25,
189
- "]" => 26,
190
- "/" => 27,
191
- "(" => 28,
192
- ")" => 29,
193
- "," => 30,
194
- "=" => 31,
195
- "%" => 32,
196
- "<" => 33,
197
- ">" => 34 }
198
-
199
- racc_nt_base = 35
185
+ :CHECK => 6,
186
+ :CHUNK => 7,
187
+ :FAILED => 8,
188
+ :FINISH => 9,
189
+ :FLOAT => 10,
190
+ :IDENTIFIER => 11,
191
+ :INTEGER => 12,
192
+ :LEVEL => 13,
193
+ :MIN => 14,
194
+ :PAGES => 15,
195
+ :PERSONALITIES => 16,
196
+ :PERSONALITY => 17,
197
+ :PROGRESS => 18,
198
+ :RECOVERY => 19,
199
+ :RESHAPE => 20,
200
+ :RESYNC => 21,
201
+ :SPEED => 22,
202
+ :SPEED_UNIT => 23,
203
+ :SUPER => 24,
204
+ :UNIT => 25,
205
+ :UNUSED_DEVICES => 26,
206
+ ":" => 27,
207
+ "[" => 28,
208
+ "]" => 29,
209
+ "/" => 30,
210
+ "(" => 31,
211
+ ")" => 32,
212
+ "," => 33,
213
+ "=" => 34,
214
+ "%" => 35,
215
+ "<" => 36,
216
+ ">" => 37 }
217
+
218
+ racc_nt_base = 38
200
219
 
201
220
  racc_use_result_var = true
202
221
 
@@ -223,6 +242,7 @@ Racc_token_to_s_table = [
223
242
  "BITMAP",
224
243
  "BLOCKS",
225
244
  "BYTE_UNIT",
245
+ "CHECK",
226
246
  "CHUNK",
227
247
  "FAILED",
228
248
  "FINISH",
@@ -236,6 +256,8 @@ Racc_token_to_s_table = [
236
256
  "PERSONALITY",
237
257
  "PROGRESS",
238
258
  "RECOVERY",
259
+ "RESHAPE",
260
+ "RESYNC",
239
261
  "SPEED",
240
262
  "SPEED_UNIT",
241
263
  "SUPER",
@@ -262,8 +284,9 @@ Racc_token_to_s_table = [
262
284
  "list_of_devices",
263
285
  "super",
264
286
  "level",
287
+ "progress",
265
288
  "bitmap",
266
- "restore_progress" ]
289
+ "progress_action" ]
267
290
 
268
291
  Racc_debug_parser = false
269
292
 
@@ -300,7 +323,7 @@ module_eval(<<'.,.,', 'mdstat_parser.y', 11)
300
323
 
301
324
  module_eval(<<'.,.,', 'mdstat_parser.y', 13)
302
325
  def _reduce_7(val, _values, result)
303
- result = { val[0] => val[15] }
326
+ result = { val[0][:value] => val[15][:value] }
304
327
  result
305
328
  end
306
329
  .,.,
@@ -331,6 +354,14 @@ module_eval(<<'.,.,', 'mdstat_parser.y', 13)
331
354
 
332
355
  # reduce 20 omitted
333
356
 
357
+ # reduce 21 omitted
358
+
359
+ # reduce 22 omitted
360
+
361
+ # reduce 23 omitted
362
+
363
+ # reduce 24 omitted
364
+
334
365
  def _reduce_none(val, _values, result)
335
366
  val[0]
336
367
  end
@@ -9,45 +9,52 @@ require 'racc/parser.rb'
9
9
 
10
10
  require 'strscan'
11
11
 
12
+ require 'riemann/tools/utils'
13
+
12
14
  module Riemann
13
15
  module Tools
14
16
  class UptimeParser < Racc::Parser
15
17
 
16
- module_eval(<<'...end uptime_parser.y/module_eval...', 'uptime_parser.y', 43)
18
+ module_eval(<<'...end uptime_parser.y/module_eval...', 'uptime_parser.y', 45)
17
19
 
18
20
  def parse(text)
19
- s = StringScanner.new(text)
20
- @tokens = []
21
+ s = Utils::StringTokenizer.new(text)
21
22
 
22
23
  until s.eos? do
23
24
  case
24
- when s.scan(/\n/) then # ignore
25
- when s.scan(/\s+/) then # ignore
26
-
27
- when s.scan(/:/) then @tokens << [':', s.matched]
28
- when s.scan(/,/) then @tokens << [',', s.matched]
29
- when s.scan(/\d+[,.]\d+/) then @tokens << [:FLOAT, s.matched.sub(',', '.').to_f]
30
- when s.scan(/\d+/) then @tokens << [:INTEGER, s.matched.to_i]
31
- when s.scan(/AM/) then @tokens << [:AM, s.matched]
32
- when s.scan(/PM/) then @tokens << [:PM, s.matched]
33
- when s.scan(/up/) then @tokens << [:UP, s.matched]
34
- when s.scan(/days?/) then @tokens << [:DAYS, s.matched]
35
- when s.scan(/hrs?/) then @tokens << [:HRS, s.matched]
36
- when s.scan(/mins?/) then @tokens << [:MINS, s.matched]
37
- when s.scan(/secs?/) then @tokens << [:SECS, s.matched]
38
- when s.scan(/users?/) then @tokens << [:USERS, s.matched]
39
- when s.scan(/load averages?:/) then @tokens << [:LOAD_AVERAGES, s.matched]
25
+ when s.scan(/\n/) then s.push_token(nil)
26
+ when s.scan(/\s+/) then s.push_token(nil)
27
+
28
+ when s.scan(/:/) then s.push_token(':')
29
+ when s.scan(/,/) then s.push_token(',')
30
+ when s.scan(/\d+[,.]\d+/) then s.push_token(:FLOAT, s.matched.sub(',', '.').to_f)
31
+ when s.scan(/\d+/) then s.push_token(:INTEGER, s.matched.to_i)
32
+ when s.scan(/AM/) then s.push_token(:AM)
33
+ when s.scan(/PM/) then s.push_token(:PM)
34
+ when s.scan(/up/) then s.push_token(:UP)
35
+ when s.scan(/days?/) then s.push_token(:DAYS)
36
+ when s.scan(/hrs?/) then s.push_token(:HRS)
37
+ when s.scan(/mins?/) then s.push_token(:MINS)
38
+ when s.scan(/secs?/) then s.push_token(:SECS)
39
+ when s.scan(/users?/) then s.push_token(:USERS)
40
+ when s.scan(/load averages?:/) then s.push_token(:LOAD_AVERAGES)
40
41
  else
41
- raise s.rest
42
+ raise s.unexpected_token
42
43
  end
43
44
  end
44
45
 
46
+ @tokens = s.tokens
47
+
45
48
  do_parse
46
49
  end
47
50
 
48
51
  def next_token
49
52
  @tokens.shift
50
53
  end
54
+
55
+ def on_error(error_token_id, error_value, value_stack)
56
+ raise(Racc::ParseError, "parse error on value \"#{error_value[:value]}\" (#{token_to_str(error_token_id)}) on line #{error_value[:lineno]}:\n#{error_value[:line]}\n#{' ' * error_value[:pos]}^#{'~' * (error_value[:value].to_s.length - 1)}")
57
+ end
51
58
  ...end uptime_parser.y/module_eval...
52
59
  ##### State transition tables begin ###
53
60
 
@@ -113,7 +120,7 @@ racc_reduce_table = [
113
120
  2, 23, :_reduce_16,
114
121
  2, 24, :_reduce_17,
115
122
  2, 25, :_reduce_18,
116
- 2, 19, :_reduce_none,
123
+ 2, 19, :_reduce_19,
117
124
  4, 20, :_reduce_20,
118
125
  6, 20, :_reduce_21 ]
119
126
 
@@ -265,51 +272,56 @@ module_eval(<<'.,.,', 'uptime_parser.y', 18)
265
272
 
266
273
  module_eval(<<'.,.,', 'uptime_parser.y', 20)
267
274
  def _reduce_14(val, _values, result)
268
- result = val[0] * 86400
275
+ result = val[0][:value] * 86400
269
276
  result
270
277
  end
271
278
  .,.,
272
279
 
273
280
  module_eval(<<'.,.,', 'uptime_parser.y', 22)
274
281
  def _reduce_15(val, _values, result)
275
- result = val[0] * 3600 + val[2] * 60
282
+ result = val[0][:value] * 3600 + val[2][:value] * 60
276
283
  result
277
284
  end
278
285
  .,.,
279
286
 
280
287
  module_eval(<<'.,.,', 'uptime_parser.y', 24)
281
288
  def _reduce_16(val, _values, result)
282
- result = val[0] * 3600
289
+ result = val[0][:value] * 3600
283
290
  result
284
291
  end
285
292
  .,.,
286
293
 
287
294
  module_eval(<<'.,.,', 'uptime_parser.y', 26)
288
295
  def _reduce_17(val, _values, result)
289
- result = val[0] * 60
296
+ result = val[0][:value] * 60
290
297
  result
291
298
  end
292
299
  .,.,
293
300
 
294
301
  module_eval(<<'.,.,', 'uptime_parser.y', 28)
295
302
  def _reduce_18(val, _values, result)
296
- result = val[0]
303
+ result = val[0][:value]
297
304
  result
298
305
  end
299
306
  .,.,
300
307
 
301
- # reduce 19 omitted
308
+ module_eval(<<'.,.,', 'uptime_parser.y', 30)
309
+ def _reduce_19(val, _values, result)
310
+ result = val[0][:value]
311
+ result
312
+ end
313
+ .,.,
302
314
 
303
315
  module_eval(<<'.,.,', 'uptime_parser.y', 32)
304
316
  def _reduce_20(val, _values, result)
305
- result = { 1 => val[1], 5 => val[2], 15 => val[3] }
317
+ result = { 1 => val[1][:value], 5 => val[2][:value], 15 => val[3][:value] }
306
318
  result
307
319
  end
308
320
  .,.,
309
321
 
310
322
  module_eval(<<'.,.,', 'uptime_parser.y', 33)
311
323
  def _reduce_21(val, _values, result)
312
- result = { 1 => val[1], 5 => val[3], 15 => val[5] }
324
+ result = { 1 => val[1][:value], 5 => val[3][:value], 15 => val[5][:value] }
313
325
  result
314
326
  end
315
327
  .,.,
@@ -3,6 +3,54 @@
3
3
  module Riemann
4
4
  module Tools
5
5
  module Utils # :nodoc:
6
+ class StringTokenizer
7
+ attr_reader :tokens
8
+
9
+ def initialize(text)
10
+ @scanner = StringScanner.new(text)
11
+
12
+ @lineno = 1
13
+ @pos = 0
14
+ @line = next_line
15
+ @tokens = []
16
+ end
17
+
18
+ def scan(expression)
19
+ @scanner.scan(expression)
20
+ end
21
+
22
+ def eos?
23
+ @scanner.eos?
24
+ end
25
+
26
+ def matched
27
+ @scanner.matched
28
+ end
29
+
30
+ def next_line
31
+ (@scanner.check_until(/\n/) || @scanner.rest).chomp
32
+ end
33
+
34
+ def push_token(token, value = nil)
35
+ value ||= @scanner.matched
36
+
37
+ if value == "\n"
38
+ @lineno += 1
39
+ @line = next_line
40
+ @pos = pos = 0
41
+ else
42
+ pos = @pos
43
+ @pos += @scanner.matched.length
44
+ end
45
+
46
+ @tokens << [token, { value: value, line: @line, lineno: @lineno, pos: pos }] if token
47
+ end
48
+
49
+ def unexpected_token
50
+ raise(Racc::ParseError, "unexpected data on line #{@lineno}:\n#{@line}\n#{' ' * @pos}^")
51
+ end
52
+ end
53
+
6
54
  def reverse_numeric_sort_with_header(data, header: 1, count: 10)
7
55
  lines = data.chomp.split("\n")
8
56
  header = lines.shift(header)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Riemann
4
4
  module Tools # :nodoc:
5
- VERSION = '1.4.0'
5
+ VERSION = '1.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kingsbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-30 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json