def handle(self, *args, **kwargs): if not args: raise SystemExit("Please specify the addresses to scan.") try: addresses = [str(ipaddr.IPAddress(ip)) for ip in args] except ValueError as e: raise SystemExit(e) plugins = [ 'ralph.scan.plugins.snmp_macs', 'ralph.scan.plugins.snmp_f5', 'ralph.scan.plugins.idrac', 'ralph.scan.plugins.ssh_linux', 'ralph.scan.plugins.puppet', 'ralph.scan.plugins.ssh_ibm_bladecenter', 'ralph.scan.plugins.hp_oa', 'ralph.scan.plugins.ssh_cisco_asa', 'ralph.scan.plugins.ssh_cisco_catalyst', 'ralph.scan.plugins.ipmi', 'ralph.scan.plugins.http_supermicro', 'ralph.scan.plugins.ilo_hp', 'ralph.scan.plugins.ssh_cisco_asa', 'ralph.scan.plugins.ssh_cisco_catalyst', 'ralph.scan.plugins.ssh_proxmox', 'ralph.scan.plugins.ssh_3par', 'ralph.scan.plugins.ssh_ssg', 'ralph.scan.plugins.ssh_ganeti', 'ralph.scan.plugins.ssh_xen', 'ralph.scan.plugins.ssh_aix', 'ralph.scan.plugins.ssh_onstor', 'ralph.scan.plugins.http_ibm_system_x', 'ralph.scan.plugins.ssh_hp_p2000', 'ralph.scan.plugins.ssh_hp_msa', 'ralph.scan.plugins.software', ] if kwargs["plugins"]: new_plugins = map( lambda s: 'ralph.scan.plugins.{}'.format(s), kwargs["plugins"].split(","), ) plugins = filter(lambda plug: plug in new_plugins, plugins) last_message = 0 for address in addresses: job = scan_address(address, plugins) while not job.is_finished: job.refresh() print('Progress: %d/%d plugins' % (len(job.meta.get('finished', [])), len(plugins))) last_message = print_job_messages(job, last_message) if job.is_failed: raise SystemExit(job.exc_info) time.sleep(5) last_message = print_job_messages(job, last_message) print(json.dumps(job.result))
def handle(self, *args, **kwargs): if not args: raise SystemExit("Please specify the addresses to scan.") try: addresses = [str(ipaddr.IPAddress(ip)) for ip in args] except ValueError as e: raise SystemExit(e) plugins = [ 'ralph.scan.plugins.snmp_macs', 'ralph.scan.plugins.snmp_f5', 'ralph.scan.plugins.idrac', 'ralph.scan.plugins.ssh_linux', 'ralph.scan.plugins.puppet', 'ralph.scan.plugins.ssh_ibm_bladecenter', 'ralph.scan.plugins.hp_oa', 'ralph.scan.plugins.ssh_cisco_asa', 'ralph.scan.plugins.ssh_cisco_catalyst', 'ralph.scan.plugins.ipmi', 'ralph.scan.plugins.http_supermicro', 'ralph.scan.plugins.ilo_hp', 'ralph.scan.plugins.ssh_cisco_asa', 'ralph.scan.plugins.ssh_cisco_catalyst', 'ralph.scan.plugins.ssh_proxmox', 'ralph.scan.plugins.ssh_3par', 'ralph.scan.plugins.ssh_ssg', 'ralph.scan.plugins.ssh_ganeti', 'ralph.scan.plugins.ssh_xen', 'ralph.scan.plugins.ssh_aix', 'ralph.scan.plugins.ssh_onstor', 'ralph.scan.plugins.http_ibm_system_x', 'ralph.scan.plugins.ssh_hp_p2000', 'ralph.scan.plugins.ssh_hp_msa', 'ralph.scan.plugins.software', ] if kwargs["plugins"]: new_plugins = map(lambda s: 'ralph.scan.plugins.{}'.format(s), kwargs["plugins"].split(","), ) plugins = filter(lambda plug: plug in new_plugins, plugins) last_message = 0 for address in addresses: job = scan_address(address, plugins) while not job.is_finished: job.refresh() print('Progress: %d/%d plugins' % (len(job.meta.get('finished', [])), len(plugins))) last_message = print_job_messages(job, last_message) if job.is_failed: raise SystemExit(job.exc_info) time.sleep(5) last_message = print_job_messages(job, last_message) print(json.dumps(job.result))
def handle(self, *args, **kwargs): options_sum = sum([ kwargs['network'], kwargs['data_center'], kwargs['environment'], kwargs['queue'], ]) if options_sum > 1: raise SystemExit( "You can't mix networks, environments, data centers and " "queues.", ) if not args and options_sum == 0: raise SystemExit("Please specify the IP address to scan.") plugins = getattr(settings, 'SCAN_PLUGINS', {}).keys() verbose = kwargs['verbose'] if kwargs["plugins"]: new_plugins = map( lambda s: 'ralph.scan.plugins.{}'.format(s), kwargs["plugins"].split(","), ) plugins = filter(lambda plug: plug in new_plugins, plugins) if kwargs['network']: try: for network in [ find_network(network_spec) for network_spec in args ]: scan_network(network, plugins) except (Error, Network.DoesNotExist) as e: raise SystemExit(e) elif kwargs['environment']: try: for environment in [ Environment.objects.get(name=name) for name in args ]: scan_environment(environment, plugins) except (Error, Environment.DoesNotExist) as e: raise SystemExit(e) elif kwargs['data_center']: try: for data_center in [ DataCenter.objects.get(name=name) for name in args ]: for environment in data_center.environment_set.filter( queue__isnull=False, ): scan_environment(environment, plugins) except (Error, DataCenter.DoesNotExist) as e: raise SystemExit(e) elif kwargs['queue']: try: for queue in [ DiscoveryQueue.objects.get(name=name) for name in args ]: for environment in queue.environment_set.all(): scan_environment(environment, plugins) except (Error, DiscoveryQueue.DoesNotExist) as e: raise SystemExit(e) else: try: ip_addresses = [unicode(ipaddr.IPAddress(ip)) for ip in args] except ValueError as e: raise SystemExit(e) else: last_message = 0 for ip_address in ip_addresses: job = scan_address(ip_address, plugins) while not job.is_finished: job.refresh() last_message = print_job_messages( job, last_message, verbose) if job.is_failed: raise SystemExit(job.exc_info) time.sleep(1) print('\nAll done!') for plugin_name, job_result in job.result.iteritems(): if job_result.get('status') == 'success': if not verbose: print('Success: ', plugin_name) else: print('-' * 40) print('Successful plugin: ' + plugin_name) print('Result data:') pprint.pprint(job_result.get('device', ''))