Example #1
0
    def check_socket_path(self, path):
        if path is None:
            return False
        # if it begins with ~ then do expand user

        if self.os == config.DEBIAN:
            socket_re = re.match(
                r'mysqld.sock$|(~/|/)(.*/)*mysqld.sock$', path)
        if self.os == config.REDHAT:
            socket_re = re.match(
                r'mysql.sock$|(~/|/)(.*/)*mysql.sock$', path)

        if socket_re is None:
            utils.eprint(
                'Invalid path was given.\n'
                ' -filename has to end with .sock.\n'
                ' -Debian uses mysqld.sock, Redhat uses mysql.sock\n'
                ' -If relative path is used, please add ~/ '
                'to the beginning')
            return False

        if socket_re.group(1) == '~/':
            res = utils.check_path_exists(path, expand=True, debug=True)
        else:
            res = utils.check_path_exists(path, debug=True)

        if not res:
            utils.eprint(
                'Invalid path was given. '
                'Could not find {}.'.format(path))

        return res
Example #2
0
def check_collectd_conf_dir():
    """
    Check if managed_config directory exists, if not,
    create one.
    """
    res = utils.check_path_exists(config.COLLECTD_CONF_DIR)
    if not res:
        utils.cprint('Creating collectd managed config dir')
        utils.call_command('mkdir ' + config.COLLECTD_CONF_DIR)
Example #3
0
def check_collectd_conf_dir():
    """
    Check if managed_config directory exists, if not,
    create one.
    """
    res = utils.check_path_exists(config.COLLECTD_CONF_DIR)
    if not res:
        utils.cprint('Creating collectd managed config dir')
        utils.call_command('mkdir ' + config.COLLECTD_CONF_DIR)
Example #4
0
    def check_collectd_plugin(self):
        """
        check if the .so file of plugin exists in the following dir
        """

        utils.print_step('Checking if the plugin is installed with '
                         'the default collectd package')

        if not utils.check_path_exists(self.plugin_dir):
            raise Exception('Collectd plugin directory is '
                            'not found at {}'.format(self.plugin_dir))

        plugin_mod = self.plugin_name + '.so'
        if utils.check_path_exists('{}/{}'.format(self.plugin_dir,
                                                  plugin_mod)):
            utils.print_success()
        else:
            self.raise_error('Missing {} plugin for collectd'.format(
                self.plugin_name))
Example #5
0
def check_collectd_path():
    utils.print_step('  Checking if collectd is installed in our specified '
                     'directory')
    res = utils.check_path_exists(config.COLLECTD_HOME)
    if not res:
        sys.stderr.write('Collectd was not found at our '
                         'default installation folder. '
                         'If you need help with configuration, please '
                         'contact [email protected]\n')
        sys.exit(1)
    utils.print_success()
Example #6
0
    def check_collectd_plugin(self):
        """
        check if the .so file of plugin exists in the following dir
        """

        utils.print_step(
            'Checking if the plugin is installed with '
            'the default collectd package')

        if not utils.check_path_exists(self.plugin_dir):
            raise Exception(
                'Collectd plugin directory is '
                'not found at {}'.format(self.plugin_dir))

        plugin_mod = self.plugin_name + '.so'
        if utils.check_path_exists(
                '{}/{}'.format(self.plugin_dir, plugin_mod)):
            utils.print_success()
        else:
            self.raise_error('Missing {} plugin for collectd'.format(
                self.plugin_name))
Example #7
0
def check_collectd_path():
    utils.print_step(
        '  Checking if collectd is installed in our specified '
        'directory')
    res = utils.check_path_exists(config.COLLECTD_HOME)
    if not res:
        sys.stderr.write(
            'Collectd was not found at our '
            'default installation folder. '
            'If you need help with configuration, please '
            'contact [email protected]\n')
        sys.exit(1)
    utils.print_success()
