forked from pierredelacelle/resque-nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_resque_failed
executable file
·52 lines (45 loc) · 1.2 KB
/
check_resque_failed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
require "rubygems"
require "resque"
require "resque/failure/redis"
require "optparse"
options = {}
required = [:warning, :critical, :host]
parser = OptionParser.new do |opts|
opts.banner = "Usage: check_resque_failed [options]"
opts.on("-h", "--host redishost", "The hostname of the redis server") do |h|
options[:host] = h
end
opts.on("-n", "--namespace resque:namespace", "The resque namespace") do |n|
options[:namespace] = n
end
opts.on("-w", "--warning percentage", "Warning threshold") do |w|
options[:warning] = w
end
opts.on("-c", "--critical critical", "Critical threshold") do |c|
options[:critical] = c
end
end
parser.parse!
if !required.all? { |k| options.has_key?(k) }
abort parser.to_s
else
redis = Redis.new(:host => options[:host])
Resque.redis = redis
Resque.redis.namespace = options[:namespace]
count = Resque::Failure::Redis.count
status = :ok
if count >= options[:critical].to_i
status = :critical
elsif count >= options[:warning].to_i
status = :warning
end
print status.to_s.upcase
print " - "
puts "failed: #{count}"
if (status == :critical)
exit(2)
elsif status == :warning
exit(1)
end
end