def build_config(self): """Build the config as a Plugins object and return. """ config = monasca_setup.agent_config.Plugins() # First watch the process config.merge(monasca_setup.detection.watch_process(['epmd'], 'rabbitmq', detailed=False)) log.info("\tWatching the rabbitmq-server process.") config.merge( monasca_setup.detection.watch_process_by_username( 'rabbitmq', 'rabbitmq', 'rabbitmq')) log.info("\tWatching all processes owned by the rabbitmq user.") if not self._watch_api: return config try: self._get_config() # Then watch the http status check service_name = 'rabbitmq' # Setup an active http_status check on the API if self.api_url.endswith("/"): check_api_url = self.api_url else: check_api_url = self.api_url + "/" log.info("\tConfiguring an http_check for the {0} API.".format( service_name)) config.merge(service_api_check(service_name, check_api_url, '.*RabbitMQ.*', use_keystone=False, service=service_name)) if self._login_test(): instance_config = {'name': self.api_url, 'rabbitmq_api_url': self.api_url, 'rabbitmq_user': self.user, 'rabbitmq_pass': self.password} if self.queues is not None: instance_config['queues'] = self._split_list(self.queues) if self.exchanges is not None: instance_config['exchanges'] = self._split_list(self.exchanges) if self.nodes is not None: instance_config['nodes'] = self._split_list(self.nodes) config['rabbitmq'] = {'init_config': None, 'instances': [instance_config]} else: exception_msg = 'Unable to access the RabbitMQ admin URL; ' \ 'the RabbitMQ plugin is not configured. ' \ 'Please correct and re-run monasca-setup.' log.error(exception_msg) raise Exception(exception_msg) except Exception: exception_msg = 'Error configuring the RabbitMQ check plugin' log.exception(exception_msg) raise Exception(exception_msg) return config
def build_config(self): """Build the config as a Plugins object and return. """ config = agent_config.Plugins() for process in self.found_processes: # Watch the service processes log.info("\tMonitoring the {0} {1} process.".format( process, self.service_name)) config.merge( watch_process([process], self.service_name, process, exact_match=False)) # 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 = [] for connection in psutil.net_connections(): if connection.status == psutil.CONN_LISTEN and connection.laddr[ 1] == int(port): listening.append(connection.laddr[0]) 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(self.service_name + '-api', api_url, self.search_pattern, self.service_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
def build_config(self): """Build the config as a Plugins object and return. """ config = agent_config.Plugins() for process in self.found_processes: # Watch the service processes log.info("\tMonitoring the {0} {1} process.".format(process, self.service_name)) config.merge(watch_process([process], self.service_name, process, exact_match=False)) # 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 = [] for connection in psutil.net_connections(): if connection.status == psutil.CONN_LISTEN and connection.laddr[1] == int(port): listening.append(connection.laddr[0]) 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(self.service_name + '-api', api_url, self.search_pattern, self.service_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
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
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