Example #8
0
    def check_dependency(self):
        """
        requires Python >= 2.3, which is already checked.

        create /opt/collectd/plugins/python directory
        cp the redis_info.py into there
        """
        if config.DEBUG:
            plugin_src = '{}/{}'.format(
                config.PLUGIN_EXTENSION_DIR, 'redis_info.py')
        else:
            plugin_src = '{}/{}/{}'.format(
                config.APP_DIR,
                config.PLUGIN_EXTENSION_DIR,
                'redis_info.py')

        utils.print_step(
            'Begin configuring Redis python plugin for collectd')

        # create directory if it doesn't exist
        if not utils.check_path_exists(config.COLLECTD_PYTHON_PLUGIN_PATH):
            utils.print_step(
                '  Creating directory {} '
                'for collectd python plugin'.format(config.COLLECTD_PYTHON_PLUGIN_PATH))
            res = utils.call_command(
                'mkdir -p {}'.format(config.COLLECTD_PYTHON_PLUGIN_PATH))
            if res == 0:
                utils.print_success()
            else:
                utils.print_failure()
                raise Exception(
                    'Unable to create directory {}.'.format(
                        config.COLLECTD_PYTHON_PLUGIN_PATH))

        utils.print_step(
            '  Moving python plugin')
        res = utils.call_command(
            'cp {src} {dst}'.format(
                src=plugin_src, dst=config.COLLECTD_PYTHON_PLUGIN_PATH))
        if res == 0:
            utils.print_success()
        else:
            utils.print_failure()
            raise Exception('Failed to move the plugin.')
Example #9
0
def check_dependency(os):
    """
    Apache checklist:
    - check curl
    - mod_status
    - extended status
    """

    utils.print_step('Checking dependency')
    if not utils.command_exists('curl'):
        raise Exception('Curl is needed for this plugin.')

    # ubuntu check
    # Assumption:
    # -latest apache2 is installed and the installation
    # -directory is in the default place
    if os == config.DEBIAN:
        utils.print_step('  Checking if mod_status is enabled')
        cmd_res = utils.get_command_output('ls /etc/apache2/mods-enabled')
        if cmd_res is None:
            utils.eprint('Apache2 mods-enabled folder is not '
                         'found /etc/apache2/mods-enabled.')
            utils.print_failure()
        elif 'status.conf' not in cmd_res or 'status.load' not in cmd_res:
            utils.print_step('Enabling apache2 mod_status module.')
            ret = utils.call_command('sudo a2enmod status')
            if ret != 0:
                utils.print_failure()
                raise Exception('a2enmod command was not found')
            utils.print_success()
        else:
            utils.print_success()

    elif os == config.REDHAT:
        utils.cprint()
        utils.cprint(
            'To enable server status page for the apache web,\n'
            'ensure that mod_status.so module is enabled.\n'
            'This module is often enabled by default.\n'
            '"LoadModule status_module modules/mod_status.so"\n'
            'such line should be included in one of the conf files.\n')
        _ = utils.cinput('Press Enter to continue.')

    utils.cprint()
    utils.cprint(
        'In order to fully utilize the server_status metrics,\n'
        'the ExtendedStatus setting needs be turned on.\n'
        'This setting can be turned on by having "ExtendedStatus on"\n'
        'in one of the .conf file.\n')

    utils.cprint('If you have already enabled this status, '
                 'answer "no" to the next question.\n'
                 'If you would like us to enable this status, '
                 'answer "yes" and we will '
                 'include a extendedstatus.conf file in your apache folder.\n')

    res = utils.ask('Would you like us to enable ' 'the ExtendedStatus?')

    if res:
        # dir changes depending on the system
        # tested on Ubuntu 14.04, RHEL 7.2
        if os == config.DEBIAN:
            conf_dir = '/etc/apache2/conf-enabled'
            app_name = 'apache2'
        elif os == config.REDHAT:
            conf_dir = '/etc/httpd/conf.d'
            app_name = 'httpd'

        utils.print_step('Checking if ' + conf_dir + ' exists.')
        if utils.check_path_exists(conf_dir):
            # pull config file here
            utils.print_success()
            include_apache_es_conf(conf_dir)
            utils.cprint('extendedstatus.conf is now included in the '
                         '{0} dir.\n'.format(conf_dir))
            utils.print_step('Restarting apache')
            ret = utils.call_command('service {app_name} restart >> '
                                     '{log} 2>&1'.format(
                                         app_name=app_name,
                                         log=config.INSTALL_LOG))
            if ret != 0:
                raise Exception('Failed to restart apache service.')
            utils.print_success()
        else:
            raise Exception(
                '{cond_dir} dir does not exist. Manual '
                'set up is required. For help, please '
                'consult [email protected]'.format(conf_dir=conf_dir))
