def writeConf(self, confName, stanzaName, settingsDict): import splunk.bundle as bundle app = self.appName # always save things to SOME app context. user = self.context == CONTEXT_APP_AND_USER and self.userName or "-" overwriteStanzas = not (self.requestedAction == ACTION_EDIT or self.requestedAction == ACTION_REMOVE) try: confObj = bundle.getConf(confName, sessionKey=self.getSessionKey(), namespace=app, owner=user, overwriteStanzas=overwriteStanzas) except splunk.ResourceNotFound: confObj = bundle.createConf(confName, sessionKey=self.getSessionKey(), namespace=app, owner=user) confObj.beginBatch() for k, v in settingsDict.items(): if isinstance(v, list): confObj[stanzaName][k] = str.join(",", v) else: confObj[stanzaName][k] = v confObj.commitBatch()
def setConf(self, confDict, filename, namespace=None, sessionKey=None, owner=None): ''' wrapper to bundle.getConf, still necessary for compatibility''' try: conf = bundle.getConf(filename, sessionKey=sessionKey, namespace=namespace, owner=owner) except: conf = bundle.createConf(filename, sessionKey=sessionKey, namespace=namespace, owner=owner) for item in confDict.keys(): try: for k, v in confDict[item].iteritems(): conf[item][k] = v except AttributeError: pass
def setConf(self, confDict, filename, namespace=None, sessionKey=None, owner=None ): ''' wrapper to bundle.getConf, still necessary for compatibility''' try: conf = bundle.getConf(filename, sessionKey=sessionKey, namespace=namespace, owner=owner) except: conf = bundle.createConf(filename, sessionKey=sessionKey, namespace=namespace, owner=owner) for item in confDict.keys(): try: for k, v in confDict[item].iteritems(): conf[item][k] = v except AttributeError: pass
def write(self, settings): if not settings or len(settings) == 0: return try: confObj = bundle.getConf(self.confName, sessionKey=self.sessionKey, namespace=AppName, owner='-') except: try: confObj = bundle.createConf(self.confName, sessionKey=self.sessionKey, namespace=AppName, owner='-') except Exception, e: logger.error('Error creating new conf file') return
def writeConf(self, confName, stanzaName, settingsDict): app = self.appName # always save things to SOME app context. user = self.context == CONTEXT_APP_AND_USER and self.userName or "-" overwriteStanzas = not (self.requestedAction == ACTION_EDIT or self.requestedAction == ACTION_REMOVE) try: confObj = bundle.getConf( confName, sessionKey=self.getSessionKey(), namespace=app, owner=user, overwriteStanzas=overwriteStanzas) except splunk.ResourceNotFound: confObj = bundle.createConf(confName, sessionKey=self.getSessionKey(), namespace=app, owner=user) confObj.beginBatch() for k, v in settingsDict.items(): if isinstance(v, list): confObj[stanzaName][k] = str.join(",", v) else: confObj[stanzaName][k] = v confObj.commitBatch()