Exemplo n.º 1
0
def check_http_response(url):
    """
    check if the url is a valid

    Input:
        url string: the url provided by the user
    Output:
        ret_val bool:
            True if the url is valid and returns 200 OK
            False otherwise
    """
    ret_val = False
    utils.print_step('Checking http response for {url}'.format(url=url))
    res = utils.get_command_output('curl -s --head {url}'.format(url=url))

    if res is None:
        ret_code = utils.INVALID_URL
    else:
        ret_code = utils.get_http_return_code(res)

    if ret_code == utils.NOT_AUTH:
        # skip for this case for now, ask for user/pass
        utils.print_failure()
        utils.eprint('Authorization is required, please ' 'try again.\n')
    elif ret_code == utils.NOT_FOUND or ret_code == utils.INVALID_URL:
        utils.print_failure()
        utils.eprint('Invalid url was provided, please try ' 'again.\n')
    elif ret_code == utils.HTTP_OK:
        utils.print_success()
        ret_val = True

    return ret_val
Exemplo n.º 2
0
def get_server_status_list(check_server_status_url):
    """
    get a list of server-status urls

    Input:
        check_server_status_url(string, []string) bool
          - a function takes a url string and a list of urls
            and return whether the url is valid
    Output:
        server_list []string: list of valid urls
    """
    server_list = []

    while utils.ask('Would you like to add a server to monitor?'):
        url = None
        while not check_server_status_url(url, server_list):
            url = utils.get_input(
                'Please enter the url that contains your '
                'server-status\n'
                '(ex: http://localhost/server-status):')

        utils.cprint()
        utils.cprint(
            'URL: {}'.format(url))
        res = utils.ask(
            'Is this the correct url?')
        if res:
            utils.print_step('Saving instance')
            server_list.append(url)
            utils.print_success()
        else:
            utils.cprint('Instance is not saved.')

    return server_list
Exemplo n.º 3
0
    def collect_data(self):
        """
        data = {
            servers: []
        }
        """
        data = {'servers': []}
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            (host, port) = p_utils.get_host_and_port(def_port='11211')
            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = ('    Host "{host}"\n'
                               '    Port "{port}"\n').format(host=host,
                                                             port=port)

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                server_list.append((host, port))
                data['servers'].append('{host}:{port}'.format(host=host,
                                                              port=port))
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 4
0
    def collect_data(self):
        """
        note: can only monitor one instance
        """
        data = {}
        record = True
        while record:
            (host, port) = p_utils.get_host_and_port(def_port='2181')
            plugin_instance = (
                '    Host "{host}"\n'
                '    Port "{port}"\n').format(
                    host=host, port=port)

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                record = False
                data = {
                    'host': host,
                    'port': port
                }
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 5
0
def get_server_status_list(check_server_status_url):
    """
    get a list of server-status urls

    Input:
        check_server_status_url(string, []string) bool
          - a function takes a url string and a list of urls
            and return whether the url is valid
    Output:
        server_list []string: list of valid urls
    """
    server_list = []

    while utils.ask('Would you like to add a server to monitor?'):
        url = None
        while not check_server_status_url(url, server_list):
            url = utils.get_input('Please enter the url that contains your '
                                  'server-status\n'
                                  '(ex: http://localhost/server-status):')

        utils.cprint()
        utils.cprint('URL: {}'.format(url))
        res = utils.ask('Is this the correct url?')
        if res:
            utils.print_step('Saving instance')
            server_list.append(url)
            utils.print_success()
        else:
            utils.cprint('Instance is not saved.')

    return server_list
Exemplo n.º 6
0
def check_collectd_exists():
    utils.print_step('  Checking if collectd exists')
    if not utils.command_exists('collectd'):
        sys.stderr.write(
            'Collectd is not installed.\n'
            'Please rerun the installer with --collectd option.\n')
        sys.exit(1)
    utils.print_success()
Exemplo n.º 7
0
def check_collectd_exists():
    utils.print_step('  Checking if collectd exists')
    if not utils.command_exists('collectd'):
        sys.stderr.write(
            'Collectd is not installed.\n'
            'Please rerun the installer with --collectd option.\n')
        sys.exit(1)
    utils.print_success()
