def check(): """Ensure PIP3 packages are installed correctly. Args: None Returns: None """ # Initialize key variables config_directory = os.environ['PATTOO_CONFIGDIR'] # Print Status print('??: Checking configuration parameters.') # Check config (pattoo.yaml) config_file = configuration.agent_config_filename('pattoo') config = files.read_yaml_file(config_file) # Check main keys keys = ['pattoo', 'pattoo_web_api', 'pattoo_agent_api'] for key in keys: if key not in config: log_message = ('''\ Section "{}" not found in configuration file in directory {}. Please fix.\ '''.format(key, config_directory)) log.log2die_safe(80007, log_message) # Check secondary keys secondaries = [ 'log_level', 'log_directory', 'cache_directory', 'daemon_directory' ] secondary_key_check(config, 'pattoo', secondaries) secondaries = ['ip_address', 'ip_bind_port'] secondary_key_check(config, 'pattoo_agent_api', secondaries) secondaries = ['ip_address', 'ip_bind_port'] secondary_key_check(config, 'pattoo_web_api', secondaries) # Check config (pattoo_webd.yaml) config_file = configuration.agent_config_filename('pattoo_webd') config = files.read_yaml_file(config_file) # Check main keys keys = ['pattoo_webd'] for key in keys: if key not in config: log_message = ('''\ Section "{}" not found in configuration file in directory {}. Please fix.\ '''.format(key, config_directory)) log.log2die_safe(80020, log_message) # Check secondary keys secondaries = ['ip_listen_address', 'ip_bind_port'] secondary_key_check(config, 'pattoo_webd', secondaries) # Print Status print('OK: Configuration parameter check passed.')
def check_config(config_file, config_dict): """Ensure agent configuration exists. Args: config: The name of the configuration file config_dict: A dictionary containing the primary configuration keys and a list of the secondary keys Returns: None """ # Initialize key variables config_directory = os.environ['PATTOO_CONFIGDIR'] # Print Status print('??: Checking configuration parameters.') # Retrieve config dict config = files.read_yaml_file(config_file) # Check main keys for primary in config_dict: if primary not in config: log_message = ('''\ Section "{}" not found in configuration file {} in directory {}. Please fix.\ '''.format(primary, config_file, config_directory)) log.log2die_safe(1055, log_message) # Print Status print('OK: Configuration parameter check passed.')
def check_pattoo_client(): """Ensure client configuration exists. Args: None Returns: True: if the client has been configured correctly """ # Print Status print('Checking client configuration parameters.') # Checks client config config_file = configuration.agent_config_filename('pattoo') config = files.read_yaml_file(config_file) # Check main keys keys = ['pattoo'] for key in keys: if key not in config: log_message = ('''\ Section "{}" not found in {} configuration file. Please fix.\ '''.format(key, config_file)) log.log2die_safe(20090, log_message) # Check secondary keys for 'pattoo' secondaries = [ 'log_level', 'log_directory', 'cache_directory', 'daemon_directory' ] secondary_key_check(config, 'pattoo', secondaries) # Print Status return True
def test_read_yaml_file(self): """Testing function read_yaml_file.""" # Initializing key variables dict_1 = { 'key1': 1, 'key2': 2, 'key3': 3, 'key4': 4, } # Create a temporary file without a json extension and test tmp = tempfile.NamedTemporaryFile(delete=False) with self.assertRaises(SystemExit): _ = files.read_yaml_file(tmp.name) os.remove(tmp.name) # Create temp file with known data directory = tempfile.mkdtemp() file_data = [(('{}{}file_1.yaml').format(directory, os.sep), dict_1)] for item in file_data: filename = item[0] data_dict = item[1] with open(filename, 'w') as filehandle: yaml.dump(data_dict, filehandle, default_flow_style=False) # Get Results result = files.read_yaml_file(filename) # Test equivalence for key in result.keys(): self.assertEqual(data_dict[key], result[key]) # Clean up filelist = [ next_file for next_file in os.listdir(directory) if next_file.endswith('.yaml') ] for delete_file in filelist: delete_path = ('{}{}{}').format(directory, os.sep, delete_file) os.remove(delete_path) os.removedirs(directory)
def __init__(self): """Initialize the class. Args: None Returns: None """ # Instantiate inheritance BaseConfig.__init__(self) # Get the configuration directory config_file = agent_config_filename(PATTOO_WEBD_NAME) self._daemon_configuration = files.read_yaml_file(config_file)
def __init__(self): """Initialize the class. Args: None Returns: None """ # Instantiate inheritance Config.__init__(self) # Get the configuration directory config_file = configuration.agent_config_filename(PATTOO_AGENT_SNMPD) self._agent_config = files.read_yaml_file(config_file)
def check_pattoo_server(): """Ensure server configuration exists. Args: None Returns: None """ # Print Status print('??: Checking server configuration parameters.') ########################################################################### # Check server config ########################################################################### config_file = configuration.agent_config_filename('pattoo_server') config = files.read_yaml_file(config_file) # Check main keys keys = [ 'pattoo_db', 'pattoo_api_agentd', 'pattoo_apid', 'pattoo_ingesterd' ] for key in keys: if key not in config: log_message = ('''\ Section "{}" not found in {} configuration file. Please fix.\ '''.format(key, config_file)) log.log2die_safe(20141, log_message) # Check secondary keys for 'pattoo_db' secondaries = [ 'db_pool_size', 'db_max_overflow', 'db_hostname', 'db_username', 'db_password', 'db_name' ] secondary_key_check(config, 'pattoo_db', secondaries) # Check secondary keys for 'pattoo_api_agentd' secondaries = ['ip_listen_address', 'ip_bind_port'] secondary_key_check(config, 'pattoo_api_agentd', secondaries) # Check secondary keys for 'pattoo_apid' secondaries = ['ip_listen_address', 'ip_bind_port'] secondary_key_check(config, 'pattoo_apid', secondaries) # Print Status print('OK: Server configuration parameter check passed.')
def _config_reader(filename): """Read a configuration file. Args: filename: Name of file to read Returns: config_dict: Dict representation of YAML in the file """ # Get the configuration directory # Expand linux ~ notation for home directories if provided. _config_directory = log.check_environment() config_directory = os.path.expanduser(_config_directory) config_file = '{}{}{}'.format(config_directory, os.sep, filename) config_dict = files.read_yaml_file(config_file) return config_dict
def get_ports(config_path): """Get the ip bind ports from the configuration file. Args: config_path: The path to the configuration file being read Returns: ports: A list of the ip bind ports to be exposed in docker """ # Initialize key variables config_dict = files.read_yaml_file(config_path) ports = [] # Retrieve bind ports from config dict if config_dict is not None: for key in config_dict: bind_port = config_dict.get(key).get('ip_bind_port') if bind_port is not None: ports.append(bind_port) return ports