riemann-tools 1.5.0 → 1.6.0

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: ce2307f0dfeaad07e9b904c5f0edf2b0d7a586507c94e8ffb2ff9e3ccf6b3c6f
4
- data.tar.gz: 8178becee10569b018dfdb54693cfa9e5c5a61dfe62ecdec7ca257004e2365ff
3
+ metadata.gz: e201bab60a1f457d506ec890d20bbda78e7229fba76acbae599b85c7d366a07b
4
+ data.tar.gz: 522750b32f5002d8fd799f95a4686eb576d63723781269fb489dd23da5567c22
5
5
  SHA512:
6
- metadata.gz: 7588c24abd5c87eb95ced867cc23350697ef893463e939a47c481518209a386c2b0a56e93e9d470e2fe1d9d0a78fa01d5b8d0e3f6af265d014072a00cf44570d
7
- data.tar.gz: 54bd9df700e67ee112e856e6104018bac1ad54444533186cdd2425416fa2ab9a0939c5bfd7de5446045d4813c9a8fac5e34db9d997ea841c9665ae97f7224b95
6
+ metadata.gz: 7e1634227dddcdd7f4223489f1193ab45168572143fae011790bc811ec346cb21743722b5a068337f8a612a0c20ea76769f7af739d74c242a9d043ec8749b625
7
+ data.tar.gz: 0c761697583bd243ea1788877a63ea21decdb25012bd52d59e109165e2e76efde3c11299c60b81aa8a0442fb3482957f06539074ea5cb56fb1d5b698994ddf11
@@ -13,7 +13,7 @@ jobs:
13
13
  lint:
14
14
  runs-on: ubuntu-latest
15
15
  steps:
16
- - uses: actions/checkout@v2
16
+ - uses: actions/checkout@v3
17
17
  - name: Setup ruby
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
@@ -32,7 +32,7 @@ jobs:
32
32
  - 3.0
33
33
  - 3.1
34
34
  steps:
35
- - uses: actions/checkout@v2
35
+ - uses: actions/checkout@v3
36
36
  - name: Setup Ruby
37
37
  uses: ruby/setup-ruby@v1
38
38
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.6.0](https://github.com/riemann/riemann-tools/tree/v1.6.0) (2022-11-04)
4
+
5
+ [Full Changelog](https://github.com/riemann/riemann-tools/compare/v1.5.0...v1.6.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add `riemann-http-check` to monitor HTTP\(S\) resources [\#248](https://github.com/riemann/riemann-tools/pull/248) ([smortex](https://github.com/smortex))
10
+ - Add FreeBSD support to `riemann-net` [\#247](https://github.com/riemann/riemann-tools/pull/247) ([smortex](https://github.com/smortex))
11
+
12
+ **Fixed bugs:**
13
+
14
+ - Fix `riemann-health` detection of `df` header [\#246](https://github.com/riemann/riemann-tools/pull/246) ([smortex](https://github.com/smortex))
15
+ - Fix/Improve `riemann-md` mdstat parser [\#245](https://github.com/riemann/riemann-tools/pull/245) ([smortex](https://github.com/smortex))
16
+
3
17
  ## [v1.5.0](https://github.com/riemann/riemann-tools/tree/v1.5.0) (2022-09-08)
4
18
 
5
19
  [Full Changelog](https://github.com/riemann/riemann-tools/compare/v1.4.0...v1.5.0)
data/README.markdown CHANGED
@@ -40,6 +40,7 @@ ship with the `riemann-tools` gem, including:
40
40
  * riemann-kvminstance - Monitor KVM instances.
41
41
  * riemann-ntp - Monitor NTP.
42
42
  * riemann-portcheck - Monitor open TCP ports.
43
+ * riemann-http-check - Monitor reachability of HTTP(S) resources.
43
44
 
44
45
  Also contained in the repository are a number of stand-alone monitoring
45
46
  tools, which are shipped as separate gems.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
5
+
6
+ require 'riemann/tools/http_check'
7
+
8
+ raise("Ruby #{Riemann::Tools::HttpCheck::REQUIRED_RUBY_VERSION} or better is required for using riemann-http-check") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(Riemann::Tools::HttpCheck::REQUIRED_RUBY_VERSION)
9
+
10
+ Riemann::Tools::HttpCheck.run
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'riemann/client'
5
- require 'pp'
6
5
 
7
6
  # Connects to a server (first arg) and populates it with a constant stream of
8
7
  # events for testing.
@@ -387,9 +387,8 @@ module Riemann
387
387
  end
388
388
 
389
389
  def disk
390
- df.split(/\n/).each do |r|
390
+ df.lines[1..].each do |r|
391
391
  f = r.split(/\s+/)
392
- next if f[0] == 'Filesystem'
393
392
 
394
393
  # Calculate capacity
395
394
  used = f[2].to_i
@@ -0,0 +1,208 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'resolv'
5
+ require 'socket'
6
+
7
+ require 'riemann/tools'
8
+
9
+ # Test for HTTP requests
10
+ module Riemann
11
+ module Tools
12
+ class HttpCheck
13
+ REQUIRED_RUBY_VERSION = '2.7.0'
14
+
15
+ include Riemann::Tools
16
+
17
+ opt :uri, 'URI to fetch', short: :none, type: :strings, default: ['http://localhost']
18
+ opt :response, 'Expected response codes', short: :none, type: :strings, default: [
19
+ '200', # OK
20
+ '301', # Moved Permanently
21
+ '401', # Unauthorized
22
+ ]
23
+ opt :connection_latency_warning, 'Lattency warning threshold', short: :none, default: 0.1
24
+ opt :connection_latency_critical, 'Lattency critical threshold', short: :none, default: 0.25
25
+ opt :response_latency_warning, 'Lattency warning threshold', short: :none, default: 0.5
26
+ opt :response_latency_critical, 'Lattency critical threshold', short: :none, default: 1.0
27
+ opt :http_timeout, 'Timeout (in seconds) for HTTP requests', short: :none, default: 5.0
28
+ opt :checks, 'A list of checks to run.', short: :none, type: :strings, default: %w[consistency connection-latency response-code response-latency]
29
+
30
+ def tick
31
+ opts[:uri].each do |uri|
32
+ test_uri(uri)
33
+ end
34
+ end
35
+
36
+ def test_uri(uri)
37
+ uri = URI(uri)
38
+
39
+ request = ::Net::HTTP::Get.new(uri)
40
+ request.basic_auth(uri.user, uri.password)
41
+
42
+ responses = []
43
+
44
+ with_each_address(uri.host) do |address|
45
+ responses << test_uri_address(uri, address, request)
46
+ end
47
+
48
+ responses.compact!
49
+
50
+ return unless opts[:checks].include?('consistency')
51
+
52
+ raise StandardError, "Could not get any response from #{uri.host}" unless responses.any?
53
+
54
+ uniq_code = responses.map(&:code).uniq
55
+ uniq_body = responses.map(&:body).uniq
56
+
57
+ issues = []
58
+ issues << "#{uniq_code.count} different response code" unless uniq_code.one?
59
+ issues << "#{uniq_body.count} different response body" unless uniq_body.one?
60
+
61
+ if issues.none?
62
+ state = 'ok'
63
+ description = "consistent response on all #{responses.count} endpoints"
64
+ else
65
+ state = 'critical'
66
+ description = "#{issues.join(' and ')} on #{responses.count} endpoints"
67
+ end
68
+
69
+ report(
70
+ service: service(uri, 'consistency'),
71
+ state: state,
72
+ description: description,
73
+ hostname: uri.host,
74
+ port: uri.port,
75
+ )
76
+ rescue StandardError => e
77
+ report(
78
+ service: service(uri, 'consistency'),
79
+ state: 'critical',
80
+ description: e.message,
81
+ hostname: uri.host,
82
+ port: uri.port,
83
+ )
84
+ end
85
+
86
+ def test_uri_address(uri, address, request)
87
+ response = nil
88
+
89
+ start = Time.now
90
+ connected = nil
91
+ done = nil
92
+
93
+ http = nil
94
+ begin
95
+ Timeout.timeout(opts[:http_timeout]) do
96
+ http = ::Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE, ipaddr: address)
97
+ connected = Time.now
98
+ response = http.request(request)
99
+ end
100
+ rescue Timeout::Error
101
+ # Ignore
102
+ else
103
+ done = Time.now
104
+ ensure
105
+ http&.finish
106
+ end
107
+
108
+ report_http_endpoint_response_code(http, uri, response) if opts[:checks].include?('response-code')
109
+ report_http_endpoint_latency(http, uri, 'connection', start, connected) if opts[:checks].include?('connection-latency')
110
+ report_http_endpoint_latency(http, uri, 'response', start, done) if opts[:checks].include?('response-latency')
111
+
112
+ response
113
+ rescue StandardError
114
+ # Ignore this address
115
+ nil
116
+ end
117
+
118
+ def with_each_address(host, &block)
119
+ addresses = Resolv::DNS.new.getaddresses(host)
120
+ if addresses.empty?
121
+ host = host[1...-1] if host[0] == '[' && host[-1] == ']'
122
+ addresses << IPAddr.new(host)
123
+ end
124
+
125
+ addresses.each do |address|
126
+ block.call(address.to_s)
127
+ end
128
+ end
129
+
130
+ def report_http_endpoint_response_code(http, uri, response)
131
+ return unless response
132
+
133
+ report(
134
+ {
135
+ state: response_code_state(response.code),
136
+ metric: response.code.to_i,
137
+ description: "#{response.code} #{response.message}",
138
+ }.merge(endpoint_report(http, uri, 'response code')),
139
+ )
140
+ end
141
+
142
+ def response_code_state(code)
143
+ opts[:response].include?(code) ? 'ok' : 'critical'
144
+ end
145
+
146
+ def report_http_endpoint_latency(http, uri, latency, start, stop)
147
+ if stop
148
+ metric = stop - start
149
+ report(
150
+ {
151
+ state: latency_state(latency, metric),
152
+ metric: metric,
153
+ description: format('%.3f ms', metric * 1000),
154
+ }.merge(endpoint_report(http, uri, "#{latency} latency")),
155
+ )
156
+ else
157
+ report(
158
+ {
159
+ state: 'critical',
160
+ description: 'timeout',
161
+ }.merge(endpoint_report(http, uri, "#{latency} latency")),
162
+ )
163
+ end
164
+ end
165
+
166
+ def latency_state(name, latency)
167
+ if latency > opts["#{name}_latency_critical".to_sym]
168
+ 'critical'
169
+ elsif latency > opts["#{name}_latency_warning".to_sym]
170
+ 'warning'
171
+ else
172
+ 'ok'
173
+ end
174
+ end
175
+
176
+ def endpoint_report(http, uri, service)
177
+ {
178
+ service: endpoint_service(http, uri, service),
179
+ hostname: uri.host,
180
+ address: http.ipaddr,
181
+ port: uri.port,
182
+ }
183
+ end
184
+
185
+ def endpoint_service(http, uri, service)
186
+ "get #{redact_uri(uri)} #{endpoint_name(IPAddr.new(http.ipaddr), http.port)} #{service}"
187
+ end
188
+
189
+ def service(uri, service)
190
+ "get #{redact_uri(uri)} #{service}"
191
+ end
192
+
193
+ def redact_uri(uri)
194
+ reported_uri = uri.dup
195
+ reported_uri.password = '**redacted**' if reported_uri.password
196
+ reported_uri
197
+ end
198
+
199
+ def endpoint_name(address, port)
200
+ if address.ipv6?
201
+ "[#{address}]:#{port}"
202
+ else
203
+ "#{address}:#{port}"
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
@@ -15,53 +15,59 @@ module Riemann
15
15
  module Tools
16
16
  class MdstatParser < Racc::Parser
17
17
 
18
- module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 49)
18
+ module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 58)
19
19
 
20
20
  def parse(text)
21
21
  s = Utils::StringTokenizer.new(text)
22
22
 
23
23
  until s.eos? do
24
24
  case
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)
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(/\([WJFSR]\)/) then s.push_token(:DISK_STATUS)
29
+ when s.scan(/<none>/) then s.push_token(:NONE)
30
+
31
+ when s.scan(/\[=*>.*\]/) then s.push_token(:PROGRESS)
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(/]/) then s.push_token(']')
42
+
43
+ when s.scan(/DELAYED\b/) then s.push_token(:DELAYED)
44
+ when s.scan(/KB\b/) then s.push_token(:BYTE_UNIT)
45
+ when s.scan(/K\/sec\b/) then s.push_token(:SPEED_UNIT)
46
+ when s.scan(/PENDING\b/) then s.push_token(:PENDING)
47
+ when s.scan(/Personalities :/) then s.push_token(:PERSONALITIES)
48
+ when s.scan(/REMOTE\b/) then s.push_token(:REMOTE)
49
+ when s.scan(/algorithm\b/) then s.push_token(:ALGORITHM)
50
+ when s.scan(/bitmap\b/) then s.push_token(:BITMAP)
51
+ when s.scan(/blocks\b/) then s.push_token(:BLOCKS)
52
+ when s.scan(/check\b/) then s.push_token(:CHECK)
53
+ when s.scan(/chunk\b/) then s.push_token(:CHUNK)
54
+ when s.scan(/finish\b/) then s.push_token(:FINISH)
55
+ when s.scan(/k\b/) then s.push_token(:UNIT)
56
+ when s.scan(/level\b/) then s.push_token(:LEVEL)
57
+ when s.scan(/min\b/) then s.push_token(:MIN)
58
+ when s.scan(/pages\b/) then s.push_token(:PAGES)
50
59
  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)
