Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import commands
- from datetime import date
- print "Fetching data..."
- hd_list = commands.getoutput('/home/jeremyf/working/python/nfs_check.sh fetch-replace all | awk \'{if ($19 == "id:") print $4" "$20; else if ($20 == "id:") print $4" "$21}\' | grep tdn | tr -d "tdn"')
- tdn_list = commands.getoutput('echo -e "status_all_tdns" | nc -w 2 tds11 1180 | awk \'{print $2" "$13}\' | tr -d "group=" | sed 1d')
- print "Processing data..."
- def parse_servers(data):
- collection = {}
- for d in data.split("\n"):
- vals = d.split(" ")
- if not vals[0]:
- continue
- group = vals[1]
- server = vals[0]
- collection[group] = { server: [] }
- return collection
- def parse_hds(data, collection):
- data = data.split("\n")
- hard_drives = []
- for hds in data:
- if hds:
- hard_drives.append(hds.split(" "))
- for group, servers in collection.items():
- for server, hds in servers.items():
- for assoc in hard_drives:
- if assoc[0] == server:
- collection[group][server].append(assoc[1])
- return collection
- def return_problemhds(data):
- group_bad_hds = { }
- for group, servers in data.items():
- for server, hds in servers.items():
- group_bad_hds[group] = group_bad_hds.get(group. [ ]) + hds
- today = date.today().strftime("%Y-%m-%d")
- return { today : group_bad_hds }
- if __name__ == "__main__":
- group_server_list = parse_servers(tdn_list)
- final_list = parse_hds(hd_list, group_server_list)
- problem_hds = return_problemhds(final_list)
Add Comment
Please, Sign In to add comment