# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved. """ Modular Input that runs on startup and load default policy to KV store if it is not available """ import sys from splunk.clilib.bundle_paths import make_splunkhome_path sys.path.append(make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib'])) import itsi_path from itsi_py3 import _ from ITOA.itoa_config import get_supported_objects from itsi.event_management.utils import NotableEventDefaultPoliciesLoader from ITOA.itoa_common import modular_input_should_run from ITOA.setup_logging import getLogger4ModInput from ITOA.mod_input_utils import skip_run_during_migration from SA_ITOA_app_common.solnlib.modular_input import ModularInput from SA_ITOA_app_common.solnlib.server_info import ServerInfo class ItsiAggregationPolicyLoader(ModularInput): """ Mod input that handles Upgrades which is primarily migration of data from older version to current version """ title = _("IT Service Intelligence Default Policies Loader") description = _("Loads the default aggregation policies.") handlers = None app = 'SA-ITOA' name = 'itsi_default_aggregation_policy_loader' use_single_instance = False use_kvstore_checkpointer = False use_hec_event_writer = False def extra_arguments(self): return [{ 'name': "log_level", 'title': _("Logging Level"), 'description': _("This is the level at which the modular input will log data.") }] @skip_run_during_migration def do_run(self, input_config): """ - This is the method called by splunkd when mod input is enabled. @param input_config: config passed down by splunkd """ logger = getLogger4ModInput(input_config) server_info = ServerInfo(self.session_key) # log the message for restartless upgrade testing which can be useful while debugging. stanza_name = next(iter(input_config.keys())) logger.info(f"Restartless upgrade - Reloaded modular input {stanza_name}") logger.info(f"Modular input running on instance: {server_info.server_name}") try: ret = NotableEventDefaultPoliciesLoader(self.session_key, logger).upload_default_policies() if not ret: logger.error('Failed to create default aggregation policies') else: logger.info("Successfully uploaded default aggregation policies") except Exception as e: logger.exception(e) raise if __name__ == "__main__": worker = ItsiAggregationPolicyLoader() worker.execute()