def getSavedSearchHistory(label, namespace=None, sessionKey=None, ignoreExpired=True, owner=None, sortKey=None, sortDir='desc', ignoreRunning=False, search=None, hostPath=None, uri=None): ''' Retrieve the history of a saved search. ignoreExpired: {True|False} When True only return saved searches that have a TTL > 0 or they have been saved by the user. When False return everything, including searches with a TTL >= 0 regardless of the job's saved status. ''' #SPL-35662 done RT searches are alert artifacts which should be of no use to UI, # dashboards should always reference running rt searches search = (search if search != None else '') + " NOT (isRealTimeSearch=1 AND isDone=1)" entities = entity.getEntities(['saved', 'searches', label, 'history'], namespace=namespace, owner=owner, sessionKey=sessionKey, search=search, hostPath=hostPath, count=0, uri=uri) if ignoreExpired or ignoreRunning: for sid, job in entities.items(): if ignoreExpired \ and splunk.search.normalizeJobPropertyValue('ttl', job.get('ttl')) <= 0 \ and not splunk.search.normalizeJobPropertyValue('isSaved', job.get('isSaved')): del entities[sid] continue # real time searches are never done so no need to ignore running isRTSearch = splunk.search.normalizeJobPropertyValue('isRealTimeSearch', job.get('isRealTimeSearch')) isDone = splunk.search.normalizeJobPropertyValue('isDone', job.get('isDone')) if ignoreRunning and not isDone and not isRTSearch: del entities[sid] if sortKey: reverse = True if sortDir == 'asc': reverse = False try: entities = sorted(entities.items(), key=lambda x: x[1].__dict__[sortKey], reverse=reverse) except KeyError, e: logger.warn("Attempted to sort on a key (%s) from a saved search's history that doesn't exist" % sortKey)
def listSavedSearches(namespace=None, sessionKey=None, owner=None, hostPath=None, count=None): '''Retrieve a list of saved searches.''' return entity.getEntities(SAVED_SEARCHES_ENDPOINT_ENTITY_PATH, namespace=namespace, owner=owner, sessionKey=sessionKey, hostPath=hostPath, count=count)
def searchScore(projectDescriptions, tools_materials): if len(tools_materials) == 0: return scoreList = [] for projDesc in projectDescriptions: descEntities = getEntities(projDesc.lower()) score = 0.0 for tm in tools_materials: for descEnt in descEntities: if singularize(tm.lower()) == singularize(descEnt.name): score += 1 score = score / len(tools_materials) scoreList.append(score) return scoreList
def listUsers(**kwargs): ''' Returns a list of users. ''' uri = 'authentication/users' return en.getEntities(uri, **kwargs)
def getUserPrefs(key): ''' obtain the user specific preference ''' return en.getEntities('data/user-prefs').get('general').get(key)
def listRoles(**kwargs): ''' Returns a list of roles. ''' uri = 'authentication/roles' return en.getEntities(uri, **kwargs)