#!/bin/python3
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 > int(sys.argv[2]):
    print ('WARNING: %s' % msg)
    sys.exit(1)

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

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