Пример #1
0
    def collect_data(self):
        data = {}
        # ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:7199/jmxrmi"

        utils.print_step('Begin writing Cassandra plugin for collectd')
        url = None

        url = utils.prompt_and_check_input(
            prompt=(
                '\nPlease enter a valid JMXServiceURL that can reach\n'
                'your MBeanServer'),
            default=(
                'service:jmx:rmi:'
                '///jndi/rmi://localhost:7199/jmxrmi'),
            check_func=self.check_JMXServiceURL,
            usage=self.url_usage).replace(" ", "")

        plugin_instance = (
            '      ServiceURL "{url}"\n').format(url=url)

        protected = utils.ask(
              'Is a valid account required to authenticate to '
              'the server?\n'
              '(If not, "monitorRole" will be used.)', None)
        if protected:
            user = utils.get_input(
                'What is the username?')
            password = utils.get_input(
                'What is the password?')
            plugin_instance += (
                '      User "{user}"\n'
                '      Password "{password}"\n').format(
                    user=user, password=password)

        utils.cprint()
        utils.cprint('Result:\n{}'.format(plugin_instance))
        res = utils.ask(
            'Is the above information correct?')
        if res:
            # pull and edit the conf file
            data = {
                'url': url
            }
            if protected:
                data['user'] = user
                data['password'] = password
        else:
            url = None

        return data
Пример #2
0
    def collect_data(self):
        """
        data = {
            url: url
        }
        """
        data = {}
        n_utils.plugin_usage()

        record = True
        url = None
        while record:
            while not n_utils.check_server_url(url):
                url = utils.get_input(
                    '\nPlease enter the url that contains your '
                    'server-status:\n(ex: http://localhost/server-status)\n'
                    '(This plugin can only monitor one server)')

            plugin_instance = (
                        '    URL "{url}"\n'.format(url=url))
            utils.cprint('Result from:\n{}'.format(plugin_instance))
            res = utils.ask(
                'Is this the correct url to monitor?')
            if res:
                data['url'] = url
                record = False

        return data
Пример #3
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
Пример #4
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
Пример #5
0
    def collect_data(self):
        """
        data = {
            url: url
        }
        """
        data = {}
        n_utils.plugin_usage()

        record = True
        url = None
        while record:
            while not n_utils.check_server_url(url):
                url = utils.get_input(
                    '\nPlease enter the url that contains your '
                    'server-status:\n(ex: http://localhost/server-status)\n'
                    '(This plugin can only monitor one server)')

            plugin_instance = ('    URL "{url}"\n'.format(url=url))
            utils.cprint('Result from:\n{}'.format(plugin_instance))
            res = utils.ask('Is this the correct url to monitor?')
            if res:
                data['url'] = url
                record = False

        return data
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
0
def installer_menu(app_list, support_dict):
    """
    provide the menu and prompts for the user to interact with the installer

    Input:
        app_list []:
            list of app detected that plugin support
        support_dict {}:
            dict that associates with each app in app_list

    Output:
        count int:
            the number of successful installation

    installer flow:
      1. show selections
      2. installs a plugin
      3. updates install state
      4. menu changes with install state

    Sample menu:
    Option  Name                 State      Date
    (1)     mysql                Installed  (installation date)
    (2)     apache               Incomplete
    (3)     postgres             New

    if resinstall,
      warn that this will overwrite {conf_file}.
    """
    exit_cmd = [
        'quit', 'q', 'exit']
    count = 0

    # the format of each row in installing menu
    menu_rowf = (
        '{index:{index_pad}} {name:{name_pad}} '
        '{state:{state_pad}} {date}')
    # padding of each parameter
    index_pad = 7
    name_pad = 30
    state_pad = 12
    color = utils.BLACK  # default color

    res = None  # to begin the prompt loop
    utils.cprint()
    utils.cprint(
        'We have detected the following applications that are '
        'supported by our configurators.')

    while res not in exit_cmd:
        utils.cprint()
        utils.cprint(
            'The following are the available configurators:')

        utils.cprint(
            menu_rowf.format(
                index='Option', index_pad=index_pad,
                name='Name', name_pad=name_pad,
                state='State', state_pad=state_pad,
                date='Date'))

        # install_state_dict contains other agents' state as well
        install_state_dict = check_install_state(app_list)
        install_state = install_state_dict[config.AGENT]

        for i, app in enumerate(app_list):
            # formatted string for menu
            index = '({i})'.format(i=i)
            app_installer = '{app}'.format(app=app)
            app_state = install_state[app]['state']

            if 'date' in install_state[app]:
                date = install_state[app]['date']
            else:
                date = ''

            if app_state == NEW:
                state = 'New'
                color = utils.GREEN
            elif app_state == INCOMPLETE:
                state = 'Incomplete'
                color = utils.YELLOW
            elif app_state == INSTALLED:
                state = 'Installed'
                color = utils.BLACK

            utils.print_color_msg(
                menu_rowf.format(
                    index=index, index_pad=index_pad,
                    name=app_installer, name_pad=name_pad,
                    state=state, state_pad=state_pad,
                    date=date), color)

        utils.cprint()
        utils.cprint(
            'To pick a configurator, type in the corresponding number '
            'next to the configurator.\n'
            'To quit out of this installer, type "[Q]uit" or "exit".')
        res = utils.get_input(
            'Which installer would you like to run?').lower()
        if res not in exit_cmd:
            # check if option is within the array list
            option = check_option(res, len(app_list))

            if option is not None:
                app = app_list[option]
                app_dict = support_dict[app]
                utils.cprint(
                    'You have selected ({option}) {app} installer'.format(
                        option=option, app=app))
                app_state = install_state[app]['state']
                if app_state == INSTALLED:
                    utils.print_warn(
                        'You have previously used this configurator\n'
                        'Reinstalling will overwrite the old configuration '
                        'file, {}.'.format(app_dict['conf_name']))
                confirm = utils.ask(
                    'Would you like to proceed with '
                    'the configurator?')
                if confirm:
                    if run_installer(config.AGENT, app_dict):
                        install_state[app]['state'] = INSTALLED
                        count += 1
                    else:
                        install_state[app]['state'] = INCOMPLETE
                    install_state[app]['date'] = '{:%c}'.format(
                        datetime.now())
                    update_install_state(config.AGENT, install_state_dict)
            else:
                utils.print_reminder('Invalid option.')

    return count
Пример #10
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
Пример #11
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
Пример #12
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
Пример #13
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
Пример #14
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
Пример #15
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
Пример #16
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