riemann-tools 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +7 -6
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +18 -0
  5. data/CHANGELOG.md +23 -0
  6. data/Gemfile +22 -0
  7. data/Rakefile +1 -1
  8. data/bin/riemann-hwmon +8 -0
  9. data/bin/riemann-tls-check +8 -0
  10. data/lib/riemann/tools/apache_status.rb +2 -0
  11. data/lib/riemann/tools/bench.rb +4 -2
  12. data/lib/riemann/tools/consul_health.rb +2 -0
  13. data/lib/riemann/tools/dir_files_count.rb +2 -0
  14. data/lib/riemann/tools/dir_space.rb +2 -0
  15. data/lib/riemann/tools/diskstats.rb +6 -4
  16. data/lib/riemann/tools/fd.rb +2 -0
  17. data/lib/riemann/tools/freeswitch.rb +2 -0
  18. data/lib/riemann/tools/haproxy.rb +2 -0
  19. data/lib/riemann/tools/health.rb +79 -11
  20. data/lib/riemann/tools/http_check.rb +56 -17
  21. data/lib/riemann/tools/hwmon.rb +111 -0
  22. data/lib/riemann/tools/mdstat_parser.tab.rb +4 -2
  23. data/lib/riemann/tools/net.rb +3 -7
  24. data/lib/riemann/tools/nginx_status.rb +8 -4
  25. data/lib/riemann/tools/ntp.rb +2 -0
  26. data/lib/riemann/tools/portcheck.rb +2 -0
  27. data/lib/riemann/tools/proc.rb +2 -0
  28. data/lib/riemann/tools/tls_check.rb +604 -0
  29. data/lib/riemann/tools/utils.rb +39 -0
  30. data/lib/riemann/tools/varnish.rb +2 -0
  31. data/lib/riemann/tools/version.rb +1 -1
  32. data/lib/riemann/tools.rb +26 -9
  33. data/riemann-tools.gemspec +2 -11
  34. data/tools/riemann-aws/lib/riemann/tools/aws/billing.rb +3 -1
  35. data/tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb +2 -0
  36. data/tools/riemann-aws/lib/riemann/tools/aws/s3_status.rb +1 -1
  37. data/tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb +2 -0
  38. data/tools/riemann-aws/lib/riemann/tools/aws/status.rb +11 -9
  39. data/tools/riemann-chronos/lib/riemann/tools/chronos.rb +2 -0
  40. data/tools/riemann-docker/lib/riemann/tools/docker.rb +5 -5
  41. data/tools/riemann-marathon/lib/riemann/tools/marathon.rb +2 -0
  42. data/tools/riemann-munin/lib/riemann/tools/munin.rb +2 -0
  43. data/tools/riemann-rabbitmq/lib/riemann/tools/rabbitmq.rb +7 -7
  44. data/tools/riemann-riak/lib/riemann/tools/riak.rb +4 -2
  45. metadata +10 -129
data/lib/riemann/tools.rb CHANGED
@@ -32,7 +32,8 @@ module Riemann
32
32
  opt :event_host, 'Event hostname', type: String
33
33
  opt :interval, 'Seconds between updates', default: 5
34
34
  opt :tag, 'Tag to add to events', type: String, multi: true
35
- opt :ttl, 'TTL for events', type: Integer
35
+ opt :ttl, 'TTL for events (twice the interval when unspecified)', type: Integer
36
+ opt :minimum_ttl, 'Minimum TTL for events', type: Integer, short: :none
36
37
  opt :attribute, 'Attribute to add to the event', type: String, multi: true
37
38
  opt :timeout, 'Timeout (in seconds) when waiting for acknowledgements', default: 30
38
39
  opt :tcp, 'Use TCP transport instead of UDP (improves reliability, slight overhead.', default: true
@@ -44,6 +45,17 @@ module Riemann
44
45
  end
45
46
  end
46
47
 
