def handleEdit(self, confInfo): if self.callerArgs.id == 'jira': jira_settings = get_jira_settings(splunk.getLocalServerInfo(), self.getSessionKey()) if 'jira_url' in self.callerArgs: jira_settings['jira_url'] = self.callerArgs['jira_url'][0] if 'jira_username' in self.callerArgs: jira_settings['jira_username'] = self.callerArgs[ 'jira_username'][0] if 'jira_password' in self.callerArgs: password = self.callerArgs['jira_password'][0] if password and password != PASSWORD_PLACEHOLDER: jira_settings['jira_password'] = password for k in DEFAULT_SETTINGS: if 'default_' + k in self.callerArgs: jira_settings[k] = self.callerArgs['default_' + k][0] if not validate_jira_settings(jira_settings): raise admin.ArgValidationException, "Error connecting to JIRA server" update_jira_settings(jira_settings, splunk.getLocalServerInfo(), self.getSessionKey()) if 'import' in self.callerArgs and self.callerArgs['import'][ 0] in ('1', 'true'): try: generate_jira_dialog(jira_settings, splunk.getLocalServerInfo(), self.getSessionKey()) except Exception, e: raise admin.AdminManagerException( "Error importing settings from Jira, check server URL and credentials: " + str(e))
def rulethresholds(self, **kwargs): try: if cherrypy.request.method == 'POST': localServerInfo = urlparse(splunk.getLocalServerInfo()) host, port = localServerInfo.netloc.split(':') splunk_url = localServerInfo.scheme + host + ':' + port user_id = cherrypy.session['user']['id'] username = cherrypy.session['user']['name'] session_key = splunk.getSessionKey() rule = json.loads(cherrypy.request.body.read()) rule_definitions = read_file_contents(LOOKUP_FILE_PATH) try: check_rule_threshold_types(rule, rule_definitions) except Exception as exc: raise Exception( "Error checking rule (rule: '{rule}') (cause: '{cause}')" .format(rule=repr(rule), cause=str(exc))) try: write_threshold_macro_values(rule) except Exception as exc: raise Exception( "Error updating macros.conf file (cause: '{cause}')". format(cause=str(exc))) try: written_rule = write_threshold_lookup_values( rule, rule_definitions) except Exception as exc: raise Exception( "Error updating rule_thresholds.csv file (cause: '{cause}')" .format(cause=str(exc))) if len(written_rule['thresholds']) > 0: try: write_user_actions_values(written_rule, user_id, username) except Exception as exc: raise Exception( "Error writing user action parameters to file (cause: '{cause}')" .format(cause=str(exc))) try: run_saved_searches(written_rule, splunk_url, username, session_key) except Exception as exc: raise Exception( "Error running saved searches (cause: '{cause}')". format(cause=str(exc))) cherrypy.response.status = 200 return json.dumps({'status': 'OK'}) except Exception as exc: cherrypy.response.status = 500 logger.exception("Error (traceback.format_exc() = '%s')", traceback.format_exc()) return json.dumps({'status': 'error', 'message': str(exc)})
def handleList(self, confInfo): app_conf = AppConf(splunk.getLocalServerInfo(), self.getSessionKey()) config = app_conf.get_config('customcommand') settings = config['customcommand'] if 'customcommand' in config else {} item = confInfo['customcommand'] item['url'] = settings['url'] if settings['url'] else 'http://your.server/' item['username'] = settings['username'] if settings['username'] else '' item['password'] = PASSWORD_PLACEHOLDER
def handleList(self, confInfo): app_conf = AppConf(splunk.getLocalServerInfo(), self.getSessionKey()) config = app_conf.get_config(self.callerArgs.id) settings = config['jirasend'] if 'jirasend' in config else {} item = confInfo['jirasend'] item['jira_url'] = settings['jira_url'] if settings['jira_url'] else 'http://your.server/' item['jira_username'] = settings['jira_username'] if settings['jira_username'] else '' item['jira_password'] = PASSWORD_PLACEHOLDER
def handleList(self, confInfo): app_conf = AppConf(splunk.getLocalServerInfo(), self.getSessionKey()) config = app_conf.get_config('customcommand') settings = config['customcommand'] if 'customcommand' in config else {} item = confInfo['customcommand'] item['url'] = settings['url'] if settings[ 'url'] else 'http://your.server/' item['username'] = settings['username'] if settings['username'] else '' item['password'] = PASSWORD_PLACEHOLDER
def handleList(self, confInfo): jira_settings = get_jira_settings(splunk.getLocalServerInfo(), self.getSessionKey()) item = confInfo['jira'] item['jira_url'] = jira_settings.get('jira_url', 'http://your.server/') item['jira_username'] = jira_settings.get('jira_username') item['jira_password'] = PASSWORD_PLACEHOLDER for k in DEFAULT_SETTINGS: item['default_' + k] = jira_settings.get(k, '') item['import'] = '0'
def get_service(): localServerInfo = urlparse(splunk.getLocalServerInfo()) host, port = localServerInfo.netloc.split(':') return splunklib.client.Service(host=host, port=port, scheme=localServerInfo.scheme, owner='-', app=SPLUNK_APP, token=splunk.getSessionKey())
def test_remote_hostpath(self): conf = getConf('web', namespace='search', sessionKey=self.sessionKey) self.assert_(isinstance(conf, Conf), "The optional argument hostPath works when ignored") conf = getConf('indexes', namespace='search', sessionKey=self.sessionKey, hostPath=splunk.getLocalServerInfo()) self.assert_(isinstance(conf, Conf), "The optional argument hostPath works when used") confName = 'testconf_%s' % round(time.time()) newConf = createConf(confName, namespace="testing", sessionKey=self.sessionKey, hostPath=splunk.getLocalServerInfo()) self.assert_( isinstance(newConf, Conf), "The optional argument hostPath works when used in createConf")
def handleEdit(self, confInfo): if self.callerArgs.id == 'jira': jira_settings = get_jira_settings(splunk.getLocalServerInfo(), self.getSessionKey()) if 'jira_url' in self.callerArgs: jira_settings['jira_url'] = self.callerArgs['jira_url'][0] if 'jira_username' in self.callerArgs: jira_settings['jira_username'] = self.callerArgs['jira_username'][0] if 'jira_password' in self.callerArgs: password = self.callerArgs['jira_password'][0] if password and password != PASSWORD_PLACEHOLDER: jira_settings['jira_password'] = password for k in DEFAULT_SETTINGS: if 'default_' + k in self.callerArgs: jira_settings[k] = self.callerArgs['default_' + k][0] if not validate_jira_settings(jira_settings): raise admin.ArgValidationException, "Error connecting to JIRA server" update_jira_settings(jira_settings, splunk.getLocalServerInfo(), self.getSessionKey()) if 'import' in self.callerArgs and self.callerArgs['import'][0] in ('1', 'true'): try: generate_jira_dialog(jira_settings, splunk.getLocalServerInfo(), self.getSessionKey()) except Exception, e: raise admin.AdminManagerException("Error importing settings from Jira, check server URL and credentials: " + str(e))
def handleEdit(self, confInfo): if self.callerArgs.id == 'jirasend': app_conf = AppConf(splunk.getLocalServerInfo(), self.getSessionKey()) settings = app_conf.get_settings(self.callerArgs.id) settings[self.callerArgs.id] = {} if 'jira_url' in self.callerArgs: settings[self.callerArgs.id]['jira_url'] = self.callerArgs['jira_url'][0] if 'jira_username' in self.callerArgs: settings[self.callerArgs.id]['jira_username'] = self.callerArgs['jira_username'][0] if 'jira_password' in self.callerArgs: password = self.callerArgs['jira_password'][0] if password and password != PASSWORD_PLACEHOLDER: settings[app_conf.password_store] = password app_conf.update_settings(self.callerArgs.id, settings)
def handleEdit(self, confInfo): if self.callerArgs.id == 'customcommand': app_conf = AppConf(splunk.getLocalServerInfo(), self.getSessionKey()) settings = app_conf.get_settings('customcommand') settings[self.callerArgs.id] = {} if 'url' in self.callerArgs: settings[self.callerArgs.id]['url'] = self.callerArgs['url'][0] if 'username' in self.callerArgs: settings[self.callerArgs. id]['username'] = self.callerArgs['username'][0] if 'password' in self.callerArgs: password = self.callerArgs['password'][0] if password and password != PASSWORD_PLACEHOLDER: settings[app_conf.password_store] = password app_conf.update_settings('customcommand', settings)
def rulethresholds(self, **kwargs): try: if cherrypy.request.method == 'POST': localServerInfo = urlparse(splunk.getLocalServerInfo()) host, port = localServerInfo.netloc.split(':') splunk_url = localServerInfo.scheme + host + ':' + port user_id = cherrypy.session['user']['id'] username = cherrypy.session['user']['name'] session_key = splunk.getSessionKey() rule = json.loads(cherrypy.request.body.read()) rule_definitions = read_file_contents(LOOKUP_FILE_PATH) try: check_rule_threshold_types(rule, rule_definitions) except Exception as exc: raise Exception("Error checking rule (rule: '{rule}') (cause: '{cause}')".format(rule = repr(rule), cause = str(exc))) try: write_threshold_macro_values(rule) except Exception as exc: raise Exception("Error updating macros.conf file (cause: '{cause}')".format(cause = str(exc))) try: written_rule = write_threshold_lookup_values(rule, rule_definitions) except Exception as exc: raise Exception("Error updating rule_thresholds.csv file (cause: '{cause}')".format(cause = str(exc))) if len(written_rule['thresholds']) > 0: try: write_user_actions_values(written_rule, user_id, username) except Exception as exc: raise Exception("Error writing user action parameters to file (cause: '{cause}')".format(cause = str(exc))) try: run_saved_searches(written_rule, splunk_url, username, session_key) except Exception as exc: raise Exception("Error running saved searches (cause: '{cause}')".format(cause = str(exc))) cherrypy.response.status = 200 return json.dumps({'status': 'OK'}) except Exception as exc: cherrypy.response.status = 500 logger.exception("Error (traceback.format_exc() = '%s')", traceback.format_exc()) return json.dumps({'status': 'error', 'message': str(exc)})
def handleList(self, confInfo): jive_settings = get_jive_settings(splunk.getLocalServerInfo(), self.getSessionKey()) item = confInfo['jive'] item['jive_url'] = jive_settings.get('jive_url', 'https://xxxx.jiveon.com/')
def test_remote_hostpath(self): conf = getConf('web', namespace='search', sessionKey=self.sessionKey) self.assert_(isinstance(conf, Conf), "The optional argument hostPath works when ignored") conf = getConf('indexes', namespace='search', sessionKey=self.sessionKey, hostPath=splunk.getLocalServerInfo()) self.assert_(isinstance(conf, Conf), "The optional argument hostPath works when used") confName = 'testconf_%s' % round(time.time()) newConf = createConf(confName, namespace="testing", sessionKey=self.sessionKey, hostPath=splunk.getLocalServerInfo()) self.assert_(isinstance(newConf, Conf), "The optional argument hostPath works when used in createConf")
def get_service(): localServerInfo = urlparse(splunk.getLocalServerInfo()) host, port = localServerInfo.netloc.split(':') return splunklib.client.Service(host = host, port = port, scheme = localServerInfo.scheme, owner = '-', app = SPLUNK_APP, token = splunk.getSessionKey())
def handleEdit(self, confInfo): if self.callerArgs.id == 'jive': jive_settings = get_jive_settings(splunk.getLocalServerInfo(), self.getSessionKey()) if 'jive_url' in self.callerArgs: jive_settings['jive_url'] = self.callerArgs['jive_url'][0] update_jive_settings(jive_settings, splunk.getLocalServerInfo(), self.getSessionKey())