#!/bin/python
import sys
import requests

url = 'http://localhost:15672/api/queues/%%2f/%s' % (sys.argv[1])

r = requests.get(url, auth=('guest', 'guest')).json()
consumers = r['consumers']
messages = r['messages']

msg = 'Messages in queue: %i (%i consumers)' % (messages, consumers)

if consumers < 1:
    print 'CRITICAL: No consumers: %s' % msg
    sys.exit(2)

if messages > sys.argv[2]:
    print 'CRITICAL: %s' % msg
    sys.exit(2)

if messages > sys.argv[3]:
    print 'WARNING: %s' % msg
    sys.exit(1)

print 'OK: %s' % msg
sys.exit(0)
