You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.5 KiB

# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
import time
from ITOA.setup_logging import logger
from ITOA.itoa_object import ItoaObject
from ITOA import itoa_common
class ItsiEntityDiscoverySearch(ItoaObject):
"""
Implements KV store collection itsi_entity_discovery_search
Fields in this collection are:
_key - saved search name
last_execution_time - last time search search was run
entity_status_tracking - whether the search result is taken into account when determining the status of an entity
If is_unstable_entity_ff is disabled
eg: {
'_key': VMware vCenter,
'last_execution_time': 1600517750.931288
}
...
If is_unstable_entity_ff is enabled, latest_entity_status_tracking_flag is True/False,
entity_status_tracking field is set
eg: {
'_key': VMware vCenter,
'last_execution_time': 1600517750.931288
'entity_status_tracking': True
}
"""
def __init__(self, session_key, current_user_name='nobody'):
self.collection_name = 'itsi_entity_discovery_search'
self.session_key = session_key
super(ItsiEntityDiscoverySearch, self).__init__(self.session_key,
current_user_name,
'itsi_entity_discovery_search',
collection_name=self.collection_name,
title_validation_required=False)
def set_search_execution(self, saved_search_name, latest_entity_status_tracking_flag=None):
"""
Creates or updates entry for a given saved search name (_key)
@param saved_search_name: name of the saved search that acts as a _key
"""
current_time = time.time()
existing_search = self.get(self.current_user_name, saved_search_name)
search_data = {'_key': saved_search_name, 'last_execution_time': current_time}
if latest_entity_status_tracking_flag is not None:
search_data['entity_status_tracking'] = latest_entity_status_tracking_flag
if existing_search:
self.update(self.current_user_name, object_id=saved_search_name, data=search_data)
logger.info('Updated itsi_entity_discovery_search entry for saved search: (%s)' % saved_search_name)
else:
self.create(self.current_user_name, data=search_data)
logger.info('Created itsi_entity_discovery_search entry for saved search: (%s)' % saved_search_name)