Changeset 10035 in genesis for tools/get-link-traffic.py


Ignore:
Timestamp:
Mar 6, 2012, 1:17:56 PM (13 years ago)
Author:
rick
Message:

MultiManager dict is buggy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/get-link-traffic.py

    r9988 r10035  
    22#
    33# XXX: Parsing snmpwalk is soo wrong todo, use a proper python library.
     4#
    45#
    56# Rick van der Zwet <info@rickvanderzwet.nl>
     
    5960  return None
    6061
    61    
    62 
    6362try:
    6463  ff = sys.argv[1]
     
    6665  ff = ''
    6766
    68 def process_file(logger, store, nf, rescan):
     67def process_file(logger, m_snmp, m_traffic, m_uptime, nf, rescan):
    6968  data = yaml.load(open(nf,'r'))
    7069  nodename = data['nodename']
    7170
    72   if store['snmp'].has_key(nodename):
    73     ip = store['snmp'][nodename]
     71  if m_snmp.has_key(nodename):
     72    ip = m_snmp[nodename]
    7473    if not ip and rescan:
    7574      logger.info("Re-scanning for new valid IP")
    7675      ip = find_right_snmp_ip(logger, data)
    77       store['snmp'][nodename] = ip
     76      m_snmp[nodename] = ip
    7877    else:
    7978      try:
     
    8281        logger.info("Re-scanning for new valid IP")
    8382        ip = find_right_snmp_ip(logger, data)
    84         store['snmp'][nodename] = ip
    85      
     83        m_snmp[nodename] = ip
    8684  else:
    8785    logger.info("Running discovery for %s", nodename)
    8886    ip = find_right_snmp_ip(logger, data)
    89     store['snmp'][nodename] = ip
     87    m_snmp[nodename] = ip
    9088
    9189  if ip == None:
    9290    logger.error("No valid ip found for node %s", nodename)
    9391    return
    94  
     92
    9593  logger.info("Processing %s via %s", nodename, ip)
    9694  target = 'IF-MIB::ifDescr'
    97  
     95
    9896  try:
    9997    iface = get_snmp_stats(logger, ip, 'IF-MIB::ifDescr')
     
    102100
    103101    uptime = get_snmp_value(logger, ip, 'DISMAN-EVENT-MIB::sysUpTimeInstance')
    104     store['uptime'][nodename] = int(uptime)
    105    
     102    m_uptime[nodename] = int(uptime)
     103
    106104    traffic = {}
    107105    for i,f in iface.iteritems():
    108106      traffic[f] = (int(ifin[i]), int(ifout[i]))
    109     store['traffic'][nodename] = traffic
     107    m_traffic[nodename] = traffic
    110108  except ConnectError:
    111109    logger.error("Unable to get all data")
    112110    pass
    113111
    114 def worker(i, input, m_store):
     112def worker(i, input, m_snmp, m_traffic, m_uptime):
    115113  logger = logging.getLogger('Worker%s' % i)
    116114  logger.info("Worker")
    117115  for (nf, rescan) in iter(input.get, 'STOP'):
    118     process_file(logger, m_store, nf, rescan)
     116    process_file(logger, m_snmp, m_traffic, m_uptime, nf, rescan)
    119117  logger.info("END")
    120118
     
    129127    store = { 'snmp' : {}, 'traffic' : {}, 'uptime' : {}}
    130128    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'])
    132134
    133135  NUMBER_OF_PROCESSES = 10
     
    135137  plist = {}
    136138  for i in range(NUMBER_OF_PROCESSES):
    137     plist[i] = Process(target=worker, args=(i, task_queue,m_store))
     139    plist[i] = Process(target=worker, args=(i, task_queue,m_snmp,m_traffic,m_uptime))
    138140    plist[i].start()
    139141
    140142  for nf in sorted(glob.glob('nodes/*%s*/wleiden.yaml' % ff)):
    141143    task_queue.put((nf, RESCAN))
    142  
     144
    143145  for i in range(NUMBER_OF_PROCESSES):
    144146    task_queue.put('STOP')
     
    147149    plist[i].join()
    148150
    149 
     151  store = {'snmp' : dict(m_snmp), 'traffic' : dict(m_traffic), 'uptime' : dict(m_uptime)}
    150152  yaml.dump(store,open(DATASTORE,'w'))
    151153
Note: See TracChangeset for help on using the changeset viewer.