# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved. from itsi.content_packs.constants import ContentType class ContentObjectsBackfiller(object): """Disable/Enable kpi backfill of services upon installation based on user's import option.""" def __init__(self, logger, session_key, backfill=False): """ :param logger: a logger instance :type logger: Logger :param session_key: the session key :type session_key: str :param backfill: whether to backfill kpis upon service installation :type backfill: bool """ self.logger = logger self.session_key = session_key self.backfill = backfill def process_objects(self, content_objects, **kwargs): """ Disable/Enable kpi backfill of services upon installation. :param content_objects: the content objects data :type content_objects: dict :return: the content objects data with kpis backfill enabled/disabled :rtype: dict """ objects = content_objects.setdefault(ContentType.SERVICE, []) for obj in objects: for kpi in obj.get('kpis', []): if kpi['type'] != 'service_health': kpi['backfill_enabled'] = self.backfill kpi['backfill_earliest_time'] = '-7d' return content_objects