60
+ when s.scan(/recover\b/) then s.push_token(:RECOVER)
61
+ when s.scan(/recovery\b/) then s.push_token(:RECOVERY)
62
+ when s.scan(/reshape\b/) then s.push_token(:RESHAPE)
63
+ when s.scan(/resync\b/) then s.push_token(:RESYNC)
64
+ when s.scan(/speed\b/) then s.push_token(:SPEED)
65
+ when s.scan(/super\b/) then s.push_token(:SUPER)
66
+ when s.scan(/unused devices:/) then s.push_token(:UNUSED_DEVICES)
67
+
68
+ when s.scan(/\d+\.\d+/) then s.push_token(:FLOAT, s.matched.to_f)
69
+ when s.scan(/\d+/) then s.push_token(:INTEGER, s.matched.to_i)
70
+ when s.scan(/\w+/) then s.push_token(:IDENTIFIER)
65
71
  else
66
72
  s.unexpected_token
67
73
  end
@@ -83,97 +89,109 @@ module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 49)
83
89
  ##### State transition tables begin ###
84
90
 
85
91
  racc_action_table = [
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 ]
92
+ 60, 17, 10, 53, 54, 15, 73, 55, 56, 14,
93
+ 3, 13, 10, 28, 4, 7, 12, 61, 72, 62,
94
+ 63, 11, 71, 18, 19, 20, 21, 22, 23, 24,
95
+ 10, 27, 30, 32, 34, 35, 36, 37, 38, 39,
96
+ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
97
+ 50, 51, 58, 64, 65, 66, 67, 68, 69, 70,
98
+ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
99
+ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
100
+ 94, 95, 96, 97, 98, 99, 100 ]
94
101
 
