Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (67 sloc) 2.42 KB
#!/usr/bin/python
import libxml2
from rabbithole import *
'''
<td>activemq.queue</td>
<td colspan=2>Consumer.TORS.VirtualTopic.ODB_ALL</td>
<td>activemq.queue</td>
<td colspan=2>Consumer.TORS_a04.VirtualTopic.ODB_ALL</td>
'''
'''
<p><b>Version</b><br/>
0.3.2</p>
'''
ProfileNeeded()
stats = {}
queueExpr = re.compile("<td>activemq.queue</td>[^<]*<td[^>]*>([^<]*)</td>", re.MULTILINE)
versionExpr = re.compile("<p><b>Version</b><br/>([^<]+)</p>", re.MULTILINE)
page = GetTemplate("queues_main")
lineTemplate = GetTemplate("queues_line")
used = {}
def GetDeployedQueue(url):
global used
match = None
version = "_N/A_"
try:
page = GetWebPage(url)
ver = versionExpr.search(page)
if ver:
version = ver.group(1).strip()
match = queueExpr.search(page)
except:
return {"queue": "_N/A_", "version": version}
if match:
key = match.group(1)
if used.has_key(key):
key = "{color:red}%s{color}" % key
used[key] = True
return {"queue": key, "version": version}
return {"queue": "", "version": version}
print "--- Check if connected..."
try:
GetWebPage(config["check_connection_url"])
except:
print "[!] Not connected to VPN!"
exit(0)
## Getting queues consumers
doc = libxml2.parseFile("queues.txt")
queues = [q.prop("name") for q in doc.xpathNewContext().xpathEval("//queue/stats[@consumerCount='0']/parent::*")]
subscribers = ""
ours = re.compile("(tors|ras|cloud)", re.IGNORECASE)
for q in queues:
if ours.search(q):
q = "{color:red}%s{color}" % q
if subscribers:
subscribers += ", "
subscribers += q
## Getting deployed versions
result = []
for env in sorted(config["deployments"].keys()):
url = "http://%s/info" % config["deployments"][env]
parsed = GetDeployedQueue(url)
print "%s (ver. %s) uses queue %s" % (env, parsed["version"], parsed["queue"])
result.append(FillTemplate(lineTemplate, {"##TITLE##": env, "##URL##": url, "##COMMENT##": parsed["queue"], "##VERSION##": parsed["version"]}))
print "--- Publishing to wiki"
WriteFile("temp.tmp", FillTemplate(page, {"##CONSUMERS##": subscribers, "##QUEUES##": "".join(result), "##UPDATED##": datetime.datetime.today().strftime("%b %d, %Y (%H:%M)")}))
GetWiki({"action": "storePage", "space": config["project_space"], "title": "ActiveMQ queues utilization (autogenerated)", "file": "temp.tmp"})
os.remove("temp.tmp")