# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved. from itsi.content_packs.constants import ContentType class ContentObjectsEnabler(object): """Disable/Enable services and correlation searches upon installation based on user's import option.""" def __init__(self, logger, session_key, enabled=False): """ :param logger: a logger instance :type logger: Logger :param session_key: the session key :type session_key: str :param enabled: whether to disable/enable services and correlation searches upon installation :type enabled: bool """ self.logger = logger self.session_key = session_key self.enabled = enabled def process_objects(self, content_objects, **kwargs): """ Disable/Enable services, correlation searches and notable events upon installation. :param content_objects: the content objects data :type content_objects: dict :return: the content objects data in which services, correlation searches and notable events objects are disabled/enabled based on user's import option :rtype: dict """ status_name_dict = { ContentType.CORRELATION_SEARCH: 'disabled', ContentType.NOTABLE_EVENT_AGGREGATION_POLICY: 'disabled', ContentType.SERVICE: 'enabled' } for content_type, status_name in status_name_dict.items(): self.update_objects_status(content_type, content_objects, status_name) return content_objects def update_objects_status(self, content_type, content_objects, status_name): """ Update status of processed content pack objects based on content type and it's corresponding object status name :param content_type: the content type, eg: services :type content_type: str :param content_objects: the content objects data :type content_objects: dict :param status_name: the content objects status name: disabled/enabled :type processed_objects: dict """ objects = content_objects.setdefault(content_type, []) for obj in objects: if status_name == 'disabled': obj[status_name] = 0 if self.enabled else 1 elif status_name == 'enabled': obj[status_name] = 1 if self.enabled else 0