From ea33bfb17aadcfc472fed77b0d5fa7c08430f8e8 Mon Sep 17 00:00:00 2001 From: richard lee Date: Wed, 20 Sep 2017 12:05:56 +0800 Subject: [PATCH] Created export volume info (markdown) --- export-volume-info.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 export-volume-info.md diff --git a/export-volume-info.md b/export-volume-info.md new file mode 100644 index 0000000..4b4caa7 --- /dev/null +++ b/export-volume-info.md @@ -0,0 +1,40 @@ +Sometime we may lose the replication of some volumes (disk failure or any other exception), this small script can help u dump all volumes info to csv files, and use your favorite tools to find the 'bad' volumes. + + +```python +import requests +from bs4 import BeautifulSoup +import json + +out = file('out.csv', 'w') + +// your weed master url +url = 'http://192.64.4.35:9333/' + + +s = requests.session() +res = s.get(url) +if res.status_code == 200: + soup = BeautifulSoup(res.content, 'html.parser') + for link in soup.find_all("a"): + if 'index.html' not in link['href']: + continue + # print link['href'] + res = s.get(link['href']) + if res.status_code == 200: + soup = BeautifulSoup(res.content, 'html.parser') + for volume in soup.find('tbody').find_all('tr'): + rows = volume.find_all('td') + // use any of your weed node, I deploy openresty before my weed cluster + res = s.get("http://192.xxx.xx.xx/dir/lookup?volumeId=%s&pretty=y" % rows[0].text) + result = [a.text for a in rows[:2]] + if res.status_code == 200: + json_data = res.json() + if 'locations' in json_data: + result.append(json.dumps(json_data['locations'])) + + dataline = ",".join(result) + print link['href'] + "," + dataline + out.write(link['href'] + "," + dataline) + out.write("\n") +``` \ No newline at end of file