def handle_POST(self): try: pre_taskserverport = self.read_taskserver_port() payload = loads(self.request['payload']) self.check_java_home(payload) # check whether the javaHome is valid self.validate_java_home(payload["javaHome"]) self.update_vmopts(payload) splunk_service = SplunkServiceFactory.create(self.sessionKey, app='splunk_app_db_connect', owner=self.userName) entity = client.Entity(splunk_service, self.endpoint) entity.update(**payload).refresh() logger.debug('updated java settings') self.update_dbx_java_home(payload["javaHome"]) self.reset_java_command_filename(splunk_service) self.read_vmopts(entity.content) self.restart_task_server(pre_taskserverport) self.writeJson(entity.content) except Exception as ex: self.response.setStatus(500) self.writeJson({ "code": 500, "message": ex.message, "detail": str(ex) })
def handle_GET(self): try: splunk_service = SplunkServiceFactory.create(self.sessionKey, app='splunk_app_db_connect', owner=self.userName) content = client.Entity(splunk_service, self.endpoint).content self.writeJson(content) except Exception as ex: self.response.setStatus(500) self.writeJson({ "code": 500, "message": ex.message, "detail": str(ex) })
def _check_java_installation_health(self): platform = self._detect_platform_dir() path_to_customized_java = os.path.join(self.path_to_app, platform, "bin", "customized.java.path") final_status = Status.OK final_details = [] if not os.path.isfile(path_to_customized_java): # check if $JAVA_HOME/bin/java satisfies the requirement of JAVA 8 if JAVA_HOME is defined java_home = os.getenv("JAVA_HOME") if java_home: logger.debug("JAVA_HOME is {}".format(java_home)) java_cmd = os.path.join(java_home, "bin", "java") else: logger.debug( "JAVA_HOME is not specified. Use default java command.") java_cmd = "java" # validating java command is_healthy, detail = validateJRE(java_cmd) if is_healthy: splunk_service = SplunkServiceFactory.create( self.sessionKey, app='splunk_app_db_connect', owner=self.userName) result = self._check_commands(splunk_service) result.append( self._check_modular_alert_java_conf(splunk_service)) # we reduce the results for status, details in result: if status != Status.OK: final_status = Status.ERROR final_details.append(details) else: final_status = Status.ERROR final_details.append(detail) else: # check the content of customized.java.path with open(path_to_customized_java, 'r') as customized_java_file: java_cmd = customized_java_file.readline().strip() is_healthy, final_details = validateJRE(java_cmd) if not is_healthy: final_status = Status.ERROR return self._create_health_check_result(final_status, final_details)
def handle_POST(self): try: payload = loads(self.request['payload']) splunk_service = SplunkServiceFactory.create(self.sessionKey, app='splunk_app_db_connect', owner=self.userName) entity = client.Entity(splunk_service, self.endpoint) # first update file first self.update_log_level(payload, splunk_service) # update the entity in conf file entity.update(**payload).refresh() self.writeJson(entity.content) except Exception as ex: self.response.setStatus(500) self.writeJson({ "code": 500, "message": ex.message, "detail": str(ex) })
import dbx_bootstrap_env import splunk.Intersplunk as interSplunk from dbx2.splunk_client.splunk_service_factory import SplunkServiceFactory import splunklib.client as client # get data volume per source type results, dummy_results, settings = interSplunk.getOrganizedResults() splunk_service = SplunkServiceFactory.create(session_key=settings['sessionKey'], app=settings['namespace'], owner=settings['owner']) all_inputs = client.Collection(splunk_service, 'configs/conf-db_inputs').list() # get all source types. source_types = set([x.content.get('sourcetype') for x in all_inputs if 'splunk_app_db_connect' == x.content.get('eai:appName')]) # get data volume per source type. output = [x for x in results if x.get('series') in source_types] # return result interSplunk.outputResults(output)
def _get_svc(self): return SplunkServiceFactory.create(session_key=self.sessionKey, app=self.context['app'], owner=self.context['user'])