Exemplo n.º 8
0
    def collect_data(self):
        """
        data = {
            instance_name: {
                host: value
                port: value
            }
        }
        """
        data = {}
        iname_list = []
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(
                    lambda x: x.replace(" ", "") not in iname_list),
                usage=(
                    '{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            (host, port) = p_utils.get_host_and_port(def_port='11211')

            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = (
                '  <Instance "{iname}">\n'
                '    Host "{host}"\n'
                '    Port "{port}"\n'
                '  </Instance>\n').format(
                    iname=iname,
                    host=host, port=port)

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                iname_list.append(iname)
                server_list.append((host, port))
                data[iname] = {
                    "host": host,
                    "port": port
                }
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 9
0
    def collect_data(self):
        """
        data = {
            servers: []
        }
        """
        data = {
            'servers': []
        }
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            (host, port) = p_utils.get_host_and_port(def_port='6379')
            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = (
                '    Host "{host}"\n'
                '    Port "{port}"\n').format(
                    host=host, port=port)

            protected = utils.ask(
                    'Is there an authorization password set up for\n'
                    '{host}:{port}'.format(host=host, port=port),
                    default=None)
            if protected:
                auth = utils.get_input(
                    'What is the authorization password?')
                plugin_instance += (
                    '    Auth "{auth}"\n'.format(auth=auth))

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                server_list.append((host, port))
                if protected:
                    url = (
                        ':{auth}@{host}:{port}').format(
                            auth=auth,
                            host=host,
                            port=port)
                else:
                    url = (
                        '{host}:{port}').format(
                            host=host, port=port)
                data['servers'].append(url)
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 10
0
    def collect_data(self):
        """
        data = {
            "instance_name": "url",
        }
        """
        data = {}
        server_list = []
        iname_list = []

        a_util.plugin_usage()
        while utils.ask('Would you like to add a server to monitor?'):
            # Ask for a instance name that isn't already recorded
            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(
                    lambda x: x.replace(" ", "") not in iname_list),
                usage=(
                    '{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            # ask for a valid server status url
            url = None
            while not a_util.check_server_url(url, server_list):
                url = utils.get_input(
                    '\nPlease enter the url that contains your '
                    'server-status\n'
                    '(ex: http://www.apache.org/server-status):')

            url_auto = url+'?auto'
            plugin_instance = (
                '  <Instance "{instance}">\n'
                '    URL "{url}"\n'
                '  </Instance>\n').format(instance=iname,
                                          url=url_auto)
            utils.cprint()
            utils.cprint(
                'Your url is appended with ?auto to convert '
                'the content into machine readable code.\n'
                '{}'.format(plugin_instance))
            res = utils.ask(
                'Is this the correct status to monitor?')
            if res:
                utils.print_step('Saving instance')
                # store input
                server_list.append(url)
                iname_list.append(iname)
                data[iname] = url_auto
                utils.print_success()
            else:
                utils.cprint('Instance is not saved.')

        return data
Exemplo n.º 11
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))
Exemplo n.º 12
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()
Exemplo n.º 13
0
def check_dependency():
    utils.print_step('Checking dependency')
    utils.print_step('  Checking http_stub_status_module')

    cmd_res = utils.get_command_output('nginx -V 2>&1 | grep -o '
                                       'with-http_stub_status_module')
    if cmd_res is None:
        utils.print_warn('http_stub_status_module is not enabled.\n'
                         'This module is required to enable the '
                         'nginx-status page.')
        self.raise_error('http_stub_status_module')
    utils.print_success()
