- Timestamp:
- Aug 12, 2010, 2:32:45 PM (14 years ago)
- Location:
- nodes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/gformat.py
r8317 r8319 28 28 ] 29 29 30 # Global variables uses 31 OK = 0 32 UNKNOWN = 1 33 DOWN = 2 30 34 31 35 … … 289 293 290 294 295 def 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 291 299 292 300 def get_used_ips(configs): 293 301 """ Return array of all IPs used in config files""" 294 302 ip_list = [] 295 for host,config in configs.iteritems():303 for config in configs: 296 304 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): 299 306 l = config[iface_key]['ip'] 300 307 addr, mask = l.split('/') -
nodes/status-monitoring.py
r8318 r8319 246 246 status = stored_status['nmap_status'] 247 247 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 248 258 # List of hosts which has some kind of problem 249 259 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 251 275 252 276 # Correlation mapping 253 277 for host, details in host_processed.iteritems(): 278 nodemap['node'][host] = gformat.OK 254 279 print "# Working on %s" % host 255 280 for ip, arpmac in details['arpmac'].iteritems(): … … 261 286 else: 262 287 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 264 293 265 294 def usage(): … … 310 339 if not opt_force_range: 311 340 configs = gformat.get_all_configs() 312 iplist = gformat.get_used_ips(configs )341 iplist = gformat.get_used_ips(configs.values()) 313 342 else: 314 343 iplist = sys.argv[1:] … … 330 359 nmap_status = stored_status['nmap_status'] 331 360 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 332 367 # Do SNMP discovery 333 368 if opt_snmp_scan: … … 335 370 else: 336 371 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 337 376 338 377 # Store changed data to disk
Note:
See TracChangeset
for help on using the changeset viewer.