Beispiel #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
Beispiel #2
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
Beispiel #3
0
    def output_config(self, data, out):
        utils.print_step('Begin writing MySQL plugin for collectd')
        out.write('LoadPlugin "mysql"\n')
        out.write('<Plugin "mysql">\n')

        if not data:
            return False

        for db in data:
            instance = (
                '    User "{username}"\n'
                '    Password "{password}"\n').format(
                        username=data[db]['username'],
                        password=data[db]['password'])

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

            out.write(
                '  <Database {db}>\n'
                '{instance}'
                '  </Database>\n'.format(db=db, instance=instance))
        out.write('</Plugin>\n')

        return True
Beispiel #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
Beispiel #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
Beispiel #6
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
Beispiel #7
0
    def output_config(self, data, out):
        utils.print_step('Begin writing nginx plugin for collectd')
        out.write('LoadPlugin "nginx"\n'
                  '<Plugin "nginx">\n'
                  '  URL "{url}"\n'
                  '</Plugin>\n'.format(url=data['url']))

        return True
Beispiel #8
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()
Beispiel #9
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()
Beispiel #10
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
Beispiel #11
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
Beispiel #12
0
    def output_config(self, data, out):
        utils.print_step('Begin writing nginx plugin for collectd')
        out.write(
            'LoadPlugin "nginx"\n'
            '<Plugin "nginx">\n'
            '  URL "{url}"\n'
            '</Plugin>\n'.format(url=data['url']))

        return True
Beispiel #13
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
Beispiel #14
0
    def overview(self):
        utils.cprint()
        utils.cprint('The telegraf redis plugin connects to one or more\n'
                     'Redis servers and gathers information\n'
                     'about their states.\n'
                     'To enable this plugin, hostname and port\n'
                     'will be needed to connect to redis-server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf redis plugin installer')
Beispiel #15
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))
Beispiel #16
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The elasticsearch plugin queries endpoints to obtain\n'
            'node and optionally cluster stats.\n'
            'The enable the plugin, it needs\n'
            'hostname and the port to connect\n'
            'to the elasticsearch server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf Elasticsearch plugin installer')
Beispiel #17
0
 def output_config(self, data, out):
     utils.print_step('Begin writing zookeeper plugin for collectd')
     out.write(
         'LoadPlugin "zookeeper"\n'
         '<Plugin "zookeeper">\n'
         '    Host "{host}"\n'
         '    Port "{port}"\n'
         '</Plugin>\n'.format(
             host=data['host'],
             port=data['port']))
     return True
Beispiel #18
0
    def overview(self):
        utils.cprint()
        utils.cprint('The memcached plugin connects to a memcached server\n'
                     'and queries statistics about cache utilization,\n'
                     'memory and bandwidth used.\n\n'
                     'To enable memcached plugin,\n'
                     'hostname and the port are needed to connect\n'
                     'to the memcached server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf Memcached plugin installer')
Beispiel #19
0
    def overview(self):
        utils.cprint()
        utils.cprint('This redis plugin makes use of collectd python\n'
                     'extension to connects to one or more\n'
                     'Redis servers and gathers information\n'
                     'about each server\'s state.\n'
                     'To enable this plugin, hostname and port\n'
                     'will be needed to connect to redis-server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd Memcached plugin installer')
Beispiel #20
0
    def overview(self):
        utils.cprint()
        utils.cprint('The telegraf MySQL plugin collects data from\n'
                     'mysql server by executing query and using\n'
                     'commands like SHOW STATUS.\n'
                     'When asked for username and password,\n'
                     'please create/provide an account for the mysql server\n'
                     'this plugin will be monitoring.')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf MySQL plugin configurator')
Beispiel #21
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()
Beispiel #22
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The telegraf redis plugin connects to one or more\n'
            'Redis servers and gathers information\n'
            'about their states.\n'
            'To enable this plugin, hostname and port\n'
            'will be needed to connect to redis-server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf redis plugin installer')
Beispiel #23
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'This redis plugin makes use of collectd python\n'
            'extension to connects to one or more\n'
            'Redis servers and gathers information\n'
            'about each server\'s state.\n'
            'To enable this plugin, hostname and port\n'
            'will be needed to connect to redis-server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd Memcached plugin installer')
Beispiel #24
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The collectd MySQL plugin collects data from\n'
            'the SHOW STATUS command in mysqlclient.\n'
            'The SHOW STATUS command can be used by user of\n'
            'any priviledge.\nWhen asked for username and password,\n'
            'please create an account under the mysql server\n'
            'the collectd will be monitoring.')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd MySQL plugin installer')
Beispiel #25
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The telegraf MySQL plugin collects data from\n'
            'mysql server by executing query and using\n'
            'commands like SHOW STATUS.\n'
            'When asked for username and password,\n'
            'please create/provide an account for the mysql server\n'
            'this plugin will be monitoring.')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf MySQL plugin configurator')
Beispiel #26
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()
Beispiel #27
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The memcached plugin connects to a memcached server\n'
            'and queries statistics about cache utilization,\n'
            'memory and bandwidth used.\n\n'
            'To enable memcached plugin,\n'
            'hostname and the port are needed to connect\n'
            'to the memcached server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin telegraf Memcached plugin installer')
Beispiel #28
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'The collectd zookeeper plugin collect statistics from\n'
            'a Zookeeper server using the mntr command.\n'
            'The mntr command requires Zookeeper 3.4.0+.\n'
            'To enable collectd zookeeper plugin,\n'
            'We need the hostname and the port to connect\n'
            'to the zookeeper server.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd Zookeeper plugin installer')