95
102
  racc_action_check = [
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 ]
103
+ 53, 11, 5, 50, 50, 11, 66, 50, 50, 10,
104
+ 0, 10, 25, 25, 1, 4, 6, 53, 66, 53,
105
+ 53, 5, 66, 12, 13, 14, 16, 18, 19, 20,
106
+ 23, 24, 28, 30, 31, 32, 33, 34, 36, 37,
107
+ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
108
+ 48, 49, 52, 54, 55, 56, 58, 59, 64, 65,
109
+ 67, 68, 74, 75, 76, 77, 78, 79, 80, 81,
110
+ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
111
+ 92, 93, 94, 95, 97, 98, 99 ]
104
112
 
105
113
  racc_action_pointer = [
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 ]
114
+ -8, 14, nil, nil, 15, -10, -16, nil, nil, nil,
115
+ -23, -11, 4, 12, 12, nil, 14, nil, -6, 9,
116
+ -4, nil, nil, 18, 22, 0, nil, nil, 28, nil,
117
+ 4, 20, 24, 4, 24, nil, 25, 3, 5, 28,
118
+ 29, 13, 11, 38, 14, 11, 36, 47, 17, 38,
119
+ -18, nil, 49, -6, 16, 17, 18, nil, 22, 20,
120
+ nil, nil, nil, nil, 34, 35, -2, 47, 50, nil,
121
+ nil, nil, nil, nil, 27, 25, 51, 26, 49, 54,
122
+ 36, 34, 57, 58, 67, 33, 41, 65, 40, 40,
123
+ 65, 68, 75, 66, 75, 56, nil, 47, 72, 58,
124
+ nil ]
116
125
 
