-
Notifications
You must be signed in to change notification settings - Fork 4
/
wip_detect_broken_bindings
executable file
·51 lines (42 loc) · 1.62 KB
/
wip_detect_broken_bindings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import requests
import re
from requests.auth import HTTPBasicAuth
import json
import pprint
import sys
from urllib.parse import quote
host = "node1"
url = 'http://' + host + ':15672/api/bindings'
basic_auth = HTTPBasicAuth('admin', 'administrator')
response = requests.get(url, auth=basic_auth)
response.raise_for_status()
vhost = "/"
broken = []
print("# Checking.. may take a while..", flush=True)
if(response.ok):
data = response.json()
for entry in data:
exchange = entry['source']
routing_key = entry['routing_key']
destination = entry['destination']
if exchange == '':
continue
if re.match('^amq.gen', destination):
continue
url = 'http://' + host + ':15672/api/exchanges/' + quote(vhost, safe='') + '/' + exchange + '/publish'
data = '{"vhost":"' + vhost + '","name":"' + exchange + '","properties":{"delivery_mode":2,"headers":{}},"routing_key":"' + routing_key + '","delivery_mode":"2","payload":"test","headers":{},"props":{},"payload_encoding":"string"}'
r = response = requests.post(url, auth=basic_auth, data=data)
try:
r.raise_for_status()
data = r.json()
if data['routed'] == False:
broken.append(destination)
except requests.exceptions.HTTPError as e:
continue
else:
print(response.content)
for entry in broken:
print("# broken bindings - just delete these queues", flush=True)
print("rabbitmqctl delete_queue %s " % entry)
print("# DONE")