Beispiel #29
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
Beispiel #30
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()
Beispiel #31
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'Overview:\n'
            'The Cassandra collectd plugin uses GenericJMX plugin\n'
            'within the java plugin to collect various\n'
            'management information from the MBeanServer.\n'
            'We have set up some common collected metrics for Cassandra.\n'
            'The information needed from the user is the access to the \n'
            'MBeanServer.\n')

        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd Cassandra plugin installer')
Beispiel #32
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()
Beispiel #33
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))
Beispiel #34
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
Beispiel #35
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()
Beispiel #36
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
Beispiel #37
0
    def output_config(self, data, out):
        utils.print_step('Begin writing telegraf redis configuration')
        server_list = data['servers']
        count = len(server_list)
        if not count:
            return False

        conf = tf_utils.get_sample_config('redis')
        if conf is None:
            raise Exception(
                'Cannot obtain sample config with telegraf command')

        server_list_str = p_utils.json_dumps(server_list)
        res = tf_utils.edit_conf(conf, 'servers', server_list_str)

        out.write(res)
        return True
Beispiel #38
0
    def overview(self):
        utils.cprint()
        utils.cprint('Overview:\n'
                     'The postgres collectd plugin connects to and \n'
                     'execute SQL statement on a PostgreSQL database.\n'
                     'It then uses the returned value as metric.\n'
                     'Custom query and function tracking is possible,\n'
                     'but it requires the user to be familiar with the\n'
                     'configuration format. Our default configuration\n'
                     'makes use of the posgres statistics collector.\n'
                     'To enable the monitoring, the plugin requires\n'
                     'a valid user account that has access to the\n'
                     'database and has the ability to read from the database.')

        utils.cprint()
        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd PostgreSQl plugin installer')
Beispiel #39
0
    def overview(self):
        utils.cprint()
        utils.cprint(
            'Overview:\n'
            'The postgres collectd plugin connects to and \n'
            'execute SQL statement on a PostgreSQL database.\n'
            'It then uses the returned value as metric.\n'
            'Custom query and function tracking is possible,\n'
            'but it requires the user to be familiar with the\n'
            'configuration format. Our default configuration\n'
            'makes use of the posgres statistics collector.\n'
            'To enable the monitoring, the plugin requires\n'
            'a valid user account that has access to the\n'
            'database and has the ability to read from the database.')

        utils.cprint()
        _ = utils.cinput('Press Enter to continue')
        utils.print_step('Begin collectd PostgreSQl plugin installer')
Beispiel #40
0
    def output_config(self, data, out):
        utils.print_step('Begin writing memcached plugin for collectd')
        if not data:
            return False

        out.write('LoadPlugin "memcached"\n')
        out.write('<Plugin "memcached">\n')

        for instance in data:
            out.write('  <Instance "{iname}">\n'
                      '    Host "{host}"\n'
                      '    Port "{port}"\n'
                      '  </Instance>\n'.format(iname=instance,
                                               host=data[instance]['host'],
                                               port=data[instance]['port']))

        out.write('</Plugin>\n')
        return True
Beispiel #41
0
    def output_config(self, data, out):
        utils.print_step('Begin writing apache plugin for collectd')
        if not data:
            return False

        out.write(
            'LoadPlugin "apache"\n'
            '<Plugin "apache">\n')

        for instance in data:
            out.write(
                '  <Instance "{instance}">\n'
                '    URL "{url}"\n'
                '  </Instance>\n'.format(instance=instance,
                                         url=data[instance]))

        out.write('</Plugin>\n')
        return True
Beispiel #42
0
    def output_config(self, data, out):
        utils.print_step('Begin writing mysql telegraf configuration file')

        server_list = data['servers']
        count = len(server_list)
        if not count:
            return False

        conf = tf_utils.get_sample_config('mysql')
        if conf is None:
            raise Exception(
                'Cannot obtain sample config with telegraf command')

        server_list_str = p_utils.json_dumps(server_list)
        res = tf_utils.edit_conf(conf, 'servers', server_list_str)

        out.write(res)
        return count
Beispiel #43
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))
Beispiel #44
0
    def output_config(self, data, out):
        utils.print_step('Begin writing memcached plugin for collectd')
        if not data:
            return False

        out.write('LoadPlugin "memcached"\n')
        out.write('<Plugin "memcached">\n')

        for instance in data:
            out.write(
                '  <Instance "{iname}">\n'
                '    Host "{host}"\n'
                '    Port "{port}"\n'
                '  </Instance>\n'.format(
                    iname=instance,
                    host=data[instance]['host'],
                    port=data[instance]['port']))

        out.write('</Plugin>\n')
        return True
Beispiel #45
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))
Beispiel #46
0
    def output_config(self, data, out):
        utils.cprint()
        utils.print_step('Begin writing telegraf configuration file')

        server_list = data['urls']
        count = len(server_list)
        if not count:
            return False

        conf = tf_utils.get_sample_config('apache')
        if conf is None:
            raise Exception(
                'Cannot obtain apache sample config with telegraf command')

        # add ?auto to url in server_list
        # replace ' with " for toml format
        url_list_str = p_utils.json_dumps(
            [url+"?auto" for url in server_list])
        res = tf_utils.edit_conf(conf, 'urls', url_list_str)

        out.write(res)
        return count
Beispiel #47
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
Beispiel #48
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
Beispiel #49
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.')