def check_hive_server(self, env, server_component_name, kinit_cmd, address_list, server_port): import params env.set_params(params) Logger.info("Server Address List : {0}, Port : {1}".format( address_list, server_port)) if not address_list: raise Fail("Can not find any " + server_component_name + " ,host. Please check configuration.") SOCKET_WAIT_SECONDS = 290 start_time = time.time() end_time = start_time + SOCKET_WAIT_SECONDS Logger.info( "Waiting for the {0} to start...".format(server_component_name)) workable_server_available = False i = 0 while time.time() < end_time and not workable_server_available: address = address_list[i] try: check_thrift_port_sasl( address, server_port, params.hive_server2_authentication, params.hive_server_principal, kinit_cmd, params.smokeuser, transport_mode=params.hive_transport_mode, http_endpoint=params.hive_http_endpoint, ssl=params.hive_ssl, ssl_keystore=params.hive_ssl_keystore_path, ssl_password=params.hive_ssl_keystore_password) Logger.info("Successfully connected to {0} on port {1}".format( address, server_port)) workable_server_available = True except: Logger.info("Connection to {0} on port {1} failed".format( address, server_port)) time.sleep(5) i += 1 if i == len(address_list): i = 0 elapsed_time = time.time() - start_time if not workable_server_available: raise Fail( "Connection to '{0}' on host: {1} and port {2} failed after {3} seconds" .format(server_component_name, params.hostname, server_port, elapsed_time)) Logger.info( "Successfully stayed connected to '{0}' on host: {1} and port {2} after {3} seconds" .format(server_component_name, params.hostname, server_port, elapsed_time))
def execute(parameters=None, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: parameters (dictionary): a mapping of parameter key to value host_name (string): the name of this host where the alert is running """ if parameters is None: return (('UNKNOWN', ['There were no parameters supplied to the script.'])) thrift_port = THRIFT_PORT_DEFAULT if HIVE_SERVER_THRIFT_PORT_KEY in parameters: thrift_port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in parameters: security_enabled = bool(parameters[SECURITY_ENABLED_KEY]) result_code = None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() is_thrift_port_ok = hive_check.check_thrift_port_sasl( host_name, thrift_port, security_enabled=security_enabled) if is_thrift_port_ok == True: result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE % (total_time, thrift_port) else: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name, thrift_port) except Exception, e: label = str(e) result_code = 'UNKNOWN'
def execute(parameters=None, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: parameters (dictionary): a mapping of parameter key to value host_name (string): the name of this host where the alert is running """ if parameters is None: return (('UNKNOWN', ['There were no parameters supplied to the script.'])) thrift_port = THRIFT_PORT_DEFAULT if HIVE_SERVER_THRIFT_PORT_KEY in parameters: thrift_port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in parameters: security_enabled = bool(parameters[SECURITY_ENABLED_KEY]) result_code = None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() is_thrift_port_ok = hive_check.check_thrift_port_sasl(host_name, thrift_port, security_enabled=security_enabled) if is_thrift_port_ok == True: result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE % (total_time, thrift_port) else: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name,thrift_port) except Exception, e: label = str(e) result_code = 'UNKNOWN'
def execute(configurations={}, parameters={}, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: configurations (dictionary): a mapping of configuration key to value parameters (dictionary): a mapping of script parameter key to value host_name (string): the name of this host where the alert is running """ if configurations is None: return ('UNKNOWN', ['There were no configurations supplied to the script.']) transport_mode = HIVE_SERVER_TRANSPORT_MODE_DEFAULT if HIVE_SERVER_TRANSPORT_MODE_KEY in configurations: transport_mode = configurations[HIVE_SERVER_TRANSPORT_MODE_KEY] port = THRIFT_PORT_DEFAULT if transport_mode.lower() == 'binary' and HIVE_SERVER_THRIFT_PORT_KEY in configurations: port = int(configurations[HIVE_SERVER_THRIFT_PORT_KEY]) elif transport_mode.lower() == 'http' and HIVE_SERVER_THRIFT_HTTP_PORT_KEY in configurations: port = int(configurations[HIVE_SERVER_THRIFT_HTTP_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in configurations: security_enabled = str(configurations[SECURITY_ENABLED_KEY]).upper() == 'TRUE' hive_server2_authentication = HIVE_SERVER2_AUTHENTICATION_DEFAULT if HIVE_SERVER2_AUTHENTICATION_KEY in configurations: hive_server2_authentication = configurations[HIVE_SERVER2_AUTHENTICATION_KEY] # defaults smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT smokeuser_principal = SMOKEUSER_PRINCIPAL_DEFAULT smokeuser = SMOKEUSER_DEFAULT # check script params if SMOKEUSER_PRINCIPAL_SCRIPT_PARAM_KEY in parameters: smokeuser_principal = parameters[SMOKEUSER_PRINCIPAL_SCRIPT_PARAM_KEY] if SMOKEUSER_SCRIPT_PARAM_KEY in parameters: smokeuser = parameters[SMOKEUSER_SCRIPT_PARAM_KEY] if SMOKEUSER_KEYTAB_SCRIPT_PARAM_KEY in parameters: smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_SCRIPT_PARAM_KEY] # check configurations last as they should always take precedence if SMOKEUSER_PRINCIPAL_KEY in configurations: smokeuser_principal = configurations[SMOKEUSER_PRINCIPAL_KEY] if SMOKEUSER_KEY in configurations: smokeuser = configurations[SMOKEUSER_KEY] result_code = None if security_enabled: hive_server_principal = HIVE_SERVER_PRINCIPAL_DEFAULT if HIVE_SERVER_PRINCIPAL_KEY in configurations: hive_server_principal = configurations[HIVE_SERVER_PRINCIPAL_KEY] if SMOKEUSER_KEYTAB_KEY in configurations: smokeuser_keytab = configurations[SMOKEUSER_KEYTAB_KEY] # Get the configured Kerberos executable search paths, if any if KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY in configurations: kerberos_executable_search_paths = configurations[KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY] else: kerberos_executable_search_paths = None kinit_path_local = get_kinit_path(kerberos_executable_search_paths) kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser_principal}; ") else: hive_server_principal = None kinitcmd=None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() try: hive_check.check_thrift_port_sasl(host_name, port, hive_server2_authentication, hive_server_principal, kinitcmd, smokeuser, transport_mode = transport_mode) result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE.format(total_time, port) except Exception, exception: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name, port, str(exception)) except Exception, e: label = str(e) result_code = 'UNKNOWN'
def execute(parameters=None, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: parameters (dictionary): a mapping of parameter key to value host_name (string): the name of this host where the alert is running """ if parameters is None: return ('UNKNOWN', ['There were no parameters supplied to the script.']) transport_mode = HIVE_SERVER_TRANSPORT_MODE_DEFAULT if HIVE_SERVER_TRANSPORT_MODE_KEY in parameters: transport_mode = parameters[HIVE_SERVER_TRANSPORT_MODE_KEY] port = THRIFT_PORT_DEFAULT if transport_mode.lower( ) == 'binary' and HIVE_SERVER_THRIFT_PORT_KEY in parameters: port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY]) elif transport_mode.lower( ) == 'http' and HIVE_SERVER_THRIFT_HTTP_PORT_KEY in parameters: port = int(parameters[HIVE_SERVER_THRIFT_HTTP_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in parameters: security_enabled = str( parameters[SECURITY_ENABLED_KEY]).upper() == 'TRUE' hive_server2_authentication = HIVE_SERVER2_AUTHENTICATION_DEFAULT if HIVE_SERVER2_AUTHENTICATION_KEY in parameters: hive_server2_authentication = parameters[ HIVE_SERVER2_AUTHENTICATION_KEY] smokeuser_principal = SMOKEUSER_PRINCIPAL_DEFAULT if SMOKEUSER_PRINCIPAL_KEY in parameters: smokeuser_principal = parameters[SMOKEUSER_PRINCIPAL_KEY] smokeuser = SMOKEUSER_DEFAULT if SMOKEUSER_KEY in parameters: smokeuser = parameters[SMOKEUSER_KEY] result_code = None if security_enabled: hive_server_principal = HIVE_SERVER_PRINCIPAL_DEFAULT if HIVE_SERVER_PRINCIPAL_KEY in parameters: hive_server_principal = parameters[HIVE_SERVER_PRINCIPAL_KEY] smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT if SMOKEUSER_KEYTAB_KEY in parameters: smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY] kinit_path_local = get_kinit_path() kinitcmd = format( "{kinit_path_local} -kt {smokeuser_keytab} {smokeuser_principal}; " ) else: hive_server_principal = None kinitcmd = None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() try: hive_check.check_thrift_port_sasl(host_name, port, hive_server2_authentication, hive_server_principal, kinitcmd, smokeuser, transport_mode=transport_mode) result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE.format(total_time, port) except Exception, exception: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name, port, str(exception)) except Exception, e: label = str(e) result_code = 'UNKNOWN'
def execute(configurations={}, parameters={}, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: configurations (dictionary): a mapping of configuration key to value parameters (dictionary): a mapping of script parameter key to value host_name (string): the name of this host where the alert is running """ if configurations is None: return ('UNKNOWN', ['There were no configurations supplied to the script.']) transport_mode = HIVE_SERVER_TRANSPORT_MODE_DEFAULT if HIVE_SERVER_TRANSPORT_MODE_KEY in configurations: transport_mode = configurations[HIVE_SERVER_TRANSPORT_MODE_KEY] port = THRIFT_PORT_DEFAULT if transport_mode.lower( ) == 'binary' and HIVE_SERVER_THRIFT_PORT_KEY in configurations: port = int(configurations[HIVE_SERVER_THRIFT_PORT_KEY]) elif transport_mode.lower( ) == 'http' and HIVE_SERVER_THRIFT_HTTP_PORT_KEY in configurations: port = int(configurations[HIVE_SERVER_THRIFT_HTTP_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in configurations: security_enabled = str( configurations[SECURITY_ENABLED_KEY]).upper() == 'TRUE' hive_server2_authentication = HIVE_SERVER2_AUTHENTICATION_DEFAULT if HIVE_SERVER2_AUTHENTICATION_KEY in configurations: hive_server2_authentication = configurations[ HIVE_SERVER2_AUTHENTICATION_KEY] if hive_server2_authentication != "KERBEROS" and hive_server2_authentication != "NONE": return ('OK', ['']) hive_ssl = False if HIVE_SSL in configurations: hive_ssl = configurations[HIVE_SSL] hive_ssl_keystore_path = None if HIVE_SSL_KEYSTORE_PATH in configurations: hive_ssl_keystore_path = configurations[HIVE_SSL_KEYSTORE_PATH] hive_ssl_keystore_password = None if HIVE_SSL_KEYSTORE_PASSWORD in configurations: hive_ssl_keystore_password = configurations[HIVE_SSL_KEYSTORE_PASSWORD] # defaults smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT smokeuser_principal = SMOKEUSER_PRINCIPAL_DEFAULT smokeuser = SMOKEUSER_DEFAULT # check script params if SMOKEUSER_PRINCIPAL_SCRIPT_PARAM_KEY in parameters: smokeuser_principal = parameters[SMOKEUSER_PRINCIPAL_SCRIPT_PARAM_KEY] if SMOKEUSER_SCRIPT_PARAM_KEY in parameters: smokeuser = parameters[SMOKEUSER_SCRIPT_PARAM_KEY] if SMOKEUSER_KEYTAB_SCRIPT_PARAM_KEY in parameters: smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_SCRIPT_PARAM_KEY] # check configurations last as they should always take precedence if SMOKEUSER_PRINCIPAL_KEY in configurations: smokeuser_principal = configurations[SMOKEUSER_PRINCIPAL_KEY] if SMOKEUSER_KEY in configurations: smokeuser = configurations[SMOKEUSER_KEY] result_code = None if security_enabled: hive_server_principal = HIVE_SERVER_PRINCIPAL_DEFAULT if HIVE_SERVER_PRINCIPAL_KEY in configurations: hive_server_principal = configurations[HIVE_SERVER_PRINCIPAL_KEY] if SMOKEUSER_KEYTAB_KEY in configurations: smokeuser_keytab = configurations[SMOKEUSER_KEYTAB_KEY] # Get the configured Kerberos executable search paths, if any if KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY in configurations: kerberos_executable_search_paths = configurations[ KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY] else: kerberos_executable_search_paths = None kinit_path_local = get_kinit_path(kerberos_executable_search_paths) kinitcmd = format( "{kinit_path_local} -kt {smokeuser_keytab} {smokeuser_principal}; " ) else: hive_server_principal = None kinitcmd = None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() try: hive_check.check_thrift_port_sasl( host_name, port, hive_server2_authentication, hive_server_principal, kinitcmd, smokeuser, transport_mode=transport_mode, ssl=hive_ssl, ssl_keystore=hive_ssl_keystore_path, ssl_password=hive_ssl_keystore_password) result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE.format(total_time, port) except: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name, port, traceback.format_exc()) except: label = traceback.format_exc() result_code = 'UNKNOWN' return (result_code, [label])
def execute(parameters=None, host_name=None): """ Returns a tuple containing the result code and a pre-formatted result label Keyword arguments: parameters (dictionary): a mapping of parameter key to value host_name (string): the name of this host where the alert is running """ if parameters is None: return (('UNKNOWN', ['There were no parameters supplied to the script.'])) transport_mode = HIVE_SERVER_TRANSPORT_MODE_DEFAULT if HIVE_SERVER_TRANSPORT_MODE_KEY in parameters: transport_mode = parameters[HIVE_SERVER_TRANSPORT_MODE_KEY] port = THRIFT_PORT_DEFAULT if transport_mode.lower() == 'binary' and HIVE_SERVER_THRIFT_PORT_KEY in parameters: port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY]) elif transport_mode.lower() == 'http' and HIVE_SERVER_THRIFT_HTTP_PORT_KEY in parameters: port = int(parameters[HIVE_SERVER_THRIFT_HTTP_PORT_KEY]) security_enabled = False if SECURITY_ENABLED_KEY in parameters: security_enabled = str(parameters[SECURITY_ENABLED_KEY]).upper() == 'TRUE' hive_server2_authentication = HIVE_SERVER2_AUTHENTICATION_DEFAULT if HIVE_SERVER2_AUTHENTICATION_KEY in parameters: hive_server2_authentication = parameters[HIVE_SERVER2_AUTHENTICATION_KEY] smokeuser_principal = SMOKEUSER_PRINCIPAL_DEFAULT if SMOKEUSER_PRINCIPAL_KEY in parameters: smokeuser_principal = parameters[SMOKEUSER_PRINCIPAL_KEY] smokeuser = SMOKEUSER_DEFAULT if SMOKEUSER_KEY in parameters: smokeuser = parameters[SMOKEUSER_KEY] result_code = None if security_enabled: hive_server_principal = HIVE_SERVER_PRINCIPAL_DEFAULT if HIVE_SERVER_PRINCIPAL_KEY in parameters: hive_server_principal = parameters[HIVE_SERVER_PRINCIPAL_KEY] smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT if SMOKEUSER_KEYTAB_KEY in parameters: smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY] kinit_path_local = get_kinit_path() kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser_principal}; ") else: hive_server_principal = None kinitcmd=None try: if host_name is None: host_name = socket.getfqdn() start_time = time.time() try: hive_check.check_thrift_port_sasl(host_name, port, hive_server2_authentication, hive_server_principal, kinitcmd, smokeuser, transport_mode = transport_mode) is_thrift_port_ok = True except: is_thrift_port_ok = False if is_thrift_port_ok == True: result_code = 'OK' total_time = time.time() - start_time label = OK_MESSAGE % (total_time, port) else: result_code = 'CRITICAL' label = CRITICAL_MESSAGE.format(host_name,port) except Exception, e: label = str(e) result_code = 'UNKNOWN'