# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved. import itsi_py3 from itsi_py3 import _ from ITOA.itoa_object import ItoaObject, CRUDMethodTypes from ITOA.itoa_common import normalize_num_field, is_valid_str, is_valid_num from ITOA.setup_logging import logger class ItsiEventManagementState(ItoaObject): ''' Implements ITSI event management state to store settings for event management view ''' log_prefix = '[ITSI Event Management State] ' collection_name = 'itsi_event_management' def __init__(self, session_key, current_user_name): super(ItsiEventManagementState, self).__init__( session_key, current_user_name, 'event_management_state', collection_name=self.collection_name, title_validation_required=True ) def do_additional_setup(self, owner, objects, req_source='unknown', method=CRUDMethodTypes.METHOD_UPSERT, transaction_id=None, skip_local_failure=False): # Do validations for data consistency for json_data in objects: # Assume json_data is valid normalize_num_field(json_data, 'fetchLimit') normalize_num_field(json_data, 'realTimeRefreshRate') str_types = ['earliest'] for str_type in str_types: # 'earliest' time can be relative string or epoch number, is_valid_str returns False for '' (empty string) if not is_valid_str(json_data.get(str_type)) and not is_valid_num(json_data.get(str_type)): # If earliest is set to '' (empty string) and latest is set to a valid value, then user may have chosen a "Before" time range if isinstance(json_data.get(str_type), itsi_py3.string_type) and not json_data.get(str_type) and ( is_valid_str(json_data.get('latest')) or is_valid_num(json_data.get('latest'))): pass else: self.raise_error_bad_validation( logger, _('An invalid value is specified for {0}. Specify a valid value.').format(str_type) ) if not 'filterCollection' in json_data: json_data['filterCollection'] = [] if not isinstance(json_data['filterCollection'], list): self.raise_error_bad_validation( logger, _('Invalid filterCollection list specified. Specify a valid filterCollection list.') )