Skip to content

Instantly share code, notes, and snippets.

@russss
Created September 1, 2011 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russss/1186406 to your computer and use it in GitHub Desktop.
Save russss/1186406 to your computer and use it in GitHub Desktop.
Nagios/Icinga plugin to get the number of un-acked messages in a number of RabbitMQ queues
#!/usr/bin/env python
# https://gist.github.com/gists/1186406
import httplib2, json, re, sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-w", "--warning", dest="warning", type="int",
default="50", help="warning threshold")
parser.add_option("-c", "--critical", dest="critical", type="int",
default="100", help="critical threshold")
parser.add_option("-r", "--regex", dest="regex", type="string", default="", help="regex to match")
parser.add_option("-H", "--host", dest="host", type="string", help="IP address")
parser.add_option("-p", "--port", dest="port", type="string", help="port", default="55672")
options, _ = parser.parse_args()
try:
http = httplib2.Http()
http.add_credentials('admin', 'admin')
_, response = http.request("http://%s:%s/api/queues" % (options.host, options.port))
queues = json.loads(response)
except (AttributeError, ValueError):
print "UNKNOWN: unable to connect to %s:%s" % (options.host, options.port)
sys.exit(3)
total = sum(queue['backing_queue_status']['pending_acks'] for queue in queues
if re.search(options.regex, queue['name']))
if total > options.warning:
print "WARNING: %s un-acked messages" % total
sys.exit(1)
elif total > options.critical:
print "CRITICAL: %s un-acked messages" % total
sys.exit(2)
print "OK: %s un-acked messages" % total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment