Created
September 21, 2009 16:14
-
-
Save vitaliel/190353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Author: Vitalie Lazu | |
# Date: Mon, 21 Sep 2009 17:59:50 +0300 | |
# | |
# Starling status plugin for nagios | |
require 'rubygems' | |
# needs memcache-client gem | |
require "memcache" | |
require 'optparse' | |
# exit codes: | |
# 0 - ok | |
# 1 - warning | |
# 2 - critical | |
# 3 - unknown | |
# Default warning: more than 20 unprocessed items, critical 50 | |
params = {:host => 'localhost', :port => '22122', :w => 20, :c => 50} | |
parser = OptionParser.new do |opts| | |
opts.banner = "Usage: #{__FILE__} [options]" | |
opts.separator '' | |
opts.on('-h', '--host HOST', String, 'Host to connect, default localhost') { |h| params[:host] = h } | |
opts.on('-p', '--port PORT', Integer, 'Starling port, default 22122') { |p| params[:port] = p } | |
opts.on('-w', '--warn LEVEL', Integer, 'Warning level, default 20') { |w| params[:w] = w } | |
opts.on('-c', '--critical LEVEL',Integer, 'Critical level, default 50') { |c| params[:c] = c } | |
opts.on_tail('-h', '--help', 'Show this message') { | |
puts opts | |
exit | |
} | |
opts.parse!(ARGV) | |
end | |
srv = "#{params[:host]}:#{params[:port]}" | |
begin | |
c = MemCache.new(srv) | |
items = 0 | |
for k,v in c.stats | |
items += v["curr_items"] | |
end | |
puts "#{srv}: Unprocessed items: #{items}" | |
if items >= params[:c] | |
exit 2 | |
elsif items >= params[:w] | |
exit 1 | |
else | |
exit 0 | |
end | |
rescue => e | |
puts "#{srv}: #{e.message}" | |
exit 3 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment