def do_test(cli_args, config): """Process 'test' CLI option. Args: connectivity_check: Set if testing for connectivity Returns: None """ # Show host information validate = snmp_manager.Validate(cli_args.host, config.snmp_auth()) snmp_params = validate.credentials() if bool(snmp_params) is True: print('\nValid credentials found:\n') print(yaml.dump(snmp_params, default_flow_style=False)) print('\n') # Get SNMP data status = snmp_info.Query(snmp_params) data = status.everything() # Pring result as YAML yaml_string = jm_general.dict2yaml(data) print(yaml_string) else: # Error, host problems log_message = ('Uncontactable host %s or no valid SNMP ' 'credentials found for it.') % (cli_args.host) jm_general.logit(1006, log_message)
def do_test(cli_args, config): """Process 'test' CLI option. Args: connectivity_check: Set if testing for connectivity Returns: None """ # Show host information validate = snmp_manager.Validate(cli_args.host, config.snmp_auth()) snmp_params = validate.credentials() if bool(snmp_params) is True: print('\nValid credentials found:\n') print(yaml.dump(snmp_params, default_flow_style=False)) print('\n') # Get SNMP data status = snmp_info.Query(snmp_params) data = status.everything() # Pring result as YAML yaml_string = jm_general.dict2yaml(data) print(yaml_string) else: # Error, host problems log_message = ( 'Uncontactable host %s or no valid SNMP ' 'credentials found for it.') % (cli_args.host) jm_general.logit(1006, log_message)
def test_dict2yaml(self): """Testing method / function dict2yaml.""" # Initializing key variables data_dict = { '1': 'test 1', 'two': 'test 2' } data_yaml = """'1': test 1 two: test 2 """ # Do test with good dict yaml_result = testimport.dict2yaml(data_dict) self.assertEqual(yaml_result, data_yaml)
def run(self): """Update the database using threads.""" while True: # Get the data_dict data_dict = self.queue.get() host = data_dict['host'] config = data_dict['config'] verbose = data_dict['verbose'] temp_dir = data_dict['temp_dir'] # Show host information validate = snmp_manager.Validate(host, config.snmp_auth()) snmp_params = validate.credentials() snmp_object = snmp_manager.Interact(snmp_params) # Verbose output if verbose is True: output = ('Processing on: host %s') % (host) print(output) # Skip invalid, and uncontactable hosts if bool(snmp_params) is False: if verbose is True: log_message = ( 'Uncontactable host %s or no valid SNMP ' 'credentials found for it.') % (host) jm_general.logit(1019, log_message, False) continue # Process if valid if bool(snmp_params) is True: # Get data status = snmp_info.Query(snmp_object) data = status.everything() yaml_string = jm_general.dict2yaml(data) # Dump data temp_file = ('%s/%s.yaml') % (temp_dir, host) with open(temp_file, 'w') as file_handle: file_handle.write(yaml_string) # Verbose output if verbose is True: output = ('Completed run: host %s') % (host) print(output) # Signals to queue job is done self.queue.task_done()
def run(self): """Update the database using threads.""" while True: # Get the data_dict data_dict = self.queue.get() host = data_dict['host'] config = data_dict['config'] verbose = data_dict['verbose'] temp_dir = data_dict['temp_dir'] # Show host information validate = snmp_manager.Validate(host, config.snmp_auth()) snmp_params = validate.credentials() # Verbose output if verbose is True: output = ('Processing on: host %s') % (host) print(output) # Skip invalid, and uncontactable hosts if bool(snmp_params) is False: if verbose is True: log_message = ('Uncontactable host %s or no valid SNMP ' 'credentials found for it.') % (host) jm_general.logit(1019, log_message, False) continue # Process if valid if bool(snmp_params) is True: # Get data status = snmp_info.Query(snmp_params) data = status.everything() yaml_string = jm_general.dict2yaml(data) # Dump data temp_file = ('%s/%s.yaml') % (temp_dir, host) with open(temp_file, 'w') as file_handle: file_handle.write(yaml_string) # Verbose output if verbose is True: output = ('Completed run: host %s') % (host) print(output) # Signals to queue job is done self.queue.task_done()