Example #10
0
def check_dependency(os):
    """
    Apache checklist:
    - check curl
    - mod_status
    - extended status
    """

    utils.print_step('Checking dependency')
    if not utils.command_exists('curl'):
        raise Exception('Curl is needed for this plugin.')

    # ubuntu check
    # Assumption:
    # -latest apache2 is installed and the installation
    # -directory is in the default place
    if os == config.DEBIAN:
        utils.print_step('  Checking if mod_status is enabled')
        cmd_res = utils.get_command_output('ls /etc/apache2/mods-enabled')
        if cmd_res is None:
            utils.eprint(
                'Apache2 mods-enabled folder is not '
                'found /etc/apache2/mods-enabled.')
            utils.print_failure()
        elif 'status.conf' not in cmd_res or 'status.load' not in cmd_res:
            utils.print_step('Enabling apache2 mod_status module.')
            ret = utils.call_command('sudo a2enmod status')
            if ret != 0:
                utils.print_failure()
                raise Exception('a2enmod command was not found')
            utils.print_success()
        else:
            utils.print_success()

    elif os == config.REDHAT:
        utils.cprint()
        utils.cprint(
            'To enable server status page for the apache web,\n'
            'ensure that mod_status.so module is enabled.\n'
            'This module is often enabled by default.\n'
            '"LoadModule status_module modules/mod_status.so"\n'
            'such line should be included in one of the conf files.\n')
        _ = utils.cinput('Press Enter to continue.')

    utils.cprint()
    utils.cprint(
        'In order to fully utilize the server_status metrics,\n'
        'the ExtendedStatus setting needs be turned on.\n'
        'This setting can be turned on by having "ExtendedStatus on"\n'
        'in one of the .conf file.\n')

    utils.cprint(
        'If you have already enabled this status, '
        'answer "no" to the next question.\n'
        'If you would like us to enable this status, '
        'answer "yes" and we will '
        'include a extendedstatus.conf file in your apache folder.\n')

    res = utils.ask(
        'Would you like us to enable '
        'the ExtendedStatus?')

    if res:
        # dir changes depending on the system
        # tested on Ubuntu 14.04, RHEL 7.2
        if os == config.DEBIAN:
            conf_dir = '/etc/apache2/conf-enabled'
            app_name = 'apache2'
        elif os == config.REDHAT:
            conf_dir = '/etc/httpd/conf.d'
            app_name = 'httpd'

        utils.print_step('Checking if ' + conf_dir + ' exists.')
        if utils.check_path_exists(conf_dir):
            # pull config file here
            utils.print_success()
            include_apache_es_conf(conf_dir)
            utils.cprint(
                'extendedstatus.conf is now included in the '
                '{0} dir.\n'.format(conf_dir))
            utils.print_step('Restarting apache')
            ret = utils.call_command(
                'service {app_name} restart >> '
                '{log} 2>&1'.format(
                    app_name=app_name,
                    log=config.INSTALL_LOG))
            if ret != 0:
                raise Exception(
                    'Failed to restart apache service.')
            utils.print_success()
        else:
            raise Exception(
                '{cond_dir} dir does not exist. Manual '
                'set up is required. For help, please '
                'consult [email protected]'.format(
                    conf_dir=conf_dir))