Exemplo n.º 1
0
    def build_config(self):
        """Build the config as a Plugins object and return.

        """
        config = agent_config.Plugins()
        if self.found_processes:
            log.info("\tMonitoring by process_name(s): {0} "
                     "for service: {1}.".format(",".join(self.found_processes),
                                                self.service_name))
            for process in self.found_processes:
                # Watch the service processes
                component_name = self.component_name if self.component_name else process
                config.merge(
                    watch_process(search_strings=[process],
                                  service=self.service_name,
                                  component=component_name,
                                  exact_match=False))

        if self.process_username:
            log.info("\tMonitoring by process_username: {0} for "
                     "service: {1}.".format(self.process_username,
                                            self.service_name))
            config.merge(
                watch_process_by_username(username=self.process_username,
                                          process_name=self.component_name,
                                          service=self.service_name,
                                          component=self.component_name))
        if self.file_dirs_names:
            for file_dir_name in self.file_dirs_names:
                # Watch file size
                file_dir = file_dir_name[0]
                file_names = file_dir_name[1]
                if len(file_dir_name) == 3:
                    file_recursive = file_dir_name[2]
                else:
                    file_recursive = False
                if file_names == ['*']:
                    log.info("\tMonitoring the size of all the files in the "
                             "directory {0}.".format(file_dir))
                else:
                    log.info("\tMonitoring the size of files {0} in the "
                             "directory {1}.".format(
                                 ", ".join(str(name) for name in file_names),
                                 file_dir))
                config.merge(
                    watch_file_size(directory_name=file_dir,
                                    file_names=file_names,
                                    file_recursive=file_recursive,
                                    service=self.service_name,
                                    component=self.component_name))

        if self.directory_names:
            for dir_name in self.directory_names:
                log.info(
                    "\tMonitoring the size of directory {0}.".format(dir_name))
                config.merge(
                    watch_directory(directory_name=dir_name,
                                    service=self.service_name,
                                    component=self.component_name))

        # Skip the http_check if disable_http_check is set
        if self.args is not None and self.args.get('disable_http_check',
                                                   False):
            self.service_api_url = None
            self.search_pattern = None

        if self.service_api_url and self.search_pattern:
            # Check if there is something listening on the host/port
            parsed = urllib.parse.urlparse(self.service_api_url)
            host, port = parsed.netloc.split(':')
            listening = find_addrs_listening_on_port(port)

            if len(listening) > 0:
                # If not listening on localhost or ips then use another local ip
                if host == 'localhost' and len(
                        set(['127.0.0.1', '0.0.0.0', '::', '::1'])
                        & set(listening)) == 0:
                    new_url = list(parsed)
                    new_url[1] = listening[0] + ':' + port
                    api_url = urllib.parse.urlunparse(new_url)
                else:
                    api_url = self.service_api_url

                # Setup an active http_status check on the API
                log.info("\tConfiguring an http_check for the {0} API.".format(
                    self.service_name))
                config.merge(
                    service_api_check(name=self.service_name + '-api',
                                      url=api_url,
                                      pattern=self.search_pattern,
                                      use_keystone=True,
                                      service=self.service_name,
                                      component=self.component_name))
            else:
                log.info("\tNo process found listening on {0} ".format(port) +
                         "skipping setup of http_check for the {0} API.".
                         format(self.service_name))

        return config
Exemplo n.º 2
0
    def build_config(self):
        """Build the config as a Plugins object and return.

        """
        config = agent_config.Plugins()
        if self.found_processes:
            log.info("\tMonitoring by process_name(s): {0} "
                     "for service: {1}.".format(",".join(self.found_processes), self.service_name))
            for process in self.found_processes:
                # Watch the service processes
                component_name = self.component_name if self.component_name else process
                config.merge(watch_process(search_strings=[process], service=self.service_name,
                                           component=component_name, exact_match=False))

        if self.process_username:
            log.info("\tMonitoring by process_username: {0} for "
                     "service: {1}.".format(self.process_username, self.service_name))
            config.merge(watch_process_by_username(username=self.process_username,
                                                   process_name=self.component_name,
                                                   service=self.service_name,
                                                   component=self.component_name))
        if self.file_dirs_names:
            for file_dir_name in self.file_dirs_names:
                # Watch file size
                file_dir = file_dir_name[0]
                file_names = file_dir_name[1]
                if len(file_dir_name) == 3:
                    file_recursive = file_dir_name[2]
                else:
                    file_recursive = False
                if file_names == ['*']:
                    log.info("\tMonitoring the size of all the files in the "
                             "directory {0}.".format(file_dir))
                else:
                    log.info("\tMonitoring the size of files {0} in the "
                             "directory {1}.".format(", ".join(str(name) for name in file_names), file_dir))
                config.merge(watch_file_size(directory_name=file_dir, file_names=file_names,
                                             file_recursive=file_recursive, service=self.service_name,
                                             component=self.component_name))

        if self.directory_names:
            for dir_name in self.directory_names:
                log.info("\tMonitoring the size of directory {0}.".format(
                    dir_name))
                config.merge(watch_directory(directory_name=dir_name, service=self.service_name, component=self.component_name))

        # Skip the http_check if disable_http_check is set
        if self.args is not None and self.args.get('disable_http_check', False):
            self.service_api_url = None
            self.search_pattern = None

        if self.service_api_url and self.search_pattern:
            # Check if there is something listening on the host/port
            parsed = urlparse.urlparse(self.service_api_url)
            host, port = parsed.netloc.split(':')
            listening = find_addrs_listening_on_port(port)

            if len(listening) > 0:
                # If not listening on localhost or ips then use another local ip
                if host == 'localhost' and len(set(['127.0.0.1', '0.0.0.0', '::', '::1']) & set(listening)) == 0:
                    new_url = list(parsed)
                    new_url[1] = listening[0] + ':' + port
                    api_url = urlparse.urlunparse(new_url)
                else:
                    api_url = self.service_api_url

                # Setup an active http_status check on the API
                log.info("\tConfiguring an http_check for the {0} API.".format(self.service_name))
                config.merge(service_api_check(name=self.service_name + '-api',
                                               url=api_url,
                                               pattern=self.search_pattern,
                                               use_keystone=True,
                                               service=self.service_name,
                                               component=self.component_name))
            else:
                log.info("\tNo process found listening on {0} ".format(port) +
                         "skipping setup of http_check for the {0} API." .format(self.service_name))

        return config