48
+ attr_reader :argv
49
+
50
+ def initialize(allow_arguments: false)
51
+ options
52
+ @argv = ARGV.dup
53
+ abort "Error: stray arguments: #{ARGV.map(&:inspect).join(', ')}" if ARGV.any? && !allow_arguments
54
+
55
+ options[:ttl] ||= options[:interval] * 2
56
+ options[:ttl] = [options[:minimum_ttl], options[:ttl]].compact.max
57
+ end
58
+
47
59
  # Returns parsed options (cached) from command line.
48
60
  def options
49
61
  @options ||= self.class.options
@@ -51,19 +63,16 @@ module Riemann
51
63
  alias opts options
52
64
 
53
65
  def attributes
54
- @attributes ||= Hash[options[:attribute].map do |attr|
55
- k, v = attr.split(/=/)
66
+ @attributes ||= options[:attribute].to_h do |attr|
67
+ k, v = attr.split('=')
56
68
  [k, v] if k && v
57
- end]
69
+ end
58
70
  end
59
71
 
60
72
  def report(event)
61
- if options[:tag]
62
- # Work around a bug with beefcake which can't take frozen strings.
63
- event[:tags] = [*event.fetch(:tags, [])] + options[:tag].map(&:dup)
64
- end
73
+ event[:tags] = event.fetch(:tags, []) + options[:tag]
65
74
 
66
- event[:ttl] ||= options[:ttl] || (options[:interval] * 2)
75
+ event[:ttl] ||= options[:ttl]
67
76
 
68
77
  event[:host] = options[:event_host].dup if options[:event_host]
69
78
 
@@ -92,5 +101,13 @@ module Riemann
92
101
  end
93
102
 
94
103
  def tick; end
104
+
105
+ def endpoint_name(address, port)
106
+ if address.ipv6?
107
+ "[#{address}]:#{port}"
108
+ else
109
+ "#{address}:#{port}"
110
+ end
111
+ end
95
112
  end
96
113
  end
@@ -14,7 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
16
 
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
18
19
 
19
20
  spec.metadata['homepage_uri'] = spec.homepage
20
21
  spec.metadata['source_code_uri'] = spec.homepage
@@ -40,14 +41,4 @@ Gem::Specification.new do |spec|
40
41
  spec.add_runtime_dependency 'json', '>= 1.8'
41
42
  spec.add_runtime_dependency 'optimist', '~> 3.0', '>= 3.0.0'
42
43
  spec.add_runtime_dependency 'riemann-client', '~> 1.1'
43
-
44
- spec.add_development_dependency 'github_changelog_generator'
45
- spec.add_development_dependency 'racc'
46
- spec.add_development_dependency 'rake'
47
- spec.add_development_dependency 'rspec'
48
- spec.add_development_dependency 'rubocop'
49
- spec.add_development_dependency 'rubocop-rake'
50
- spec.add_development_dependency 'rubocop-rspec'
51
- spec.add_development_dependency 'sinatra'
52
- spec.add_development_dependency 'webrick'
53
44
  end
@@ -21,7 +21,9 @@ module Riemann
21
21
  opt :time_end, 'End time in seconds of the metrics period ', type: Integer, default: 60
22
22
 
23
23
  def initialize
24
- if options[:fog_credentials_file]
24
+ super
25
+
26
+ if opts[:fog_credentials_file]
25
27
  Fog.credentials_path = opts[:fog_credentials_file]
26
28
  Fog.credential = opts[:fog_credential].to_sym
27
29
  @cloudwatch = Fog::AWS::CloudWatch.new
@@ -17,6 +17,8 @@ module Riemann
17
17
  opt :region, 'AWS region', type: String, default: 'eu-west-1'
18
18
  opt :dbinstance_identifier, 'DBInstanceIdentifier', type: String
19
19
  def initialize
20
+ super
21
+
20
22
  abort 'FATAL: specify a DB instance name, see --help for usage' unless opts[:dbinstance_identifier]
21
23
  creds = if opts[:access_key] && opts[:secret_key]
