Skip to content

Instantly share code, notes, and snippets.

@Gsantomaggio
Last active January 13, 2016 14:52
Show Gist options
  • Save Gsantomaggio/a05c6b2ba86180bc1951 to your computer and use it in GitHub Desktop.
Save Gsantomaggio/a05c6b2ba86180bc1951 to your computer and use it in GitHub Desktop.
__author__ = 'gabriele'
import urllib2
import base64
import time
import datetime
import json
def print_time(step):
ts = time.time();
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S');
print st + " - " + step
def get_auth(user, password):
return base64.encodestring('%s:%s' % (user, user)).replace('\n', '')
def call_api(rabbitmq_host, vhost, user, password):
request = urllib2.Request("http://" + rabbitmq_host + ":15672/api/queues");
request.add_header("Authorization", "Basic %s" % get_auth(user, password))
request.get_method = lambda: 'GET'
response = urllib2.urlopen(request)
print_time(" *** response done, loading json")
queues = json.load(response)
for q in queues:
print_time(" *** removing " + q['name'])
request_del = urllib2.Request(
"http://" + rabbitmq_host + ":15672/api/queues/" + vhost + "/" + q[
'name'])
request_del.add_header("Authorization",
"Basic %s" % get_auth(user, password))
request_del.get_method = lambda: 'DELETE'
urllib2.urlopen(request_del)
print_time(" *** removed " + q['name'])
if __name__ == '__main__':
rabbitmq_host = "localhost";
call_api(rabbitmq_host, "%2f", "guest", "guest")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment