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.

52 lines
2.5 KiB

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
from ITOA.itoa_exceptions import ItoaValidationError
from ITOA.itoa_object import ItoaObject, CRUDMethodTypes
from ITOA.setup_logging import logger
class ItsiDriftDetection(ItoaObject):
"""
Implements ITSI drift detection templates (for use with the drift detection feature)
"""
collection_name = "itsi_drift_detection_template"
REQUIRED_FIELDS = ["aggregation_function", "aggregation_span", "lookback_period", "threshold_direction",
"tolerance_in_percent"]
def __init__(self, session_key, current_user_name):
super(ItsiDriftDetection, self).__init__(session_key, current_user_name, "drift_detection_template",
collection_name=self.collection_name)
def do_object_validation(self, owner, objects, validate_name=True, dupname_tag=None, transaction_id=None,
skip_local_failure=False, ignore_same_key=False):
"""
See ItoaObject.do_object_validation()
"""
aggregation_function_values = set(["avg", "max", "min", "sum"])
threshold_values = set(["up", "down", "both"])
for obj in objects:
for field in self.REQUIRED_FIELDS:
if obj.get(field) is None:
raise ItoaValidationError(message="Required field %s missing" % field, logger=logger)
if obj["aggregation_function"] not in aggregation_function_values:
raise ItoaValidationError(
message="Invalid aggregation_function value: %s" % obj["aggregation_function"], logger=logger,
)
if obj["threshold_direction"] not in threshold_values:
raise ItoaValidationError(
message="Invalid threshold value: %s" % obj["threshold_direction"], logger=logger,
)
return super(ItsiDriftDetection, self).do_object_validation(
owner, objects, validate_name=validate_name, dupname_tag=dupname_tag, transaction_id=transaction_id,
skip_local_failure=skip_local_failure, ignore_same_key=ignore_same_key,
)
def do_additional_setup(self, owner, objects, req_source="unknown", method=CRUDMethodTypes.METHOD_UPSERT,
transaction_id=None, skip_local_failure=False, **kwargs):
"""
See ItoaObject.do_additional_setup()
"""
for obj in objects:
obj["tolerance_in_percent"] = int(obj["tolerance_in_percent"])