Changeset 8319 in genesis for nodes/status-monitoring.py


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

Initial status output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.