117
126
  racc_action_default = [
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 ]
127
+ -33, -33, -6, -4, -33, -33, -2, 101, -1, -5,
128
+ -33, -33, -33, -33, -33, -29, -30, -32, -33, -33,
129
+ -33, -31, -3, -33, -11, -33, -9, -10, -33, -8,
130
+ -13, -15, -33, -33, -33, -12, -33, -33, -33, -33,
131
+ -33, -33, -33, -33, -33, -33, -33, -33, -33, -33,
132
+ -24, -14, -17, -33, -33, -33, -33, -7, -33, -33,
133
+ -25, -26, -27, -28, -33, -33, -33, -33, -33, -19,
134
+ -20, -21, -22, -23, -33, -33, -33, -33, -33, -33,
135
+ -33, -33, -33, -33, -33, -33, -33, -33, -33, -33,
136
+ -33, -33, -33, -33, -33, -33, -16, -33, -33, -33,
137
+ -18 ]
128
138
 
129
139
  racc_goto_table = [
130
- 9, 1, 2, 5, 8, 12, 25, 34, 36, 55,
131
- 57, 59, nil, nil, nil, nil, 26, nil, nil, nil,
132
- 30 ]
140
+ 9, 1, 2, 5, 8, 6, 25, 31, 33, 52,
141
+ 57, 59, 16, nil, nil, nil, nil, nil, 26, nil,
142
+ 29 ]
133
143
 
134
144
  racc_goto_check = [
135
145
  6, 1, 2, 3, 4, 5, 7, 8, 9, 10,
136
- 11, 12, nil, nil, nil, nil, 6, nil, nil, nil,
146
+ 11, 12, 13, nil, nil, nil, nil, nil, 6, nil,
137
147
  6 ]
138
148
 
139
149
  racc_goto_pointer = [
140
- nil, 1, 2, 1, -1, -1, -5, -15, -25, -26,
141
- -44, -45, -45 ]
150
+ nil, 1, 2, 1, -1, 2, -5, -17, -23, -23,
151
+ -41, -42, -42, 1 ]
142
152
 
143
153
  racc_goto_default = [
144
154
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
145
- nil, nil, nil ]
155
+ nil, nil, nil, nil ]
146
156
 