Exemplo n.º 14
0
    def collect_data(self):
        """
        data = {
            instance_name: {
                host: value
                port: value
            }
        }
        """
        data = {}
        iname_list = []
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(lambda x: x.replace(" ", "") not in iname_list),
                usage=('{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            (host, port) = p_utils.get_host_and_port(def_port='11211')

            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = ('  <Instance "{iname}">\n'
                               '    Host "{host}"\n'
                               '    Port "{port}"\n'
                               '  </Instance>\n').format(iname=iname,
                                                         host=host,
                                                         port=port)

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                iname_list.append(iname)
                server_list.append((host, port))
                data[iname] = {"host": host, "port": port}
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 15
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()
Exemplo n.º 16
0
def check_version():
    """
    check python version
    """
    cur_version = sys.version_info
    utils.print_step('  Checking python version')
    if cur_version < REQ_VERSION:
        sys.stderr.write(
            'Your Python interpreter is older '
            'than what we have tested, we suggest upgrading '
            'to a newer 2.7 version before continuing.\n')
        sys.exit()
    utils.print_success()
Exemplo n.º 17
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))
Exemplo n.º 18
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()
Exemplo n.º 19
0
    def collect_data(self):
        """
        data = {
            servers: []
        }
        """
        data = {'servers': []}
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            (host, port) = p_utils.get_host_and_port(def_port='6379')
            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = ('    Host "{host}"\n'
                               '    Port "{port}"\n').format(host=host,
                                                             port=port)

            protected = utils.ask(
                'Is there an authorization password set up for\n'
                '{host}:{port}'.format(host=host, port=port),
                default=None)
            if protected:
                auth = utils.get_input('What is the authorization password?')
                plugin_instance += ('    Auth "{auth}"\n'.format(auth=auth))

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                server_list.append((host, port))
                if protected:
                    url = (':{auth}@{host}:{port}').format(auth=auth,
                                                           host=host,
                                                           port=port)
                else:
                    url = ('{host}:{port}').format(host=host, port=port)
                data['servers'].append(url)
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 20
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.')
Exemplo n.º 21
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))
Exemplo n.º 22
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))
Exemplo n.º 23
0
    def collect_data(self):
        """
        data = {
            servers: []
        }
        """
        data = {
            'servers': []
        }
        server_list = []

        while utils.ask('\nWould you like to add a server to monitor?'):
            (host, port) = p_utils.get_host_and_port(def_port='11211')
            if (host, port) in server_list:
                utils.eprint(
                    'You have already added this {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = (
                '    Host "{host}"\n'
                '    Port "{port}"\n').format(
                    host=host, port=port)

            utils.cprint()
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                server_list.append((host, port))
                data['servers'].append(
                    '{host}:{port}'.format(
                        host=host, port=port))
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 24
0
def check_http_response(url):
    """
    check if the url is a valid

    Input:
        url string: the url provided by the user
    Output:
        ret_val bool:
            True if the url is valid and returns 200 OK
            False otherwise
    """
    ret_val = False
    utils.print_step('Checking http response for {url}'.format(url=url))
    res = utils.get_command_output('curl -s --head {url}'.format(url=url))

    if res is None:
        ret_code = utils.INVALID_URL
    else:
        ret_code = utils.get_http_return_code(res)

    if ret_code == utils.NOT_AUTH:
        # skip for this case for now, ask for user/pass
        utils.print_failure()
        utils.eprint(
            'Authorization is required, please '
            'try again.\n')
    elif ret_code == utils.NOT_FOUND or ret_code == utils.INVALID_URL:
        utils.print_failure()
        utils.eprint(
            'Invalid url was provided, please try '
            'again.\n')
    elif ret_code == utils.HTTP_OK:
        utils.print_success()
        ret_val = True

    return ret_val
