Changeset 8319 in genesis for nodes


Ignore:
Timestamp:
Aug 12, 2010, 2:32:45 PM (14 years ago)
Author:
rick
Message:

Initial status output

Location:
nodes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nodes/gformat.py

    r8317 r8319  
    2828    ]
    2929
     30# Global variables uses
     31OK = 0
     32UNKNOWN = 1
     33DOWN = 2
    3034
    3135
     
    289293
    290294
     295def get_interface_keys(config):
     296  """ Quick hack to get all interface keys, later stage convert this to a iterator """
     297  return [elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
     298
    291299
    292300def get_used_ips(configs):
    293301    """ Return array of all IPs used in config files"""
    294302    ip_list = []
    295     for host,config in configs.iteritems():
     303    for config in configs:
    296304      ip_list.append(config['masterip'])
    297       iface_keys = [elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
    298       for iface_key in iface_keys:
     305      for iface_key in get_interface_keys(config):
    299306        l = config[iface_key]['ip']
    300307        addr, mask = l.split('/')
  • nodes/status-monitoring.py

    r8318 r8319  
    246246  status = stored_status['nmap_status']
    247247
     248  # Data store format used for nodemap generation
     249  nodemap_status_file = '/tmp/nodemap_status.yaml'
     250  nodemap = { 'node' : {}, 'link' : {}}
     251
     252  # XXX: Pushed back till we actually store the MAC in the config files automatically
     253  #configmac_to_host = dict()
     254  #for host,config in configs.iteritems():
     255  #  for iface_key in gformat.get_interface_keys(config):
     256  #    configmac_to_host[config[iface_key]['mac']] = host
     257
    248258  # List of hosts which has some kind of problem
    249259  for host in list(set(configs.keys()) - set(host_processed.keys())):
    250      print "# Problem in host '%s'" % host
     260     config = configs[host]
     261     print "# Problems in host '%s'" % host
     262     host_down = True
     263     for ip in gformat.get_used_ips([config]):
     264       if status[ip]['state'] == "up":
     265         host_down = False
     266       print "## -  ", ip, status[ip]['state']
     267     if host_down:
     268       print "## HOST is DOWN!"
     269       nodemap['node'][host] = gformat.DOWN
     270     else:
     271       print "## SNMP problems (not reachable, deamon not running, etc)"
     272       nodemap['node'][host] = gformat.UNKNOWN
     273
     274       
    251275
    252276  # Correlation mapping
    253277  for host, details in host_processed.iteritems():
     278    nodemap['node'][host] = gformat.OK
    254279    print "# Working on %s" % host
    255280    for ip, arpmac in details['arpmac'].iteritems():
     
    261286      else:
    262287        print "## Interlink %s - %s"  % (host, mac_to_host[arpmac])
    263 
     288        nodemap['link'][(host,mac_to_host[arpmac])] = gformat.OK
     289
     290  stream = file(nodemap_status_file,'w')
     291  yaml.dump(nodemap, stream, default_flow_style=False)
     292  print "# Wrote nodemap status to '%s'" % nodemap_status_file
    264293
    265294def usage():
     
    310339  if not opt_force_range:
    311340    configs = gformat.get_all_configs()
    312     iplist = gformat.get_used_ips(configs)
     341    iplist = gformat.get_used_ips(configs.values())
    313342  else:
    314343    iplist = sys.argv[1:]
     
    330359    nmap_status = stored_status['nmap_status']
    331360
     361  # Save the MAC -> HOST mappings, by default as it helps indentifing the
     362  # 'unknown links'
     363  mac_to_host = {}
     364  if stored_status:
     365     mac_to_host = stored_status['mac_to_host']
     366
    332367  # Do SNMP discovery
    333368  if opt_snmp_scan:
     
    335370  else:
    336371    snmp_status = stored_status
     372
     373  # Include our saved MAC -> HOST mappings
     374  mac_to_host.update(snmp_status['mac_to_host'])
     375  snmp_status['mac_to_host'] = mac_to_host
    337376 
    338377  # Store changed data to disk
Note: See TracChangeset for help on using the changeset viewer.