Exemple #1
0
def install():
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_directory = os.environ.get('PATTOO_CONFIGDIR')

    opcua_agent_dict = {
            'polling_interval': 300,
    }

    # Attempt to create configuration directory
    files.mkdir(config_directory)

    # Create the pattoo user and group
    configure.create_user('pattoo', '/nonexistent', ' /bin/false', True)

    # Attempt to change the ownership of the configuration directory
    shared.chown(config_directory)

    config_file = configure.pattoo_config(
                                        'pattoo_agent_opcuad',
                                        config_directory,
                                        opcua_agent_dict)

    configure.check_config(config_file, opcua_agent_dict)
Exemple #2
0
def install(pattoo_home):
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    bacnet_agent_dict = {
        'polling_interval': 300,
    }

    # Attempt to create configuration directory
    files.mkdir(config_dir)

    # Create the pattoo user and group
    if _shared.root_check() is True:
        # Create the pattoo user and group
        configure.create_user('pattoo', pattoo_home, '/bin/false', True)

        # Attempt to change the ownership of the config and home directories
        shared.chown(config_dir)
        shared.chown(pattoo_home)

    config_file = configure.pattoo_config('pattoo_agent_bacnetipd', config_dir,
                                          bacnet_agent_dict)

    configure.check_config(config_file, bacnet_agent_dict)
def install(daemon_list):
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    autonomousd_agent_dict = {
        'polling_interval': 300,
    }

    hubd_agent_dict = {
        'polling_interval': 300,
        'ip_targets': {
            'ip_address': '127:0.0.1',
            'ip_bind_port': 5000
        }
    }

    spoked_agent_dict = {
        'polling_interval': 300,
        'ip_listen_address': '127.0.0.1',
        'ip_bind_port': 5000
    }

    # Attempt to create configuration directory
    files.mkdir(config_dir)

    # Create the pattoo user and group
    configure.create_user('pattoo', '/nonexistent', ' /bin/false', True)

    # Attempt to change the ownership of the configuration directory
    shared.chown(config_dir)

    # Configure daemons in list regardless of order
    for daemon in daemon_list:
        # Configure autonomous agent
        if 'autonomousd' in daemon:
            configure.configure_component(daemon, config_dir,
                                          autonomousd_agent_dict)

        # Configure spoked agent
        elif 'spoked' in daemon:
            configure.configure_component(daemon, config_dir,
                                          spoked_agent_dict)

        # Convert hubd agents
        elif 'hubd' in daemon:
            configure.configure_component(daemon, config_dir, hubd_agent_dict)

        else:
            continue
Exemple #4
0
def pattoo_config(file_name, config_directory, config_dict):
    """Create configuration file.

    Args:
        file_name: Name of the configuration file without its file extension
        config_directory: Full path to the configuration directory
        config_dict: A dictionary containing the configuration values.

    Returns:
        The path to the configuration file

    """
    # Initialize key variables
    config_file = os.path.join(config_directory, '{}.yaml'.format(file_name))

    # Say what we are doing
    print('\nConfiguring {} file.\n'.format(config_file))

    # Get configuration
    config = read_config(config_file, config_dict)

    # Check validity of directories, if any
    if bool(config) is False:
        # Set default
        config = config_dict

    # Iterate over config dict
    for _, value in sorted(config.items()):
        if isinstance(value, dict) is True:
            for secondary_key in value.keys():
                if 'directory' in secondary_key:
                    if os.sep not in value.get(secondary_key):
                        log.log2die_safe(
                            1019, '{} is an invalid directory'.format(value))

                    # Attempt to create directory
                    full_directory = os.path.expanduser(
                        value.get(secondary_key))
                    if os.path.isdir(full_directory) is False:
                        print('Creating: {}'.format(full_directory))
                        files.mkdir(full_directory)

                    # Recursively set file ownership to pattoo user and group
                    if getpass.getuser() == 'root':
                        shared.chown(full_directory)

        # Write file
        try:
            f_handle = open(config_file, 'w')
        except PermissionError:
            log.log2die(
                1076, '''\
Insufficient permissions for creating the file:{}'''.format(config_file))
        else:
            with f_handle:
                yaml.dump(config, f_handle, default_flow_style=False)

    return config_file
Exemple #5
0
def install(pattoo_home):
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    pattoo_webd_dict = {
        'pattoo_webd': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20200,
        },
        'pattoo_web_api': {
            'ip_address': '::1',
            'ip_bind_port': 20202
        },
    }

    shared_config = {
        'pattoo': {
            'language': 'en',
            'log_directory': ('/var/log/pattoo'),
            'log_level': 'debug',
            'cache_directory': ('/opt/pattoo/cache'),
            'daemon_directory': ('/opt/pattoo/daemon'),
            'system_daemon_directory': '/var/run/pattoo',
        }
    }

    # Attempt to create configuration directory
    files.mkdir(config_dir)

    # Create the pattoo user and group
    configure.create_user('pattoo', pattoo_home, '/bin/false', True)

    # Attempt to change the ownership of the config and pattoo-home directories
    shared.chown(config_dir)
    shared.chown(pattoo_home)

    # Create pattoo configuration if pattoo had not been installed
    configure.configure_component('pattoo', config_dir, shared_config)

    # Configure pattoo web
    configure.configure_component('pattoo_webd', config_dir, pattoo_webd_dict)
