Guest User

Untitled

a guest
Feb 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. import commands
  2. from datetime import date
  3. print "Fetching data..."
  4. 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"')
  5. tdn_list = commands.getoutput('echo -e "status_all_tdns" | nc -w 2 tds11 1180 | awk \'{print $2" "$13}\' | tr -d "group=" | sed 1d')
  6.  
  7. print "Processing data..."
  8. def parse_servers(data):
  9.     collection = {}
  10.  
  11.     for d in data.split("\n"):
  12.         vals = d.split(" ")
  13.  
  14.         if not vals[0]:
  15.             continue
  16.  
  17.         group = vals[1]
  18.         server = vals[0]
  19.  
  20.         collection[group] = { server: [] }
  21.  
  22.     return collection
  23.  
  24.  
  25. def parse_hds(data, collection):
  26.     data = data.split("\n")
  27.     hard_drives = []
  28.     for hds in data:
  29.         if hds:
  30.             hard_drives.append(hds.split(" "))
  31.  
  32.     for group, servers in collection.items():
  33.         for server, hds in servers.items():
  34.             for assoc in hard_drives:
  35.                 if assoc[0] == server:
  36.                     collection[group][server].append(assoc[1])
  37.  
  38.     return collection
  39.  
  40. def return_problemhds(data):
  41.     group_bad_hds = { }
  42.     for group, servers in data.items():
  43.         for server, hds in servers.items():
  44.             group_bad_hds[group] = group_bad_hds.get(group. [ ]) + hds
  45.    
  46.     today = date.today().strftime("%Y-%m-%d")
  47.     return { today : group_bad_hds }
  48.  
  49. if __name__ == "__main__":
  50.     group_server_list = parse_servers(tdn_list)
  51.     final_list = parse_hds(hd_list, group_server_list)
  52.     problem_hds = return_problemhds(final_list)
Add Comment
Please, Sign In to add comment