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 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
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 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
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
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
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
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 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
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 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: ret_val bool: True if 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_nginx_status(res) if not status: 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.') record = utils.ask('Would you like to record this url anyway?', 'no') if record: ret_val = True else: ret_val = True return ret_val
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 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 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
def check_dependency(os): """ Apache checklist: - check curl - mod_status - extended status """ utils.print_step('Checking dependency') if not utils.command_exists('curl'): raise Exception('Curl is needed for this plugin.') # ubuntu check # Assumption: # -latest apache2 is installed and the installation # -directory is in the default place if os == config.DEBIAN: utils.print_step(' Checking if mod_status is enabled') cmd_res = utils.get_command_output('ls /etc/apache2/mods-enabled') if cmd_res is None: utils.eprint( 'Apache2 mods-enabled folder is not ' 'found /etc/apache2/mods-enabled.') utils.print_failure() elif 'status.conf' not in cmd_res or 'status.load' not in cmd_res: utils.print_step('Enabling apache2 mod_status module.') ret = utils.call_command('sudo a2enmod status') if ret != 0: utils.print_failure() raise Exception('a2enmod command was not found') utils.print_success() else: utils.print_success() elif os == config.REDHAT: utils.cprint() utils.cprint( 'To enable server status page for the apache web,\n' 'ensure that mod_status.so module is enabled.\n' 'This module is often enabled by default.\n' '"LoadModule status_module modules/mod_status.so"\n' 'such line should be included in one of the conf files.\n') _ = utils.cinput('Press Enter to continue.') utils.cprint() utils.cprint( 'In order to fully utilize the server_status metrics,\n' 'the ExtendedStatus setting needs be turned on.\n' 'This setting can be turned on by having "ExtendedStatus on"\n' 'in one of the .conf file.\n') utils.cprint( 'If you have already enabled this status, ' 'answer "no" to the next question.\n' 'If you would like us to enable this status, ' 'answer "yes" and we will ' 'include a extendedstatus.conf file in your apache folder.\n') res = utils.ask( 'Would you like us to enable ' 'the ExtendedStatus?') if res: # dir changes depending on the system # tested on Ubuntu 14.04, RHEL 7.2 if os == config.DEBIAN: conf_dir = '/etc/apache2/conf-enabled' app_name = 'apache2' elif os == config.REDHAT: conf_dir = '/etc/httpd/conf.d' app_name = 'httpd' utils.print_step('Checking if ' + conf_dir + ' exists.') if utils.check_path_exists(conf_dir): # pull config file here utils.print_success() include_apache_es_conf(conf_dir) utils.cprint( 'extendedstatus.conf is now included in the ' '{0} dir.\n'.format(conf_dir)) utils.print_step('Restarting apache') ret = utils.call_command( 'service {app_name} restart >> ' '{log} 2>&1'.format( app_name=app_name, log=config.INSTALL_LOG)) if ret != 0: raise Exception( 'Failed to restart apache service.') utils.print_success() else: raise Exception( '{cond_dir} dir does not exist. Manual ' 'set up is required. For help, please ' 'consult [email protected]'.format( conf_dir=conf_dir))
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
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
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
def check_dependency(os): """ Apache checklist: - check curl - mod_status - extended status """ utils.print_step('Checking dependency') if not utils.command_exists('curl'): raise Exception('Curl is needed for this plugin.') # ubuntu check # Assumption: # -latest apache2 is installed and the installation # -directory is in the default place if os == config.DEBIAN: utils.print_step(' Checking if mod_status is enabled') cmd_res = utils.get_command_output('ls /etc/apache2/mods-enabled') if cmd_res is None: utils.eprint('Apache2 mods-enabled folder is not ' 'found /etc/apache2/mods-enabled.') utils.print_failure() elif 'status.conf' not in cmd_res or 'status.load' not in cmd_res: utils.print_step('Enabling apache2 mod_status module.') ret = utils.call_command('sudo a2enmod status') if ret != 0: utils.print_failure() raise Exception('a2enmod command was not found') utils.print_success() else: utils.print_success() elif os == config.REDHAT: utils.cprint() utils.cprint( 'To enable server status page for the apache web,\n' 'ensure that mod_status.so module is enabled.\n' 'This module is often enabled by default.\n' '"LoadModule status_module modules/mod_status.so"\n' 'such line should be included in one of the conf files.\n') _ = utils.cinput('Press Enter to continue.') utils.cprint() utils.cprint( 'In order to fully utilize the server_status metrics,\n' 'the ExtendedStatus setting needs be turned on.\n' 'This setting can be turned on by having "ExtendedStatus on"\n' 'in one of the .conf file.\n') utils.cprint('If you have already enabled this status, ' 'answer "no" to the next question.\n' 'If you would like us to enable this status, ' 'answer "yes" and we will ' 'include a extendedstatus.conf file in your apache folder.\n') res = utils.ask('Would you like us to enable ' 'the ExtendedStatus?') if res: # dir changes depending on the system # tested on Ubuntu 14.04, RHEL 7.2 if os == config.DEBIAN: conf_dir = '/etc/apache2/conf-enabled' app_name = 'apache2' elif os == config.REDHAT: conf_dir = '/etc/httpd/conf.d' app_name = 'httpd' utils.print_step('Checking if ' + conf_dir + ' exists.') if utils.check_path_exists(conf_dir): # pull config file here utils.print_success() include_apache_es_conf(conf_dir) utils.cprint('extendedstatus.conf is now included in the ' '{0} dir.\n'.format(conf_dir)) utils.print_step('Restarting apache') ret = utils.call_command('service {app_name} restart >> ' '{log} 2>&1'.format( app_name=app_name, log=config.INSTALL_LOG)) if ret != 0: raise Exception('Failed to restart apache service.') utils.print_success() else: raise Exception( '{cond_dir} dir does not exist. Manual ' 'set up is required. For help, please ' 'consult [email protected]'.format(conf_dir=conf_dir))
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
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
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
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
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