- Timestamp:
- Mar 6, 2012, 1:17:56 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/get-link-traffic.py
r9988 r10035 2 2 # 3 3 # XXX: Parsing snmpwalk is soo wrong todo, use a proper python library. 4 # 4 5 # 5 6 # Rick van der Zwet <info@rickvanderzwet.nl> … … 59 60 return None 60 61 61 62 63 62 try: 64 63 ff = sys.argv[1] … … 66 65 ff = '' 67 66 68 def process_file(logger, store, nf, rescan):67 def process_file(logger, m_snmp, m_traffic, m_uptime, nf, rescan): 69 68 data = yaml.load(open(nf,'r')) 70 69 nodename = data['nodename'] 71 70 72 if store['snmp'].has_key(nodename):73 ip = store['snmp'][nodename]71 if m_snmp.has_key(nodename): 72 ip = m_snmp[nodename] 74 73 if not ip and rescan: 75 74 logger.info("Re-scanning for new valid IP") 76 75 ip = find_right_snmp_ip(logger, data) 77 store['snmp'][nodename] = ip76 m_snmp[nodename] = ip 78 77 else: 79 78 try: … … 82 81 logger.info("Re-scanning for new valid IP") 83 82 ip = find_right_snmp_ip(logger, data) 84 store['snmp'][nodename] = ip 85 83 m_snmp[nodename] = ip 86 84 else: 87 85 logger.info("Running discovery for %s", nodename) 88 86 ip = find_right_snmp_ip(logger, data) 89 store['snmp'][nodename] = ip87 m_snmp[nodename] = ip 90 88 91 89 if ip == None: 92 90 logger.error("No valid ip found for node %s", nodename) 93 91 return 94 92 95 93 logger.info("Processing %s via %s", nodename, ip) 96 94 target = 'IF-MIB::ifDescr' 97 95 98 96 try: 99 97 iface = get_snmp_stats(logger, ip, 'IF-MIB::ifDescr') … … 102 100 103 101 uptime = get_snmp_value(logger, ip, 'DISMAN-EVENT-MIB::sysUpTimeInstance') 104 store['uptime'][nodename] = int(uptime)105 102 m_uptime[nodename] = int(uptime) 103 106 104 traffic = {} 107 105 for i,f in iface.iteritems(): 108 106 traffic[f] = (int(ifin[i]), int(ifout[i])) 109 store['traffic'][nodename] = traffic107 m_traffic[nodename] = traffic 110 108 except ConnectError: 111 109 logger.error("Unable to get all data") 112 110 pass 113 111 114 def worker(i, input, m_s tore):112 def worker(i, input, m_snmp, m_traffic, m_uptime): 115 113 logger = logging.getLogger('Worker%s' % i) 116 114 logger.info("Worker") 117 115 for (nf, rescan) in iter(input.get, 'STOP'): 118 process_file(logger, m_s tore, nf, rescan)116 process_file(logger, m_snmp, m_traffic, m_uptime, nf, rescan) 119 117 logger.info("END") 120 118 … … 129 127 store = { 'snmp' : {}, 'traffic' : {}, 'uptime' : {}} 130 128 pass 131 m_store = manager.dict(store) 129 # XXX: Manager.dict has bug of handling dicts inside dicts, using awefull quick 130 # XXX: http://bugs.python.org/issue6766 131 m_snmp = manager.dict(store['snmp']) 132 m_traffic = manager.dict(store['traffic']) 133 m_uptime = manager.dict(store['uptime']) 132 134 133 135 NUMBER_OF_PROCESSES = 10 … … 135 137 plist = {} 136 138 for i in range(NUMBER_OF_PROCESSES): 137 plist[i] = Process(target=worker, args=(i, task_queue,m_s tore))139 plist[i] = Process(target=worker, args=(i, task_queue,m_snmp,m_traffic,m_uptime)) 138 140 plist[i].start() 139 141 140 142 for nf in sorted(glob.glob('nodes/*%s*/wleiden.yaml' % ff)): 141 143 task_queue.put((nf, RESCAN)) 142 144 143 145 for i in range(NUMBER_OF_PROCESSES): 144 146 task_queue.put('STOP') … … 147 149 plist[i].join() 148 150 149 151 store = {'snmp' : dict(m_snmp), 'traffic' : dict(m_traffic), 'uptime' : dict(m_uptime)} 150 152 yaml.dump(store,open(DATASTORE,'w')) 151 153
Note:
See TracChangeset
for help on using the changeset viewer.