147
157
  racc_reduce_table = [
148
158
  0, 0, :racc_error,
149
- 3, 39, :_reduce_1,
150
- 3, 40, :_reduce_none,
151
- 4, 43, :_reduce_none,
152
- 0, 43, :_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,
159
+ 3, 42, :_reduce_1,
160
+ 2, 43, :_reduce_none,
161
+ 4, 46, :_reduce_none,
161
162
  0, 46, :_reduce_none,
162
- 9, 47, :_reduce_none,
163
- 0, 47, :_reduce_none,
164
- 14, 49, :_reduce_none,
163
+ 2, 44, :_reduce_5,
164
+ 0, 44, :_reduce_6,
165
+ 19, 47, :_reduce_7,
166
+ 2, 48, :_reduce_none,
167
+ 1, 48, :_reduce_none,
168
+ 5, 47, :_reduce_none,
169
+ 4, 47, :_reduce_none,
170
+ 2, 49, :_reduce_none,
165
171
  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 ]
172
+ 9, 50, :_reduce_none,
173
+ 0, 50, :_reduce_none,
174
+ 14, 52, :_reduce_none,
175
+ 0, 52, :_reduce_none,
176
+ 18, 51, :_reduce_none,
177
+ 3, 51, :_reduce_none,
178
+ 3, 51, :_reduce_none,
179
+ 3, 51, :_reduce_none,
180
+ 3, 51, :_reduce_none,
181
+ 3, 51, :_reduce_none,
182
+ 0, 51, :_reduce_none,
183
+ 1, 53, :_reduce_none,
184
+ 1, 53, :_reduce_none,
185
+ 1, 53, :_reduce_none,
186
+ 1, 53, :_reduce_none,
187
+ 2, 45, :_reduce_none,
188
+ 2, 45, :_reduce_none,
189
+ 2, 54, :_reduce_none,
190
+ 1, 54, :_reduce_none ]
173
191
 
174
- racc_reduce_n = 25
192
+ racc_reduce_n = 33
175
193
 
176
- racc_shift_n = 93
194
+ racc_shift_n = 101
177
195
 