22
24
  {
@@ -21,7 +21,7 @@ module Riemann
21
21
 
22
22
  def base_metrics
23
23
  # get last 60 seconds
24
- start_time = (Time.now.utc - 3600 * 24 * 1).iso8601
24
+ start_time = (Time.now.utc - (3600 * 24 * 1)).iso8601
25
25
  end_time = Time.now.utc.iso8601
26
26
 
27
27
  # The base query that all metrics would get
@@ -14,6 +14,8 @@ module Riemann
14
14
  opt :region, 'AWS region', type: String, default: 'us-east-1'
15
15
  opt :queue, 'SQS Queue name', type: String
16
16
  def initialize
17
+ super
18
+
17
19
  creds = if opts.key?('access_key') && opts.key?('secret_key')
18
20
  {
19
21
  aws_access_key_id: opts[:access_key],
@@ -20,21 +20,23 @@ module Riemann
20
20
  opt :event_warning, 'Number of days before event. Defaults to nil (i.e. when the event appears)', default: nil
21
21
 
22
22
  def initialize
23
- if options[:fog_credentials_file]
24
- Fog.credentials_path = options[:fog_credentials_file]
25
- Fog.credential = options[:fog_credential].to_sym
23
+ super
24
+
25
+ if opts[:fog_credentials_file]
26
+ Fog.credentials_path = opts[:fog_credentials_file]
27
+ Fog.credential = opts[:fog_credential].to_sym
26
28
  @compute = Fog::AWS::Compute.new
27
29
  else
28
- @compute = if options[:access_key] && options[:secret_key]
30
+ @compute = if opts[:access_key] && opts[:secret_key]
29
31
  Fog::AWS::Compute.new({
30
- access_key_key_id: options[:access_key],
31
- secret_key_access_key: options[:secret_key],
32
- region: options[:region],
32
+ access_key_key_id: opts[:access_key],
33
+ secret_key_access_key: opts[:secret_key],
34
+ region: opts[:region],
33
35
  })
34
36
  else
35
37
  Fog::AWS::Compute.new({
36
38
  use_iam_profile: true,
37
- region: options[:region],
39
+ region: opts[:region],
38
40
  })
39
41
  end
40
42
  end
@@ -61,7 +63,7 @@ module Riemann
61
63
  elsif opts[:event_warning] && (Date.today >= before - opts[:event_warning])
62
64
  { state: 'warning' }
63
65
  else
64
- { state: 'warning' }
66
+ {}
65
67
  end
66
68
 
67
69
  report ev.merge(ev2)
@@ -21,6 +21,8 @@ module Riemann
21
21
  def initialize
22
22
  options[:interval] = 60
23
23
  options[:ttl] = 120
24
+
25
+ super
24
26
  end
25
27
 
26
28
  # Handles HTTP connections and GET requests safely
@@ -31,6 +31,8 @@ module Riemann
31
31
  end
32
32
 
33
33
  def initialize
34
+ super
35
+
34
36
  Docker.url = opts[:docker_host] unless opts[:docker_host].nil?
35
37
 
36
38
  @hostname = opts[:host_hostname]
@@ -121,7 +123,7 @@ module Riemann
121
123
  end
122
124
 
123
125
  def disk
124
- `df -P`.split(/\n/).each do |r|
126
+ `df -P`.split("\n").each do |r|
125
127
  f = r.split(/\s+/)
126
128
  next if f[0] == 'Filesystem'
127
129
  next unless f[0] =~ %r{/} # Needs at least one slash in the mount path
@@ -171,10 +173,8 @@ module Riemann
171
173
  disk if @disk_enabled
172
174
 
173
175
  # Get CPU, Memory and Load of each container
174
- threads = []
175
-
176
- containers.each do |ctr|
177
- threads << Thread.new(ctr) do |container|
176
+ threads = containers.map do |ctr|
177
+ Thread.new(ctr) do |container|
178
178
  id = container.id
179
179
  name = get_container_name(container)
180
180
 
@@ -21,6 +21,8 @@ module Riemann
21
21
  def initialize
22
22
  options[:interval] = 60
23
23
  options[:ttl] = 120
24
+
25
+ super
24
26
  end
25
27
 
26
28
  # Handles HTTP connections and GET requests safely
@@ -10,6 +10,8 @@ module Riemann
10
10
  require 'munin-ruby'
11
11
 
12
12
  def initialize
13
+ super
14
+
13
15
  @munin = ::Munin::Node.new
14
16
  end
15
17
 
@@ -27,8 +27,8 @@ module Riemann
27
27
 
28
28
  def base_url
29
29
  protocol = 'http'
30
- protocol = 'https' if options[:monitor_use_tls] && (options[:monitor_use_tls] == true)
31
- "#{protocol}://#{options[:monitor_user]}:#{options[:monitor_pass]}@#{options[:monitor_host]}:#{options[:monitor_port]}/api"
30
+ protocol = 'https' if opts[:monitor_use_tls] && (opts[:monitor_use_tls] == true)
31
+ "#{protocol}://#{opts[:monitor_user]}:#{opts[:monitor_pass]}@#{opts[:monitor_host]}:#{opts[:monitor_port]}/api"
32
32
  end
33
33
 
34
34
  def overview_url
@@ -44,7 +44,7 @@ module Riemann
44
44
  end
45
45
 
46
46
  def event_host
47
- options[:event_host] || :monitor_host
47
+ opts[:event_host] || :monitor_host
48
48
  end
49
49
 
50
50
  def safe_get(uri, event_host)
@@ -53,8 +53,8 @@ module Riemann
53
53
  begin
54
54
  connection = Faraday.new(uri)
55
55
  response = connection.get do |req|
56
- req.options[:timeout] = options[:read_timeout]
57
- req.options[:open_timeout] = options[:open_timeout]
56
+ req.opts[:timeout] = opts[:read_timeout]
57
+ req.opts[:open_timeout] = opts[:open_timeout]
58
58
  end
59
59
  report(
60
60
  host: event_host,
@@ -75,7 +75,7 @@ module Riemann
75
75
 
76
76
  def check_queues
77
77
  response = safe_get(queues_url, event_host)
78
- max_size_check_filter = (Regexp.new(options[:ignore_max_size_queues]) if options[:ignore_max_size_queues])
78
+ max_size_check_filter = (Regexp.new(opts[:ignore_max_size_queues]) if opts[:ignore_max_size_queues])
79
79
 
80
80
  return if response.nil?
81
81
 
@@ -102,7 +102,7 @@ module Riemann
102
102
 
103
103
  errs << 'Queue has jobs but no consumers' if !queue['messages_ready'].nil? && (queue['messages_ready']).positive? && (queue['consumers']).zero?
104
104
 
105
- errs << "Queue has #{queue['messages_ready']} jobs" if (max_size_check_filter.nil? || queue['name'] !~ (max_size_check_filter)) && !queue['messages_ready'].nil? && (queue['messages_ready'] > options[:max_queue_size])
105
+ errs << "Queue has #{queue['messages_ready']} jobs" if (max_size_check_filter.nil? || queue['name'] !~ (max_size_check_filter)) && !queue['messages_ready'].nil? && (queue['messages_ready'] > opts[:max_queue_size])
106
106
 
107
107
  if errs.empty?
108
108
  report(
@@ -30,6 +30,8 @@ module Riemann
30
30
  opt :user_agent, 'User-Agent header for HTTP requests', short: :none, default: "#{File.basename($PROGRAM_NAME)}/#{Riemann::Tools::VERSION} (+https://github.com/riemann/riemann-tools)"
31
31
 
32
32
  def initialize
33
+ super
34
+
33
35
  detect_features
34
36
 
35
37
  @httpstatus = true
@@ -151,7 +153,7 @@ module Riemann
151
153
 
152
154
  # Returns the alerts state for the given fsm.
153
155
  def fsm_state(type, percentile, val)
154
- limit = opts["#{type}_#{percentile}_warning".to_sym]
156
+ limit = opts[:"#{type}_#{percentile}_warning"]
155
157
  case val
156
158
  when 0..limit
157
159
  'ok'
@@ -201,7 +203,7 @@ module Riemann
201
203
  str = `riak-admin status`
202
204
  raise 'riak-admin failed' unless $CHILD_STATUS == 0
203
205
 
204
- Hash[str.split(/\n/).map { |i| i.split(/ : /) }]
206
+ str.split("\n").to_h { |i| i.split(' : ') }
205
207
  end
206
208
 
207
209
  # Get current stats as a hash
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.10.0
4
+ version: 1.11.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: 2024-01-13 00:00:00.000000000 Z
11
+ date: 2024-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -58,132 +58,6 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.1'
61
- - !ruby/object:Gem::Dependency
62
- name: github_changelog_generator
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
- - !ruby/object:Gem::Dependency
76
- name: racc
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- - !ruby/object:Gem::Dependency
90
- name: rake
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: rspec
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
117
- - !ruby/object:Gem::Dependency
118
- name: rubocop
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: rubocop-rake
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
- - !ruby/object:Gem::Dependency
146
- name: rubocop-rspec
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - ">="
150
- - !ruby/object:Gem::Version
151
- version: '0'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
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'
187
61
  description: Collection of utilities which submit events to Riemann,
188
62
  email:
189
63
  - aphyr@aphyr.com
@@ -200,6 +74,7 @@ executables:
200
74
  - riemann-haproxy
201
75
  - riemann-health
202
76
  - riemann-http-check
77
+ - riemann-hwmon
203
78
  - riemann-kvminstance
204
79
  - riemann-md
205
80
  - riemann-memcached
@@ -208,6 +83,7 @@ executables:
208
83
  - riemann-ntp
209
84
  - riemann-portcheck
210
85
  - riemann-proc
86
+ - riemann-tls-check
211
87
  - riemann-varnish
212
88
  - riemann-wrapper
213
89
  - riemann-zookeeper
@@ -243,6 +119,7 @@ files:
243
119
  - bin/riemann-haproxy
244
120
  - bin/riemann-health
245
121
  - bin/riemann-http-check
122
+ - bin/riemann-hwmon
246
123
  - bin/riemann-kvminstance
247
124
  - bin/riemann-md
248
125
  - bin/riemann-memcached
@@ -251,6 +128,7 @@ files:
251
128
  - bin/riemann-ntp
252
129
  - bin/riemann-portcheck
253
130
  - bin/riemann-proc
131
+ - bin/riemann-tls-check
254
132
  - bin/riemann-varnish
255
133
  - bin/riemann-wrapper
256
134
  - bin/riemann-zookeeper
@@ -268,6 +146,7 @@ files:
268
146
  - lib/riemann/tools/haproxy.rb
269
147
  - lib/riemann/tools/health.rb
270
148
  - lib/riemann/tools/http_check.rb
149
+ - lib/riemann/tools/hwmon.rb
271
150
  - lib/riemann/tools/kvm.rb
272
151
  - lib/riemann/tools/md.rb
273
152
  - lib/riemann/tools/mdstat_parser.tab.rb
@@ -278,6 +157,7 @@ files:
278
157
  - lib/riemann/tools/portcheck.rb
279
158
  - lib/riemann/tools/proc.rb
280
159
  - lib/riemann/tools/riemann_client_wrapper.rb
160
+ - lib/riemann/tools/tls_check.rb
281
161
  - lib/riemann/tools/uptime_parser.tab.rb
282
162
  - lib/riemann/tools/utils.rb
283
163
  - lib/riemann/tools/varnish.rb
@@ -349,6 +229,7 @@ licenses:
349
229
  - MIT
350
230
  metadata:
351
231
  allowed_push_host: https://rubygems.org/
232
+ rubygems_mfa_required: 'true'
352
233
  homepage_uri: https://github.com/aphyr/riemann-tools
353
234
  source_code_uri: https://github.com/aphyr/riemann-tools
354
235
  changelog_uri: https://github.com/aphyr/riemann-tools
@@ -367,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
367
248
  - !ruby/object:Gem::Version
368
249
  version: '0'
369
250
  requirements: []
370
- rubygems_version: 3.4.20
251
+ rubygems_version: 3.5.13
371
252
  signing_key:
372
253
  specification_version: 4
373
254
  summary: Utilities which submit events to Riemann.