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.
62 lines
2.2 KiB
62 lines
2.2 KiB
# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
|
|
|
|
"""
|
|
Represents an Actions object which currently is contained within a Rule type
|
|
object.
|
|
"""
|
|
from ..notable_event_error import NotableEventBadRequest
|
|
from .criterion import ExecutionCriteria
|
|
|
|
|
|
class ActionItem(object):
|
|
"""
|
|
Represents an ActionItem
|
|
"""
|
|
def __init__(self, **kwargs):
|
|
raise TypeError('Cannot instantiate this class. Call `Item.validate(item)`')
|
|
|
|
@staticmethod
|
|
def validate (action_item):
|
|
'''
|
|
validate an ActionItem
|
|
'''
|
|
if not isinstance(action_item, dict):
|
|
raise NotableEventBadRequest(('Expecting a dictionary for %s.'
|
|
' Received type=%s') % type(action_item))
|
|
|
|
if 'type' not in action_item:
|
|
raise NotableEventBadRequest('Missing key `type`')
|
|
if 'config' not in action_item:
|
|
raise NotableEventBadRequest('Missing key `config`')
|
|
if 'execution_criteria' not in action_item:
|
|
raise NotableEventBadRequest('Missing key `execution_criteria`')
|
|
|
|
ExecutionCriteria.validate(action_item['execution_criteria'])
|
|
|
|
|
|
class Actions(object):
|
|
"""
|
|
Actions is a Clause like object, expect it consists of a condition with
|
|
some Action Items
|
|
"""
|
|
def __init__(self, **kwargs):
|
|
raise TypeError('Cannot instantiate this class. Call `Clause.validate(condition, items)`')
|
|
|
|
@staticmethod
|
|
def validate(actions):
|
|
'''
|
|
Validate Actions
|
|
'''
|
|
if not isinstance (actions, dict):
|
|
raise NotableEventBadRequest('Expecting `actions` to be a dict. Received type=%s.' %
|
|
type(actions).__name__)
|
|
if 'condition' not in actions:
|
|
raise NotableEventBadRequest('Actions: Missing key `condition`')
|
|
if 'items' not in actions:
|
|
raise NotableEventBadRequest('Actions: Missing key `items`')
|
|
if not isinstance(actions['items'], list):
|
|
raise NotableEventBadRequest(('Actions: Expected type for `actions["items"]`=list'
|
|
'Received=%s.') % type(actions['items']).__name__)
|
|
for action_item in actions['items']:
|
|
ActionItem.validate(action_item)
|