def handleCustom(self, confInfo): if self.customAction == 'desc': confInfo['desc'] = self.description return raise admin.NotFoundException( "This endpoint does not support action: " + self.customAction)
def handleEdit(self, confInfo): """ Handles edits to the configuration options """ ## Get requested action actionStr = str(self.requestedAction) if Governance.REQUESTED_ACTIONS.has_key(actionStr): actionStr = Governance.REQUESTED_ACTIONS[actionStr] logger.info('Entering %s' % (actionStr)) ## Refresh self.handleReload(makeKVS=False) name = self.callerArgs.id args = self.callerArgs if name is not None: try: conf = entity.getEntity('configs/conf-governance', name, sessionKey=self.getSessionKey()) except ResourceNotFound: raise admin.NotFoundException( "A governance configuration with the given name '%s' could not be found" % (name)) else: # Stop if no name was provided raise admin.ArgValidationException("No name provided") ## Create the resulting configuration that would be persisted if the settings provided are applied ## This rest handler supports the addition of arguments based on convention; therefore we merge args a little differently for arg in args: governanceMatch = Governance.governanceRE.match(arg) controlMatch = Governance.controlRE.match(arg) tagMatch = Governance.tagRE.match(arg) if governanceMatch or controlMatch or tagMatch or arg in Governance.VALID_PARAMS: conf[arg] = args[arg][0] for key, val in conf.items(): if key == admin.EAI_ENTRY_ACL: if val.has_key('app') and val['app'] is not None and len( val['app']) > 0: conf.namespace = val['app'] if val.has_key('owner') and val['owner'] is not None and len( val['owner']) > 0: conf.owner = val['owner'] if conf.namespace is None or len(conf.namespace) == 0: conf.namespace = Governance.DEFAULT_NAMESPACE if conf.owner is None or len(conf.owner) == 0: conf.owner = Governance.DEFAULT_OWNER try: ## Check config Governance.checkConf(conf, name) except InvalidConfigException as e: e = "The edit attempt for the governance entry '%s' produced an invalid configuration: %s" % ( name, str(e)) logger.error(e) raise admin.ArgValidationException(e) ## Write out an update to the governance config file entity.setEntity(conf, sessionKey=self.getSessionKey()) logger.info("Successfully updated the '%s' governance configuration" % (name)) ## Reload governance (makeKVS) self.handleReload() logger.info('%s completed successfully' % (actionStr))
def saveConf(self, confInfo, verify_exists=False): """ Handles edits to the configuration options Arguments confInfo -- The object containing the information about what is being requested. verify_exists -- Make sure the entry exists before saving """ try: name = self.callerArgs.id args = self.callerArgs # Load the existing configuration confDict = self.readConf(self.conf_file) # Get the settings for the given stanza is_found = False existing_settings = None if name is not None: for stanza, settings in confDict.items(): if stanza == name: is_found = True # In case, we need to view the old settings existing_settings = copy.copy(settings) break # Got the settings object we were looking for # Stop if we could not find the name if not is_found and verify_exists: raise admin.NotFoundException( "A stanza for the given name '%s' could not be found" % (name)) # Get the settings that are being set new_settings = {} for key in args.data: new_settings[key] = args[key][0] # Create the resulting configuration that would be persisted if the settings provided are applied if is_found: settings.update(new_settings) else: settings = existing_settings # Check the configuration settings cleaned_params = self.checkConf( new_settings, name, confInfo, existing_settings=existing_settings) # Get the validated parameters validated_params = self.convertParams(name, cleaned_params, True) # Clear out the given parameters if blank so that it can be removed if the user wishes (note that values of none are ignored by Splunk) clearable_params = [] for p in clearable_params: if p in validated_params and validated_params[p] is None: validated_params[p] = "" # Write out the updated conf self.writeConf(self.conf_file, name, validated_params) except admin.NotFoundException as e: raise e except Exception as e: self.logger.exception("Exception generated while performing edit") raise e
def handleEdit(self, confInfo): """ Handles edits to the configuration options """ ## Get requested action actionStr = str(self.requestedAction) if actionStr in CorrelationSearches.REQUESTED_ACTIONS: actionStr = CorrelationSearches.REQUESTED_ACTIONS[actionStr] logger.info('Entering %s', actionStr) ## Refresh self.handleReload(makeKVS=False) reviewstatusesDict = self.readConf('reviewstatuses') # Get list of valid Splunk users users = NotableOwner.getOwners(self.getSessionKey()) name = self.callerArgs.id args = self.callerArgs if not name: raise admin.ArgValidationException('No name provided') try: conf = entity.getEntity('configs/conf-correlationsearches', name, sessionKey=self.getSessionKey()) except ResourceNotFound: raise admin.NotFoundException( "A correlationsearch configuration with the given name '%s' could not be found" % name) # Create the resulting configuration that would be persisted if the settings provided are applied for key, val in conf.items(): if key in args.data: # Get the new value new_value = args[key][0] # Set the value to a single space if empty or none, otherwise, Splunk won't save it (SOLNPCI-532) if new_value in [None, '']: new_value = ' ' # Assign the value conf[key] = new_value ## namespace/owner if admin.EAI_ENTRY_ACL in conf: conf.namespace = conf[admin.EAI_ENTRY_ACL].get( 'app', None) or CorrelationSearches.DEFAULT_NAMESPACE conf.owner = conf[admin.EAI_ENTRY_ACL].get( 'owner', None) or CorrelationSearches.DEFAULT_OWNER else: conf.namespace = CorrelationSearches.DEFAULT_NAMESPACE conf.owner = CorrelationSearches.DEFAULT_OWNER try: # Check config CorrelationSearches.checkConf(conf, name, users=users, reviewstatuses=reviewstatusesDict) except InvalidConfigException as e: e = "The edit attempt for the correlation search '%s' produced an invalid configuration: %s" % ( name, str(e)) logger.error(e) raise admin.ArgValidationException(e) # Write out an update to the correlationsearches config file entity.setEntity(conf, sessionKey=self.getSessionKey()) logger.info("Successfully updated the '%s' correlation search", name) # Reload correlationsearches (makeKVS) self.handleReload(reloadReviewStatuses=False) logger.info('%s completed successfully', actionStr)
def handleCustom(self, confInfo): if self.customAction == 'desc': confInfo['desc'] = "Base handler for all classes. This should have been overwritten with a higher-level handler." return raise admin.NotFoundException("This endpoint does not support action: " + self.customAction)