|
|
@ -131,6 +131,18 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Arbitrary unique ID that is used to reference the condition from a custom expression.
|
|
|
|
- Arbitrary unique ID that is used to reference the condition from a custom expression.
|
|
|
|
- Can only contain upper-case letters.
|
|
|
|
- Can only contain upper-case letters.
|
|
|
|
|
|
|
|
- Required for custom expression filters.
|
|
|
|
|
|
|
|
eval_type:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Filter condition evaluation method.
|
|
|
|
|
|
|
|
- Defaults to C(andor) if conditions are less then 2 or if
|
|
|
|
|
|
|
|
I(formula) is not specified.
|
|
|
|
|
|
|
|
- Defaults to C(custom_expression) when formula is specified.
|
|
|
|
|
|
|
|
choices:
|
|
|
|
|
|
|
|
- 'andor'
|
|
|
|
|
|
|
|
- 'and'
|
|
|
|
|
|
|
|
- 'or'
|
|
|
|
|
|
|
|
- 'custom_expression'
|
|
|
|
formula:
|
|
|
|
formula:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- User-defined expression to be used for evaluating conditions of filters with a custom expression.
|
|
|
|
- User-defined expression to be used for evaluating conditions of filters with a custom expression.
|
|
|
@ -1215,11 +1227,11 @@ class Filter(object):
|
|
|
|
self._zapi = zbx
|
|
|
|
self._zapi = zbx
|
|
|
|
self._zapi_wrapper = zapi_wrapper
|
|
|
|
self._zapi_wrapper = zapi_wrapper
|
|
|
|
|
|
|
|
|
|
|
|
def _construct_evaltype(self, _eval, _conditions):
|
|
|
|
def _construct_evaltype(self, _eval_type, _formula, _conditions):
|
|
|
|
"""Construct the eval type
|
|
|
|
"""Construct the eval type
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
_eval: zabbix condition evaluation formula
|
|
|
|
_formula: zabbix condition evaluation formula
|
|
|
|
_conditions: list of conditions to check
|
|
|
|
_conditions: list of conditions to check
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
@ -1230,9 +1242,37 @@ class Filter(object):
|
|
|
|
'evaltype': '0',
|
|
|
|
'evaltype': '0',
|
|
|
|
'formula': None
|
|
|
|
'formula': None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _eval_type == 'andor':
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
'evaltype': '0',
|
|
|
|
|
|
|
|
'formula': None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _eval_type == 'and':
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
'evaltype': '1',
|
|
|
|
|
|
|
|
'formula': None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _eval_type == 'or':
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
'evaltype': '2',
|
|
|
|
|
|
|
|
'formula': None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _eval_type == 'custom_expression':
|
|
|
|
|
|
|
|
if _formula is not None:
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'evaltype': '3',
|
|
|
|
'evaltype': '3',
|
|
|
|
'formula': _eval
|
|
|
|
'formula': _formula
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self._module.fail_json(msg="'formula' is required when 'eval_type' is set to 'custom_expression'")
|
|
|
|
|
|
|
|
if _formula is not None:
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
'evaltype': '3',
|
|
|
|
|
|
|
|
'formula': _formula
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
'evaltype': '0',
|
|
|
|
|
|
|
|
'formula': None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def _construct_conditiontype(self, _condition):
|
|
|
|
def _construct_conditiontype(self, _condition):
|
|
|
@ -1401,7 +1441,7 @@ class Filter(object):
|
|
|
|
https://www.zabbix.com/documentation/3.4/manual/api/reference/action/object#action_filter_condition""" % (value, conditiontype)
|
|
|
|
https://www.zabbix.com/documentation/3.4/manual/api/reference/action/object#action_filter_condition""" % (value, conditiontype)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def construct_the_data(self, _formula, _conditions):
|
|
|
|
def construct_the_data(self, _eval_type, _formula, _conditions):
|
|
|
|
"""Construct the user defined filter conditions to fit the Zabbix API
|
|
|
|
"""Construct the user defined filter conditions to fit the Zabbix API
|
|
|
|
requirements operations data using helper methods.
|
|
|
|
requirements operations data using helper methods.
|
|
|
|
|
|
|
|
|
|
|
@ -1426,6 +1466,7 @@ class Filter(object):
|
|
|
|
"operator": self._construct_operator(cond)
|
|
|
|
"operator": self._construct_operator(cond)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
_constructed_evaltype = self._construct_evaltype(
|
|
|
|
_constructed_evaltype = self._construct_evaltype(
|
|
|
|
|
|
|
|
_eval_type,
|
|
|
|
_formula,
|
|
|
|
_formula,
|
|
|
|
constructed_data['conditions']
|
|
|
|
constructed_data['conditions']
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -1573,6 +1614,7 @@ def main():
|
|
|
|
acknowledge_default_subject=dict(type='str', required=False, default=None),
|
|
|
|
acknowledge_default_subject=dict(type='str', required=False, default=None),
|
|
|
|
conditions=dict(type='list', required=False, default=None),
|
|
|
|
conditions=dict(type='list', required=False, default=None),
|
|
|
|
formula=dict(type='str', required=False, default=None),
|
|
|
|
formula=dict(type='str', required=False, default=None),
|
|
|
|
|
|
|
|
eval_type=dict(type='str', required=False, default=None, choices=['andor', 'and', 'or', 'custom_expression']),
|
|
|
|
operations=dict(type='list', required=False, default=None),
|
|
|
|
operations=dict(type='list', required=False, default=None),
|
|
|
|
recovery_operations=dict(type='list', required=False, default=[]),
|
|
|
|
recovery_operations=dict(type='list', required=False, default=[]),
|
|
|
|
acknowledge_operations=dict(type='list', required=False, default=[])
|
|
|
|
acknowledge_operations=dict(type='list', required=False, default=[])
|
|
|
@ -1603,6 +1645,7 @@ def main():
|
|
|
|
acknowledge_default_subject = module.params['acknowledge_default_subject']
|
|
|
|
acknowledge_default_subject = module.params['acknowledge_default_subject']
|
|
|
|
conditions = module.params['conditions']
|
|
|
|
conditions = module.params['conditions']
|
|
|
|
formula = module.params['formula']
|
|
|
|
formula = module.params['formula']
|
|
|
|
|
|
|
|
eval_type = module.params['eval_type']
|
|
|
|
operations = module.params['operations']
|
|
|
|
operations = module.params['operations']
|
|
|
|
recovery_operations = module.params['recovery_operations']
|
|
|
|
recovery_operations = module.params['recovery_operations']
|
|
|
|
acknowledge_operations = module.params['acknowledge_operations']
|
|
|
|
acknowledge_operations = module.params['acknowledge_operations']
|
|
|
@ -1645,7 +1688,7 @@ def main():
|
|
|
|
operations=ops.construct_the_data(operations),
|
|
|
|
operations=ops.construct_the_data(operations),
|
|
|
|
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
|
|
|
|
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
|
|
|
|
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
|
|
|
|
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
|
|
|
|
conditions=fltr.construct_the_data(formula, conditions)
|
|
|
|
conditions=fltr.construct_the_data(eval_type, formula, conditions)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if difference == {}:
|
|
|
|
if difference == {}:
|
|
|
@ -1674,7 +1717,7 @@ def main():
|
|
|
|
operations=ops.construct_the_data(operations),
|
|
|
|
operations=ops.construct_the_data(operations),
|
|
|
|
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
|
|
|
|
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
|
|
|
|
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
|
|
|
|
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
|
|
|
|
conditions=fltr.construct_the_data(formula, conditions)
|
|
|
|
conditions=fltr.construct_the_data(eval_type, formula, conditions)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
module.exit_json(changed=True, msg="Action created: %s, ID: %s" % (name, action_id))
|
|
|
|
module.exit_json(changed=True, msg="Action created: %s, ID: %s" % (name, action_id))
|
|
|
|
|
|
|
|
|
|
|
|