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.

40 lines
1.4 KiB

# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
"""
Represents a Rule in a Notable Event Aggregation Policy
"""
from itsi_py3 import _
from ..notable_event_error import NotableEventBadRequest
from .clause import Clause
from .actions import Actions
class Rule(object):
"""
A Rule within a Notable Event Aggregation Policy
"""
def __init__(self, **kwargs):
raise TypeError(_('Cannot instantiate this class. Call'
' `Rule.validate(rule)`'))
@staticmethod
def validate(rule):
'''
validate a Rule
'''
if not isinstance(rule, dict):
raise NotableEventBadRequest(_('Expecting a dictionary for %s.'
' Received type=%s') % type(rule))
if 'title' not in rule:
raise NotableEventBadRequest(_('Missing key `title` in rule'))
if 'activation_criteria' not in rule:
raise NotableEventBadRequest(_('Missing key `activation_criteria` in rule'))
if 'actions' not in rule:
raise NotableEventBadRequest(_('Missing key `actions` in rule'))
if not isinstance(rule['actions'], list):
raise NotableEventBadRequest(_('Expecting actions to be list. Received=%s type=%s') % (
rule['actions'], type(rule['actions']).__name__))
for action in rule.get('actions'):
Actions.validate(action)