def title(self): utils.cprint( ' ____ _ \n' ' / ___|__ _ ___ ___ __ _ _ __ __| |_ __ __ _ \n' ' | | / _` / __/ __|/ _` | \'_ \ / _` | \'__/ _` |\n' ' | |__| (_| \__ \__ \ (_| | | | | (_| | | | (_| |\n' ' \____\__,_|___/___/\__,_|_| |_|\__,_|_| \__,_|\n')
def check_server_url(url, url_list=[]): """ check if the url provided is a valid server-status page Input: url string: the url provided by the user url_list []string: list of url user has monitored already Output: True if the user provides a valid url False otherwise """ ret_val = False if not p_utils.check_url(url, url_list): return False res = utils.get_command_output('curl -s {url}'.format(url=url)) status = check_apache_server_status(res) if status is None: utils.print_warn( 'The url you have provided ' 'does not seem to be the correct server_status ' 'page. Incorrect server-status will not be ' 'recorded.') utils.cprint() record = utils.ask( 'Would you like to record this url anyway?', 'no') if record: ret_val = True else: utils.cprint( 'Monitoring {}'.format(status)) ret_val = True return ret_val
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
def check_server_url(url, url_list=[]): """ check if the url provided is a valid server-status page Input: url string: the url provided by the user url_list []string: list of url user has monitored already Output: True if the user provides a valid url False otherwise """ ret_val = False if not p_utils.check_url(url, url_list): return False res = utils.get_command_output('curl -s {url}'.format(url=url)) status = check_apache_server_status(res) if status is None: utils.print_warn('The url you have provided ' 'does not seem to be the correct server_status ' 'page. Incorrect server-status will not be ' 'recorded.') utils.cprint() record = utils.ask('Would you like to record this url anyway?', 'no') if record: ret_val = True else: utils.cprint('Monitoring {}'.format(status)) ret_val = True return ret_val
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
def title(self): utils.cprint( '__________ __ \n' '\____ /____ ____ | | __ ____ ____ ______ ___________ \n' ' / // _ \ / _ \| |/ // __ \_/ __ \\\\____ \_/ __ \_ __ \ \n' ' / /( <_> | <_> ) <\ ___/\ ___/| |_> > ___/| | \/ \n' '/_______ \____/ \____/|__|_ \\\\___ >\___ > __/ \___ >__| \n' ' \/ \/ \/ \/|__| \/ \n')
def overview(): utils.cprint() utils.cprint('To collect metrics from Nginx server, the following\n' 'steps need to be taken:\n' '1. http_stub_status_module for nginx needs to be enabled.\n' '2. Enable the nginx-status page for each virtual host.\n') _ = utils.cinput('Press Enter to continue')
def url_usage(self): utils.cprint() utils.cprint( 'JMXService URL syntax:\n' '\tservice:jmx:rmi:sap\n' 'where one of the accepted syntax includes:\n' '\tservice:jmx:rmi:///jndi/rmi://[TARGET_MACHINE]:' '[RMI_REGISTRY_PORT]/jmxrmi\n')
def title(): utils.cprint( ' _____ __________ _____ _________ ___ ______________\n' ' / _ \\______ \/ _ \ \_ ___ \ / | \_ _____/\n' ' / /_\ \| ___/ /_\ \/ \ \// ~ \ __)_ \n' ' / | \ | / | \ \___\ Y / \ \n' ' \____|__ /____| \____|__ /\______ /\___|_ /_______ /\n' ' \/ \/ \/ \/ \/ \n')
def title(self): utils.cprint( " _____ _ _ _ _____ _ \n" "| ___| | | | (_) / ___| | | \n" "| |__ | | __ _ ___| |_ _ ___\ `--. ___ __ _ _ __ ___| |__ \n" "| __|| |/ _` / __| __| |/ __|`--. \/ _ \/ _` | '__/ __| '_ \ \n" "| |___| | (_| \__ \ |_| | (__/\__/ / __/ (_| | | | (__| | | |\n" "\____/|_|\__,_|___/\__|_|\___\____/ \___|\__,_|_| \___|_| |_|\n")
def title(): utils.cprint( ' _____ __________ _____ _________ ___ ______________\n' ' / _ \\______ \/ _ \ \_ ___ \ / | \_ _____/\n' ' / /_\ \| ___/ /_\ \/ \ \// ~ \ __)_ \n' ' / | \ | / | \ \___\ Y / \ \n' ' \____|__ /____| \____|__ /\______ /\___|_ /_______ /\n' ' \/ \/ \/ \/ \/ \n')
def title(self): utils.cprint( ' __ __ _ _ \n' '| \/ | | | | |\n' '| \ / | ___ _ __ ___ ___ __ _ ___ | |__ ___ __| |\n' '| |\/| | / _ \| \'_ ` _ \ / __|/ _` | / __|| \'_ \ / _ \ / `|\n' '| | | || __/| | | | | || (__| (_| || (__ | | | || __/| (_| |\n' '|_| |_| \___||_| |_| |_| \___|\__,_| \___||_| |_| \___| \__,_|\n')
def check_collectd_conf_dir(): """ Check if managed_config directory exists, if not, create one. """ res = utils.check_path_exists(config.COLLECTD_CONF_DIR) if not res: utils.cprint('Creating collectd managed config dir') utils.call_command('mkdir ' + config.COLLECTD_CONF_DIR)
def title(self): utils.cprint( ' __ __ _ _ \n' '| \/ | | | | |\n' '| \ / | ___ _ __ ___ ___ __ _ ___ | |__ ___ __| |\n' '| |\/| | / _ \| \'_ ` _ \ / __|/ _` | / __|| \'_ \ / _ \ / `|\n' '| | | || __/| | | | | || (__| (_| || (__ | | | || __/| (_| |\n' '|_| |_| \___||_| |_| |_| \___|\__,_| \___||_| |_| \___| \__,_|\n' )
def check_collectd_conf_dir(): """ Check if managed_config directory exists, if not, create one. """ res = utils.check_path_exists(config.COLLECTD_CONF_DIR) if not res: utils.cprint('Creating collectd managed config dir') utils.call_command('mkdir ' + config.COLLECTD_CONF_DIR)
def title(): utils.cprint(' **** ** ** \n' '/**/** /** ***** // \n' '/**//** /** **///** ** ******* ** **\n' '/** //** /**/** /**/**//**///**//** ** \n' '/** //**/**//******/** /** /** //*** \n' '/** //**** /////**/** /** /** **/** \n' '/** //*** ***** /** *** /** ** //**\n' '// /// ///// // /// // // // \n')
def title(self): utils.cprint( "______ _ _____ _____ _ \n" "| ___ \ | | / ___|| _ | | \n" "| |_/ /__ ___| |_ __ _ _ __ ___ ___ \ `--. | | | | | \n" "| __/ _ \/ __| __/ _` | '__/ _ \/ __| `--. \| | | | | \n" "| | | (_) \__ \ || (_| | | | __/\__ \/\__/ /\ \/' / |____\n" "\_| \___/|___/\__\__, |_| \___||___/\____/ \_/\_\_____/\n" " __/ | \n" " |___/ ")
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')
def title(self): utils.cprint( ' **** **** ******** ******* ** \n' '/**/** **/** ** ** **////// **/////** /** \n' '/**//** ** /** //** ** /** ** //** /** \n' '/** //*** /** //*** /*********/** /** /** \n' '/** //* /** /** ////////**/** **/** /** \n' '/** / /** ** /**//** // ** /** \n' '/** /** ** ******** //******* **/********\n' '// // // //////// /////// // ////////\n')
def title(self): utils.cprint( "______ _ _____ _____ _ \n" "| ___ \ | | / ___|| _ | | \n" "| |_/ /__ ___| |_ __ _ _ __ ___ ___ \ `--. | | | | | \n" "| __/ _ \/ __| __/ _` | '__/ _ \/ __| `--. \| | | | | \n" "| | | (_) \__ \ || (_| | | | __/\__ \/\__/ /\ \/' / |____\n" "\_| \___/|___/\__\__, |_| \___||___/\____/ \_/\_\_____/\n" " __/ | \n" " |___/ ")
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))
def title(self): art = ( ' **** **** ******** ******* ** \n' '/**/** **/** ** ** **////// **/////** /** \n' '/**//** ** /** //** ** /** ** //** /** \n' '/** //*** /** //*** /*********/** /** /** \n' '/** //* /** /** ////////**/** **/** /** \n' '/** / /** ** /**//** // ** /** \n' '/** /** ** ******** //******* **/********\n' '// // // //////// /////// // ////////\n') utils.cprint(art)
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')
def overview(): utils.cprint() utils.cprint( 'In order to monitor a apache server, the following ' 'steps need to be taken:\n' '1. mod_status for apache needs to be enabled. ' '(Default is enabled)\n' '2. ExtendedStatus needs to be turned on. (Default is off)\n' '3. Enable the server-status handler for each virtual host.\n') _ = utils.cinput('Press Enter to continue')
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')
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')
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')
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')
def overview(): utils.cprint() utils.cprint( 'In order to monitor a apache server, the following ' 'steps need to be taken:\n' '1. mod_status for apache needs to be enabled. ' '(Default is enabled)\n' '2. ExtendedStatus needs to be turned on. (Default is off)\n' '3. Enable the server-status handler for each virtual host.\n') _ = utils.cinput('Press Enter to continue')
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')
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')
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')
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')
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')
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')
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))
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
def title(self): utils.cprint( ",-.----. \n" "\ / \ ,---, ,--, \n" "; : \ ,---.'|,--.'| \n" "| | .\ : | | :| |, .--.--. \n" ". : |: | ,---. | | |`--'_ / / ' \n" "| | \ : / \ ,--.__| |,' ,'| | : /`./ \n" "| : . / / / | / ,' |' | | | : ;_ \n" "; | | \ . ' / |. ' / || | : \ \ `. \n" "| | ;\ \\' ; /|' ; |: |' : |__ `----. \ \n" ": ' | \.'' | / || | '/ '| | '.'| / /`--' / \n" ": : :-' | : || : :|; : ;'--'. / \n" "| |.' \ \ / \ \ / | , / `--'---' \n" "`---' `----' `----' ---`-' \n")
def plugin_usage(): utils.cprint( 'To monitor a apache server, ' 'you must enable the server-status page.\n' 'To enable a server-status page, the following code in quote\n' '"<Location /server-status>\n' ' SetHandler server-status\n' '</Location>"\n' 'must be included within a <VirtualHost> block ' 'for the .conf file of your server.\n\n' 'To check whether the server-status page is working, ' 'please visit\n' '\tyour-server-name/server-status\n' 'It should look similar to\n' '\tapache.org/server-status\n')
def title(self): utils.cprint( ",-.----. \n" "\ / \ ,---, ,--, \n" "; : \ ,---.'|,--.'| \n" "| | .\ : | | :| |, .--.--. \n" ". : |: | ,---. | | |`--'_ / / ' \n" "| | \ : / \ ,--.__| |,' ,'| | : /`./ \n" "| : . / / / | / ,' |' | | | : ;_ \n" "; | | \ . ' / |. ' / || | : \ \ `. \n" "| | ;\ \\' ; /|' ; |: |' : |__ `----. \ \n" ": ' | \.'' | / || | '/ '| | '.'| / /`--' / \n" ": : :-' | : || : :|; : ;'--'. / \n" "| |.' \ \ / \ \ / | , / `--'---' \n" "`---' `----' `----' ---`-' \n")
def plugin_usage(): utils.cprint( 'To monitor a apache server, ' 'you must enable the server-status page.\n' 'To enable a server-status page, the following code in quote\n' '"<Location /server-status>\n' ' SetHandler server-status\n' '</Location>"\n' 'must be included within a <VirtualHost> block ' 'for the .conf file of your server.\n\n' 'To check whether the server-status page is working, ' 'please visit\n' '\tyour-server-name/server-status\n' 'It should look similar to\n' '\tapache.org/server-status\n')
def plugin_usage(): utils.cprint( 'To monitor a nginx server, ' 'you must enable a server-status page.\n' 'To enable a server-status page, the following code in quote\n' '"location /server-status{\n' ' stub_status on;\n' ' access_log off;\n' ' allow 127.0.0.1;\n' ' # deny all;\n' '}"\n' 'must be included within a server block ' 'for the .conf file of your server.\n\n' 'To check whether the server-status page is working, ' 'please visit\n' '\tyour-server-name/server-status\n')
def usage(): """ Deprecated deprecated by argparse module """ utils.cprint( "Usage: gather_metrics [operating system(DEBIAN|REDHAT)] " "[agent(COLLECTD|TELEGRAF)] [APP_DIR] [log file] [-TEST]\n" "operating system:\n" " Determines the installer control flow.\n" "agent:\n" " Determines the directory path.\n" "app_dir:\n" " The location of WF-PCInstaller where setup.py resides.\n" "log_file:\n" " Errors will log to this file.\n" "-TEST:\n" " Installs all detected applications with default setting.\n" " This is for integeration test. Default is off.\n")
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('nginx') 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, 'urls', server_list_str) out.write(res) return True
def edit_conf(conf, key, value): """ read the sample config and modify the appropriate field Input: key string - the key field in the conf value string - the corresponding key value Output: res_conf string - the configuration string with the proper field changed use regex substitute key = (old value) with the supplied key = value """ # regex search for key search_re = re.compile( r'{key} = '.format(key=key), re.I) # break the conf by new line since the telegraf # conf has key = value format per line conf_list = conf.split('\n') for index, line in enumerate(conf_list): search_res = search_re.search(line) if search_res is not None: conf_list[index] = ( re.sub( r'{key} = .*'.format(key=key), '{key} = {value}'.format(key=key, value=value), line)) # make sure new line is reinserted res_conf = '\n'.join(conf_list) if config.DEBUG: utils.cprint('After change:') utils.cprint(res_conf) return res_conf
def check_JMXServiceURL(self, url): if url is None: return False # parse character following RFC 2609 for char in url: c = ord(char) if c < 32 or c >= 127: utils.print_color_msg( 'Service URL cannot contain non-ASCII character' 'such as {}'.format(hex(c)), utils.YELLOW) return False url_len = len(url) # parse prefix requiredPrefix_re = re.match(r'service:jmx:(.*)', url) if requiredPrefix_re is None: utils.print_color_msg( 'JMXServiceURL must start with service:jmx:', utils.YELLOW) return False # working example: # "service:jmx:rmi:///jndi/rmi://localhost:7199/jmxrmi" rest = requiredPrefix_re.group(1) # parse protocol rest_re = re.search( r'(.*?)://(.*)', rest) if rest_re is None: utils.print_color_msg( 'Missing :// after protocol', utils.YELLOW) return False protocol = rest_re.group(1) if not protocol[0].isalpha(): utils.cprint('Invalid protocol: {}'.format(protocol)) return False return True
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
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
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