Exemple #6
0
def install(pattoo_home):
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    pattoo_webd_dict = {
        'pattoo_webd': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20200,
        },
        'pattoo_web_api': {
            'ip_address': '::1',
            'ip_bind_port': 20202
        },
    }

    # Attempt to create configuration directory
    files.mkdir(config_dir)

    # Create the pattoo user and group
    configure.create_user('pattoo', pattoo_home, ' /bin/false', True)

    # Attempt to change the ownership of the config and pattoo-home directories
    shared.chown(config_dir)
    shared.chown(pattoo_home)

    # Configure pattoo web
    configure.configure_component('pattoo_webd', config_dir, pattoo_webd_dict)
Exemple #7
0
def install(daemon_list, pattoo_home):
    """Start configuration process.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    snmp_agent_dict = {
        'polling_interval': 300,
    }

    # Attempt to create configuration directory
    files.mkdir(config_dir)

    # Create the pattoo user and group
    if getpass.getuser() != 'travis':
        # Create the pattoo user and group
        configure.create_user('pattoo', pattoo_home, '/bin/false', True)

        # Attempt to change the ownership of the config and home directories
        shared.chown(config_dir)
        shared.chown(pattoo_home)

    # Attempt to change the ownership of the configuration directory
    shared.chown(config_dir)

    for daemon in daemon_list:
        config_file = configure.pattoo_config(daemon, config_dir,
                                              snmp_agent_dict)

        configure.check_config(config_file, snmp_agent_dict)
Exemple #8
0
def install(pattoo_home):
    """Start configuration process.

    Args:
        pattoo_home: The home directory of the pattoo user

    Returns:
        None
    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_directory = os.environ.get('PATTOO_CONFIGDIR')
    shared_config = {
        'encryption': {
            'api_email': '*****@*****.**',
        },
        'pattoo': {
            'language': 'en',
            'log_directory': ('/var/log/pattoo'),
            'log_level': 'debug',
            'cache_directory': ('/opt/pattoo-cache'),
            'daemon_directory': ('/opt/pattoo-daemon'),
            'system_daemon_directory': '/var/run/pattoo',
        }
    }

    agent_config = {
        'encryption': {
            'agent_email': '*****@*****.**'
        },
        'pattoo_agent_api': {
            'ip_address': '127.0.0.1',
            'ip_bind_port': 20201
        },
        'pattoo_web_api': {
            'ip_address': '127.0.0.1',
            'ip_bind_port': 20202,
        }
    }

    server_config = {
        'pattoo_db': {
            'db_pool_size': 10,
            'db_max_overflow': 20,
            'db_hostname': 'localhost',
            'db_username': '******',
            'db_password': '******',
            'db_name': 'pattoo'
        },
        'pattoo_api_agentd': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20201,
        },
        'pattoo_apid': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20202,
        },
        'pattoo_ingesterd': {
            'ingester_interval': 3600,
            'batch_size': 500,
            'graceful_timeout': 10
        }
    }

    # Attempt to create configuration directory
    files.mkdir(config_directory)

    if getpass.getuser() != 'travis':
        # Create the pattoo user and group
        configure.create_user('pattoo', pattoo_home, '/bin/false', True)

        # Attempt to change the ownership of the config and home directories
        shared.chown(config_directory)
        shared.chown(pattoo_home)

    # Create configuration
    configure.configure_component('pattoo', config_directory, shared_config)

    configure.configure_component('pattoo_agent', config_directory,
                                  agent_config)

    configure.configure_component('pattoo_server', config_directory,
                                  server_config)
Exemple #9
0
def install(pattoo_home):
    """Start configuration process.

    Args:
        pattoo_home: The home directory of the pattoo user

    Returns:
        None
    """
    # Initialize key variables
    if os.environ.get('PATTOO_CONFIGDIR') is None:
        os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
    config_directory = os.environ.get('PATTOO_CONFIGDIR')
    shared_config = {
        'pattoo': {
            'language': 'en',
            'log_directory': (
                '/var/log/pattoo'),
            'log_level': 'debug',
            'cache_directory': (
                '/opt/pattoo/cache'),
            'daemon_directory': (
                '/opt/pattoo/daemon'),
            'system_daemon_directory': '/var/run/pattoo',
        }
    }

    # Defines how agents will communicate with the API daemons
    # Only required for travis-ci unittesting
    agent_config = {
        'pattoo_agent_api': {
            'ip_address': '127.0.0.1',
            'ip_bind_port': 20201
        },
    }

    server_config = {
        'pattoo_db': {
            'db_pool_size': 10,
            'db_max_overflow': 20,
            'db_hostname': 'localhost',
            'db_username': '******',
            'db_password': '******',
            'db_name': 'pattoo'
        },
        'pattoo_api_agentd': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20201,
            'api_encryption_email': '*****@*****.**',
        },
        'pattoo_apid': {
            'ip_listen_address': '0.0.0.0',
            'ip_bind_port': 20202,
            'jwt_secret_key': secrets.token_urlsafe(64),
            'acesss_token_exp': '15_m',
            'refresh_token_exp': '1_D'
        },
        'pattoo_ingesterd': {
            'ingester_interval': 3600,
            'batch_size': 500,
            'graceful_timeout': 10
        }
    }

    # Attempt to create configuration directory
    files.mkdir(config_directory)

    if _shared.root_check() is True:
        # Create the pattoo user and group
        configure.create_user('pattoo', pattoo_home, '/bin/false', True)

        # Attempt to change the ownership of the config and home directories
        shared.chown(config_directory)
        shared.chown(pattoo_home)

    # Create configuration
    configure.configure_component('pattoo', config_directory, shared_config)

    configure.configure_component(
        'pattoo_server', config_directory, server_config)

    configure.configure_component(
        'pattoo_agent', config_directory, agent_config)