Пример #1
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)
Пример #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)
Пример #3
0
    def check_dependency(self):
        utils.print_step('Checking dependency')

        ldd_out = utils.get_command_output(
            'ldd {}/java.so'.format(self.plugin_dir))
        for line in ldd_out.split('\n'):
            libjvm_re = re.search(r'libjvm.so(.*?)not found', line)
            if libjvm_re is not None:
                utils.call_command(
                    'echo Missing libjvm dependency for collectd java plugin '
                    '>>{log}'.format(log=config.INSTALL_LOG))
                self.raise_error(
                    'Missing libjvm dependency for collectd java plugin.')
        utils.print_success()
Пример #4
0
    def clean_plugin_write(self):
        """
        Prevent unfinished config file from being written into the directory

        Create and write to a temporary file.  Use try catch block to call
        write_plugin function.  If the configuration file is written
        successfully, then it will be copied over to the correct place.
        """
        temp_file = 'wavefront_temp_{0}.conf'.format(utils.random_string(7))
        error = None

        try:
            with open(temp_file, 'w') as out:
                try:
                    data = self.collect_data()
                    res = self.output_config(data, out)
                except KeyboardInterrupt as e:
                    error = e
                except Exception as e:
                    error = e
                finally:
                    if error:
                        utils.eprint('\nClosing and removing temp file.\n')
                        utils.call_command('rm ' + temp_file)
                        raise error
        except (IOError, OSError) as e:
            utils.eprint('Cannot open {}'.format(filepath))
            raise Exception(
                  'Error: {}\n'
                  'Cannot open {}.'.format(e, filepath))

        # if there was at least one instance being monitor
        if res:
            utils.print_step('Copying the plugin file to the correct place')
            cp_cmd = (
                'cp {infile} {conf_dir}/{outfile}').format(
                    infile=temp_file,
                    conf_dir=self.conf_dir,
                    outfile=self.conf_name)
            ret = utils.call_command(cp_cmd)

            if ret == 0:
                utils.print_success()
                utils.cprint(
                    '{0} can be found at {1}.'.format(
                        self.conf_name,
                        self.conf_dir))
            else:
                utils.call_command('rm {}'.format(temp_file))
                raise Exception('Failed to copy the plugin file.\n')
        else:
            utils.call_command('rm {}'.format(temp_file))
            raise Exception('You did not provide any instance to monitor.\n')

        utils.call_command('rm {}'.format(temp_file))
Пример #5
0
    def clean_plugin_write(self):
        """
        Prevent unfinished config file from being written into the directory

        Create and write to a temporary file.  Use try catch block to call
        write_plugin function.  If the configuration file is written
        successfully, then it will be copied over to the correct place.
        """
        temp_file = 'wavefront_temp_{0}.conf'.format(utils.random_string(7))
        error = None

        try:
            with open(temp_file, 'w') as out:
                try:
                    data = self.collect_data()
                    res = self.output_config(data, out)
                except KeyboardInterrupt as e:
                    error = e
                except Exception as e:
                    error = e
                finally:
                    if error:
                        utils.eprint('\nClosing and removing temp file.\n')
                        utils.call_command('rm ' + temp_file)
                        raise error
        except (IOError, OSError) as e:
            utils.eprint('Cannot open {}'.format(filepath))
            raise Exception('Error: {}\n'
                            'Cannot open {}.'.format(e, filepath))

        # if there was at least one instance being monitor
        if res:
            utils.print_step('Copying the plugin file to the correct place')
            cp_cmd = ('cp {infile} {conf_dir}/{outfile}').format(
                infile=temp_file,
                conf_dir=self.conf_dir,
                outfile=self.conf_name)
            ret = utils.call_command(cp_cmd)

            if ret == 0:
                utils.print_success()
                utils.cprint('{0} can be found at {1}.'.format(
                    self.conf_name, self.conf_dir))
            else:
                utils.call_command('rm {}'.format(temp_file))
                raise Exception('Failed to copy the plugin file.\n')
        else:
            utils.call_command('rm {}'.format(temp_file))
            raise Exception('You did not provide any instance to monitor.\n')

        utils.call_command('rm {}'.format(temp_file))
Пример #6
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.')
Пример #7
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))
Пример #8
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))