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.

53 lines
2.1 KiB

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
from itsi.content_packs.constants import ContentType
from ITOA.setup_logging import InstrumentCall
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, transaction_id=None, backfill_timerange="-7d"):
"""
: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
:param transaction_id: transaction info for tracking for debugging
:type transaction_id: basestring
"""
backfill_timerange_options = ['-7d', '-14d', '-30d', '-60d']
self.logger = logger
self.session_key = session_key
self.backfill = backfill
if backfill_timerange in backfill_timerange_options:
self.backfill_timerange = backfill_timerange
else:
self.backfill_timerange = '-7d'
self._instrumentation = InstrumentCall(logger)
self.transaction_id = transaction_id
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
"""
with self._instrumentation.track("ContentObjectsBackfiller.process_objects", transaction_id=self.transaction_id):
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'] = self.backfill_timerange
return content_objects