Changeset 8328 in genesis for nodes/get-network-status.py


Ignore:
Timestamp:
Aug 12, 2010, 9:07:52 PM (14 years ago)
Author:
rick
Message:

Argument and 'flow' fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/get-network-status.py

    r8324 r8328  
    9090
    9191
    92 def do_nmap_scan(command, iphosts, result_file=None):
     92def do_nmap_scan(command, iphosts, result_file=None, forced_scan=False):
    9393  """ Wrapper around _run_nmap to get listing of all hosts, the default nmap
    9494      does not return results for failed hosts"""
     
    9797
    9898  # Return stored file if exists
    99   if result_file and os.path.exists(result_file) and os.path.getsize(result_file) > 0:
     99  if not forced_scan and result_file and os.path.exists(result_file)  \
     100    and os.path.getsize(result_file) > 0:
    100101    print "# Reading stored NMAP results from '%s'" % (result_file)
    101102    status = parse_nmap(parse(result_file))
     
    137138  #
    138139  # Gather SNMP data from hosts
    139   for host, scan in status.iteritems():
     140  for host in iphosts:
     141    # Status might be containing old hosts as well and visa-versa
     142    if not status.has_key(host):
     143       print "## [ERROR] No nmap result found"
     144       continue
     145
     146    scan = status[host]
    140147    if scan['state'] != "up":
    141       continue
    142    
    143     # Filter set? use it
    144     if iphosts and not host in iphosts:
    145       print "## IP '%s' not in specified filter" % host
    146148      continue
    147149 
     
    298300
    299301def usage():
    300     print "Usage: %s <all|force|stored|host HOST1 [HOST2 ...]>" % sys.argv[0]
     302    print "Usage: %s <arguments>"
     303    print "Arguments:"
     304    print "\tall         = scan all known ips, using cached nmap"
     305    print "\tnmap-only   = scan all known ips, using nmap only"
     306    print "\tsnmp-only   = scan all known ips, using snmp only"
     307    print "\tforce       = scan all known ips, no cache used"
     308    print "\tforced-snmp = scan all known ips, no snmp cache"
     309    print "\tstored      = generate status file using stored entries"
     310    print "\thost <HOST1> [HOST2 ...]  = generate status file using stored entries"
     311    print "\tmerge <FILE1> [FILE2 ...] = merge status file with other status files"
    301312    sys.exit(0)
    302313
     
    360371    if not opt_store_scan:
    361372      nmap_result_file = None
    362     nmap_status = do_nmap_scan("-p T:ssh,U:domain,T:80,T:ntp,U:snmp,T:8080 -sU -sT ",iplist, nmap_result_file)
     373    nmap_status = do_nmap_scan(
     374                   "-p T:ssh,U:domain,T:80,T:ntp,U:snmp,T:8080 -sU -sT ",
     375                   iplist,nmap_result_file, opt_force_scan)
     376
    363377  else:
    364378    nmap_status = stored_status['nmap_status']
Note: See TracChangeset for help on using the changeset viewer.