178
196
  racc_token_table = {
179
197
  false => 0,
@@ -184,38 +202,41 @@ racc_token_table = {
184
202
  :BYTE_UNIT => 5,
185
203
  :CHECK => 6,
186
204
  :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
205
+ :DELAYED => 8,
206
+ :DISK_STATUS => 9,
207
+ :FINISH => 10,
208
+ :FLOAT => 11,
209
+ :IDENTIFIER => 12,
210
+ :INTEGER => 13,
211
+ :LEVEL => 14,
212
+ :MIN => 15,
213
+ :NONE => 16,
214
+ :PAGES => 17,
215
+ :PERSONALITIES => 18,
216
+ :PERSONALITY => 19,
217
+ :PENDING => 20,
218
+ :PROGRESS => 21,
219
+ :RECOVER => 22,
220
+ :RECOVERY => 23,
221
+ :REMOTE => 24,
222
+ :RESHAPE => 25,
223
+ :RESYNC => 26,
224
+ :SPEED => 27,
225
+ :SPEED_UNIT => 28,
226
+ :SUPER => 29,
227
+ :UNIT => 30,
228
+ :UNUSED_DEVICES => 31,
229
+ "[" => 32,
230
+ "]" => 33,
231
+ ":" => 34,
232
+ "/" => 35,
233
+ "," => 36,
234
+ "=" => 37,
235
+ "%" => 38,
236
+ "(" => 39,
237
+ ")" => 40 }
238
+
239
+ racc_nt_base = 41
219
240
 
220
241
  racc_use_result_var = true
221
242
 
@@ -244,18 +265,23 @@ Racc_token_to_s_table = [
244
265
  "BYTE_UNIT",
245
266
  "CHECK",
246
267
  "CHUNK",
247
- "FAILED",
268
+ "DELAYED",
269
+ "DISK_STATUS",
248
270
  "FINISH",
249
271
  "FLOAT",
250
272
  "IDENTIFIER",
251
273
  "INTEGER",
252
274
  "LEVEL",
253
275
  "MIN",
276
+ "NONE",
254
277
  "PAGES",
255
278
  "PERSONALITIES",
256
279
  "PERSONALITY",
280
+ "PENDING",
257
281
  "PROGRESS",
282
+ "RECOVER",
258
283
  "RECOVERY",
284
+ "REMOTE",
259
285
  "RESHAPE",
260
286
  "RESYNC",
261
287
  "SPEED",
@@ -263,17 +289,15 @@ Racc_token_to_s_table = [
263
289
  "SUPER",
264
290
  "UNIT",
265
291
  "UNUSED_DEVICES",
266
- "\":\"",
267
292
  "\"[\"",
268
293
  "\"]\"",
294
+ "\":\"",
269
295
  "\"/\"",
270
- "\"(\"",
271
- "\")\"",
272
296
  "\",\"",
273
297
  "\"=\"",
274
298
  "\"%\"",
275
- "\"<\"",
276
- "\">\"",
299
+ "\"(\"",
300
+ "\")\"",
277
301
  "$start",
278
302
  "target",
279
303
  "personalities",
@@ -286,7 +310,8 @@ Racc_token_to_s_table = [
286
310
  "level",
287
311
  "progress",
288
312
  "bitmap",
289
- "progress_action" ]
313
+ "progress_action",
314
+ "identifiers" ]
290
315
 
291
316
  Racc_debug_parser = false
292
317
 
@@ -362,6 +387,22 @@ module_eval(<<'.,.,', 'mdstat_parser.y', 13)
362
387
 
363
388
  # reduce 24 omitted
364
389
 
390
+ # reduce 25 omitted
391
+
392
+ # reduce 26 omitted
393
+
394
+ # reduce 27 omitted
395
+
396
+ # reduce 28 omitted
397
+
398
+ # reduce 29 omitted
399
+
400
+ # reduce 30 omitted
401
+
402
+ # reduce 31 omitted
403
+
404
+ # reduce 32 omitted
405
+
365
406
  def _reduce_none(val, _values, result)
366
407
  val[0]
367
408
  end
@@ -9,7 +9,7 @@ module Riemann
9
9
  include Riemann::Tools
10
10
 
11
11
  opt :interfaces, 'Interfaces to monitor', type: :strings, default: nil
12
- opt :ignore_interfaces, 'Interfaces to ignore', type: :strings, default: ['lo']
12
+ opt :ignore_interfaces, 'Interfaces to ignore', type: :strings, default: ['\Alo\d*\z']
13
13
 
14
14
  def initialize
15
15
  @old_state = nil
@@ -19,9 +19,54 @@ module Riemann
19
19
  []
20
20
  end
21
21
  @ignore_interfaces = opts[:ignore_interfaces].reject(&:empty?).map(&:dup)
22
+
23
+ ostype = `uname -s`.chomp.downcase
24
+ case ostype
25
+ when 'freebsd'
26
+ @state = method :freebsd_state
27
+ else
28
+ puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == 'linux'
29
+ @state = method :linux_state
30
+ end
31
+ end
32
+
33
+ def report_interface?(iface)
34
+ if !@interfaces.empty?
35
+ @interfaces.any? { |pattern| iface.match?(pattern) }
36
+ else
37
+ @ignore_interfaces.none? { |pattern| iface.match?(pattern) }
38
+ end
39
+ end
40
+
41
+ FREEBSD_MAPPING = {
42
+ 'collisions' => 'tx colls',
43
+ 'dropped-packets' => 'rx drop',
44
+ 'received-bytes' => 'rx bytes',
45
+ 'received-packets' => 'rx packets',
46
+ 'received-errors' => 'rx errs',
47
+ 'sent-bytes' => 'tx bytes',
48
+ 'sent-packets' => 'tx packets',
49
+ 'send-errors' => 'tx errs',
50
+ }.freeze
51
+
52
+ def freebsd_state
53
+ require 'json'
54
+
55
+ state = {}
56
+
57
+ all_stats = JSON.parse(`netstat -inb --libxo=json`)
58
+ all_stats.dig('statistics', 'interface').select { |s| s['mtu'] }.each do |interface_stats|
59
+ next unless report_interface?(interface_stats['name'])
60
+
61
+ FREEBSD_MAPPING.each do |key, service|
62
+ state["#{interface_stats['name']} #{service}"] = interface_stats[key]
63
+ end
64
+ end
65
+
66
+ state
22
67
  end
23
68
 
24
- def state
69
+ def linux_state
25
70
  f = File.read('/proc/net/dev')
26
71
  state = {}
27
72
  f.split("\n").each do |line|
@@ -29,8 +74,7 @@ module Riemann
29
74
 
30
75
  iface = Regexp.last_match(1)
31
76
 
32
- next unless @interfaces.empty? || @interfaces.any? { |pattern| iface.match?(pattern) }
33
- next if @ignore_interfaces.any? { |pattern| iface.match?(pattern) }
77
+ next unless report_interface?(iface)
34
78
 
35
79
  ['rx bytes',
36
80
  'rx packets',
@@ -60,7 +104,7 @@ module Riemann
60
104
  end
61
105
 
62
106
  def tick
63
- state = self.state
107
+ state = @state.call
64
108
 
65
109
  if @old_state
66
110
  # Report services from `@old_state` that don't exist in `state` as expired
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Riemann
4
4
  module Tools # :nodoc:
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.0'
6
6
  end
7
7
  end
@@ -48,4 +48,6 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency 'rubocop'
49
49
  spec.add_development_dependency 'rubocop-rake'
50
50
  spec.add_development_dependency 'rubocop-rspec'
51
+ spec.add_development_dependency 'sinatra'
52
+ spec.add_development_dependency 'webrick'
51
53
  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.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kingsbury
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -156,6 +156,34 @@ dependencies:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: sinatra
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: webrick
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
159
187
  description: Collection of utilities which submit events to Riemann,
160
188
  email:
161
189
  - aphyr@aphyr.com
@@ -171,6 +199,7 @@ executables:
171
199
  - riemann-freeswitch
172
200
  - riemann-haproxy
173
201
  - riemann-health
202
+ - riemann-http-check
174
203
  - riemann-kvminstance
175
204
  - riemann-md
176
205
  - riemann-memcached
@@ -213,6 +242,7 @@ files:
213
242
  - bin/riemann-freeswitch
214
243
  - bin/riemann-haproxy
215
244
  - bin/riemann-health
245
+ - bin/riemann-http-check
216
246
  - bin/riemann-kvminstance
217
247
  - bin/riemann-md
218
248
  - bin/riemann-memcached
@@ -237,6 +267,7 @@ files:
237
267
  - lib/riemann/tools/freeswitch.rb
238
268
  - lib/riemann/tools/haproxy.rb
239
269
  - lib/riemann/tools/health.rb
270
+ - lib/riemann/tools/http_check.rb
240
271
  - lib/riemann/tools/kvm.rb
241
272
  - lib/riemann/tools/md.rb
242
273
  - lib/riemann/tools/mdstat_parser.tab.rb
@@ -321,7 +352,7 @@ metadata:
321
352
  homepage_uri: https://github.com/aphyr/riemann-tools
322
353
  source_code_uri: https://github.com/aphyr/riemann-tools
323
354
  changelog_uri: https://github.com/aphyr/riemann-tools
324
- post_install_message:
355
+ post_install_message:
325
356
  rdoc_options: []
326
357
  require_paths:
327
358
  - lib
@@ -336,8 +367,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
367
  - !ruby/object:Gem::Version
337
368
  version: '0'
338
369
  requirements: []
339
- rubygems_version: 3.2.5
340
- signing_key:
370
+ rubygems_version: 3.3.23
371
+ signing_key:
341
372
  specification_version: 4
342
373
  summary: Utilities which submit events to Riemann.
343
374
  test_files: []