Exemplo n.º 25
0
    def collect_data(self):
        """
        data = {
            instance_name: {
                host: value,
                port: value,
            (optional)
                auth: value,
                slave: bool
            }
        }
        """
        data = {}
        iname_list = []
        server_list = []

        while utils.ask('Would you like to add a server to monitor?'):
            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(
                    lambda x: x.replace(" ", "") not in iname_list),
                usage=(
                    '{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            host = utils.prompt_and_check_input(
                prompt=(
                    '\nPlease enter the hostname that connects to your\n'
                    'redis server: (ex: localhost)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=(
                    '\nWhat is the TCP-port used to connect to the host? '),
                check_func=utils.check_valid_port,
                usage=(
                    'A valid port is a number '
                    'between (0, 65535) inclusive.'),
                default='6379')

            if (host, port) in server_list:
                utils.eprint(
                    'You have already monitored {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = (
                '    Instance "{iname}"\n'
                '    Host "{host}"\n'
                '    Port "{port}"\n').format(
                    iname=iname,
                    host=host, port=port)

            protected = utils.ask(
                    'Is there an authorization password set up for\n'
                    '{host}:{port}'.format(host=host, port=port),
                    default=None)
            if protected:
                auth = utils.get_input(
                    'What is the authorization password?')
                plugin_instance += (
                    '    Auth "{auth}"\n'.format(auth=auth))

            slave = utils.ask(
                'Is this a slave server?', default='no')

            utils.cprint()
            if slave:
                utils.cprint('(slave server)')
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                iname_list.append(iname)
                server_list.append((host, port))
                data[iname] = {
                    'host': host,
                    'port': port,
                }
                if protected:
                    data[iname]['auth'] = auth
                if slave:
                    data[iname]['slave'] = True
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 26
0
    def collect_data(self):
        """
        Prompt the user for information, and guide them through the plugin

        host: (default: localhost)
        User: (any existing user will work if not monitoring replication db)
        Password:(password for the user)
        Socket: ( path to sockt, used for localhost )
        TCP: (port number, used for remote host )
        * Database: (the specific db to monitor)
            * This option doesn't seem to affect anything with
            * the collectd plugin

        data = {
            "username": username,
            "password": password,
            "host": host,
            "port or socket": ,
            "db": db
        }
        """
        data = {}
        db_list = []
        server_list = []
        if self.os == config.DEBIAN:
            default_socket_path = '/var/run/mysqld/mysqld.sock'
        if self.os == config.REDHAT:
            default_socket_path = '/var/lib/mysql/mysql.sock'

        while utils.ask('Would you like to add a DB server to monitor?'):
            remote = utils.ask(
                'Is this a remote host?')

            host = ''
            port = ''
            if remote:
                host = utils.prompt_and_check_input(
                    prompt=(
                        'What is the hostname or IP of your DB server? '
                        '(ex: 127.0.0.1)'),
                    check_func=utils.hostname_resolves,
                    usage='{} does not resolve.'.format,
                    usage_fmt=True)

                port = utils.prompt_and_check_input(
                    prompt=(
                        'What is the TCP-port used to connect to the host?'),
                    default='3306',
                    check_func=utils.check_valid_port,
                    usage=(
                        'A valid port is a number '
                        'between (0, 65535) inclusive.\n'))
            else:
                socket = None
                while(not self.check_socket_path(socket)):
                    socket = utils.get_input(
                        'What is the path to your mysql sock file?',
                        default_socket_path)

            if (host, port) in server_list:
                utils.cprint(
                    'You have already recorded\n'
                    '{host}:{port}'.format(
                        host=host, port=port))
                continue

            db = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this DB '
                    'server?\n(Space between words will be '
                    'removed)'),
                check_func=(
                    lambda x: x.replace(" ", "") not in db_list),
                usage=(
                    '{} has already been recorded.'.format),
                usage_fmt=True).replace(" ", "")

            utils.cprint(
                'Please provide/create an valid account '
                'that the plugin can use to login to the server. '
                'Account with minimal privilege is sufficient.')
            username = utils.get_input(
                'What is the username?')
            password = utils.get_input(
                'What is the password?')

            instance = (
                '    User "{username}"\n'
                '    Password "{password}"\n').format(
                        username=username,
                        password=password)

            if remote:
                instance += (
                    '    Host "{}"\n'
                    '    Port "{}"\n'.format(host, port))
            else:
                instance += (
                    '    Host "localhost"\n'
                    '    Socket "{}"\n'.format(socket))

            utils.cprint()
            utils.cprint(
                'Database {}\n'
                '{}'.format(db, instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                db_list.append(db)
                data[db] = {
                    "username": username,
                    "password": password,
                    "host": host,
                }
                if remote:
                    data[db]['port'] = port
                    server_list.append((host, port))
                else:
                    data[db]['socket'] = socket
                utils.print_success()
            else:
                utils.cprint('This instance will not be saved.')

        return data
Exemplo n.º 27
0
    def collect_data(self):
        """
        Prompt the user for information, and guide them through the plugin

        host: (default: localhost)
        User: (any existing user will work if not monitoring replication db)
        Password:(password for the user)
        TCP: (port number, used for remote host )

        data = {
            "servers": [(list of dsn)]
        }
        """
        data = {'servers': []}
        db_list = []

        while utils.ask('\nWould you like to add a mysql server to monitor?'):
            host = utils.prompt_and_check_input(
                prompt=(
                    '\nWhat is the hostname or IP of your DB server? '
                    '(ex: 127.0.0.1)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=(
                    '\nWhat is the TCP-port used to connect to the host? '),
                check_func=utils.check_valid_port,
                usage=(
                    'A valid port is a number '
                    'between (0, 65535) inclusive.'),
                default="3306")

            if (host, port) in db_list:
                utils.cprint(
                    'You have already recorded\n'
                    '{host}:{port}'.format(
                        host=host, port=port))
                continue

            utils.cprint(
                'Please provide/create an valid account '
                'that the plugin can use to login to the server. '
                'Account with minimal privilege is sufficient.')
            username = utils.get_input(
                '\nWhat is the username?')
            password = utils.get_input(
                'What is the password?')

            instance = (
                '    User "{username}"\n'
                '    Password "{password}"\n'
                '    Host "{host}"\n'
                '    Port "{port}"\n').format(
                        username=username,
                        password=password,
                        host=host, port=port)

            utils.cprint()
            utils.cprint(
                'Result:\n{instance}'.format(instance=instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                db_list.append((host, port))
                server = (
                    '{username}:{password}@tcp({host}:{port})').format(
                      username=username,
                      password=password,
                      host=host, port=port)
                data['servers'].append(server)
                utils.print_success()
            else:
                utils.cprint('This instance will not be saved.')

        return data
Exemplo n.º 28
0
    def collect_data(self):
        """
        data = {
            instance_name: {
                host: value,
                port: value,
            (optional)
                auth: value,
                slave: bool
            }
        }
        """
        data = {}
        iname_list = []
        server_list = []

        while utils.ask('Would you like to add a server to monitor?'):
            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(lambda x: x.replace(" ", "") not in iname_list),
                usage=('{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            host = utils.prompt_and_check_input(
                prompt=('\nPlease enter the hostname that connects to your\n'
                        'redis server: (ex: localhost)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=(
                    '\nWhat is the TCP-port used to connect to the host? '),
                check_func=utils.check_valid_port,
                usage=('A valid port is a number '
                       'between (0, 65535) inclusive.'),
                default='6379')

            if (host, port) in server_list:
                utils.eprint(
                    'You have already monitored {host}:{port}.'.format(
                        host=host, port=port))
                continue

            plugin_instance = ('    Instance "{iname}"\n'
                               '    Host "{host}"\n'
                               '    Port "{port}"\n').format(iname=iname,
                                                             host=host,
                                                             port=port)

            protected = utils.ask(
                'Is there an authorization password set up for\n'
                '{host}:{port}'.format(host=host, port=port),
                default=None)
            if protected:
                auth = utils.get_input('What is the authorization password?')
                plugin_instance += ('    Auth "{auth}"\n'.format(auth=auth))

            slave = utils.ask('Is this a slave server?', default='no')

            utils.cprint()
            if slave:
                utils.cprint('(slave server)')
            utils.cprint('Result: \n{}'.format(plugin_instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                iname_list.append(iname)
                server_list.append((host, port))
                data[iname] = {
                    'host': host,
                    'port': port,
                }
                if protected:
                    data[iname]['auth'] = auth
                if slave:
                    data[iname]['slave'] = True
                utils.print_success()
            else:
                utils.cprint('This instance is not saved.')

        return data
Exemplo n.º 29
0
    def collect_data(self):
        """
        data = {
            instance_name: {
                db: value,
                host: value,
                port: value,
                username: value,
                password: value,
            }
        }
        """
        data = {}
        name_list = []  # keep a list of db name to check for uniqueness
        db_list = []

        while utils.ask('Would you like to add a database to monitor?'):
            db = utils.get_input(
                'What is the name of the database?\n'
                '(The name should match your database name)')

            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(
                    lambda x: x.replace(" ", "") not in name_list),
                usage=(
                    '{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            host = utils.prompt_and_check_input(
                prompt=(
                    'What is the hostname or IP of your DB server? '
                    '(ex: 127.0.0.1)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=(
                    'What is the TCP-port used to connect to the host? '
                    '(ex: 5432)'),
                check_func=utils.check_valid_port,
                usage=(
                    'A valid port is a number '
                    'between (0, 65535) inclusive.\n'))

            if (db, host, port) in db_list:
                utils.cprint(
                    'You have already monitored {db} at\n'
                    '{host}:{port}'.format(
                        db=db, host=host, port=port))
                continue

            utils.cprint(
                'Please provide/create an valid account '
                'that the plugin can use to login to the server. ')
            username = utils.get_input(
                'What is the username?')
            password = utils.get_input(
                'What is the password?')

            instance = (
                '    Host "{host}"\n'
                '    Port "{port}"\n'
                '    User "{username}"\n'
                '    Password "{password}"\n'
                '    Instance "{iname}"\n').format(
                    host=host, port=port,
                    username=username,
                    password=password,
                    iname=iname)

            utils.cprint()
            utils.cprint(
                'Database {}\n'
                '{}'.format(db, instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                name_list.append(iname)
                db_list.append((db, host, port))
                data[iname] = {
                    "db": db,
                    "host": host,
                    "port": port,
                    "username": username,
                    "password": password
                }

                utils.print_success()
            else:
                utils.cprint('This instance will not be saved.')

        return data
Exemplo n.º 30
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))
Exemplo n.º 31
0
    def collect_data(self):
        """
        Prompt the user for information, and guide them through the plugin

        host: (default: localhost)
        User: (any existing user will work if not monitoring replication db)
        Password:(password for the user)
        TCP: (port number, used for remote host )

        data = {
            "servers": [(list of dsn)]
        }
        """
        data = {'servers': []}
        db_list = []

        while utils.ask('\nWould you like to add a mysql server to monitor?'):
            host = utils.prompt_and_check_input(
                prompt=('\nWhat is the hostname or IP of your DB server? '
                        '(ex: 127.0.0.1)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=(
                    '\nWhat is the TCP-port used to connect to the host? '),
                check_func=utils.check_valid_port,
                usage=('A valid port is a number '
                       'between (0, 65535) inclusive.'),
                default="3306")

            if (host, port) in db_list:
                utils.cprint('You have already recorded\n'
                             '{host}:{port}'.format(host=host, port=port))
                continue

            utils.cprint('Please provide/create an valid account '
                         'that the plugin can use to login to the server. '
                         'Account with minimal privilege is sufficient.')
            username = utils.get_input('\nWhat is the username?')
            password = utils.get_input('What is the password?')

            instance = ('    User "{username}"\n'
                        '    Password "{password}"\n'
                        '    Host "{host}"\n'
                        '    Port "{port}"\n').format(username=username,
                                                      password=password,
                                                      host=host,
                                                      port=port)

            utils.cprint()
            utils.cprint('Result:\n{instance}'.format(instance=instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                db_list.append((host, port))
                server = ('{username}:{password}@tcp({host}:{port})').format(
                    username=username, password=password, host=host, port=port)
                data['servers'].append(server)
                utils.print_success()
            else:
                utils.cprint('This instance will not be saved.')

        return data
Exemplo n.º 32
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))
Exemplo n.º 33
0
    def collect_data(self):
        """
        sample_url: "postgres://[user[:password]]@host:port[/dbname]"
        data = {
            server_url: {
                databases: []
            }
        }
        """
        data = {}
        name_list = []  # keep a list of db name to check for uniqueness
        db_list = []

        while utils.ask('Would you like to add a database to monitor?'):
            db = utils.get_input('What is the name of the database?\n'
                                 '(The name should match your database name)')

            iname = utils.prompt_and_check_input(
                prompt=(
                    '\nHow would you like to name this monitoring instance?\n'
                    '(How it should appear on your wavefront metric page, \n'
                    'space between words will be removed)'),
                check_func=(lambda x: x.replace(" ", "") not in name_list),
                usage=('{} has already been used.'.format),
                usage_fmt=True).replace(" ", "")

            host = utils.prompt_and_check_input(
                prompt=('What is the hostname or IP of your DB server? '
                        '(ex: 127.0.0.1)'),
                check_func=utils.hostname_resolves,
                usage='{} does not resolve.'.format,
                usage_fmt=True)

            port = utils.prompt_and_check_input(
                prompt=('What is the TCP-port used to connect to the host? '
                        '(ex: 5432)'),
                check_func=utils.check_valid_port,
                usage=('A valid port is a number '
                       'between (0, 65535) inclusive.\n'))

            if (db, host, port) in db_list:
                utils.cprint('You have already monitored {db} at\n'
                             '{host}:{port}'.format(db=db,
                                                    host=host,
                                                    port=port))
                continue

            utils.cprint('Please provide/create an valid account '
                         'that the plugin can use to login to the server. ')
            username = utils.get_input('What is the username?')
            password = utils.get_input('What is the password?')

            instance = ('    Host "{host}"\n'
                        '    Port "{port}"\n'
                        '    User "{username}"\n'
                        '    Password "{password}"\n'
                        '    Instance "{iname}"\n').format(host=host,
                                                           port=port,
                                                           username=username,
                                                           password=password,
                                                           iname=iname)

            utils.cprint()
            utils.cprint('Database {}\n' '{}'.format(db, instance))
            res = utils.ask('Is the above information correct?')

            if res:
                utils.print_step('Saving instance')
                name_list.append(iname)
                db_list.append((db, host, port))
                data[iname] = {
                    "db": db,
                    "host": host,
                    "port": port,
                    "username": username,
                    "password": password
                }

                utils.print_success()
            else:
                utils.cprint('This instance will not be saved.')

        return data