Skip to content

Commit

Permalink
fix zabbix_action module for zabbix6 (#648)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Petrov <[email protected]>
  • Loading branch information
crashwind and Kirill Petrov authored Mar 11, 2022
1 parent 6852cc3 commit e16519e
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions plugins/modules/zabbix_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,16 @@ def check_if_action_exists(self, name):
"""
try:
_action = self._zapi.action.get({
_params = {
"selectOperations": "extend",
"selectRecoveryOperations": "extend",
"selectAcknowledgeOperations": "extend",
"selectFilter": "extend",
'filter': {'name': [name]}
})
}
if LooseVersion(self._zbx_api_version) >= LooseVersion('6.0'):
_params['selectUpdateOperations'] = _params.pop('selectAcknowledgeOperations', 'extend')
_action = self._zapi.action.get(_params)
if len(_action) > 0:
_action[0]['recovery_operations'] = _action[0].pop('recoveryOperations', [])
_action[0]['acknowledge_operations'] = _action[0].pop('acknowledgeOperations', [])
Expand Down Expand Up @@ -869,6 +872,15 @@ def _construct_parameters(self, **kwargs):
_params.pop('ack_longdata', None)
_params.pop('ack_shortdata', None)

if LooseVersion(self._zbx_api_version) >= LooseVersion('6.0'):
if 'update_operations' in _params and not isinstance(_params.get('update_operations', None), type(None)):
_params.pop('acknowledge_operations', None)
elif isinstance(_params.get('acknowledge_operations', None), list):
_params['update_operations'] = _params.pop('acknowledge_operations', [])
else:
_params['update_operations'] = []
_params.pop('acknowledge_operations', None)

return _params

def check_difference(self, **kwargs):
Expand Down Expand Up @@ -2010,7 +2022,7 @@ def main():
result = action.delete_action(action_id)
module.exit_json(changed=True, msg="Action Deleted: %s, ID: %s" % (name, result))
else:
difference = action.check_difference(
kwargs = dict(
action_id=action_id,
name=name,
event_source=event_source,
Expand All @@ -2025,10 +2037,16 @@ def main():
acknowledge_default_subject=acknowledge_default_subject,
operations=ops.construct_the_data(operations),
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
conditions=fltr.construct_the_data(eval_type, formula, conditions)
)

if LooseVersion(zapi_wrapper._zbx_api_version) >= LooseVersion('6.0'):
kwargs[argument_spec['acknowledge_operations']['aliases'][0]] = acknowledge_ops.construct_the_data(acknowledge_operations)
else:
kwargs['acknowledge_operations'] = acknowledge_ops.construct_the_data(acknowledge_operations)

difference = action.check_difference(**kwargs)

if difference == {}:
module.exit_json(changed=False, msg="Action is up to date: %s" % (name))
else:
Expand All @@ -2041,7 +2059,7 @@ def main():
if state == "absent":
module.exit_json(changed=False)
else:
action_id = action.add_action(
kwargs = dict(
name=name,
event_source=event_source,
esc_period=esc_period,
Expand All @@ -2055,9 +2073,15 @@ def main():
acknowledge_default_subject=acknowledge_default_subject,
operations=ops.construct_the_data(operations),
recovery_operations=recovery_ops.construct_the_data(recovery_operations),
acknowledge_operations=acknowledge_ops.construct_the_data(acknowledge_operations),
conditions=fltr.construct_the_data(eval_type, formula, conditions)
)

if LooseVersion(zapi_wrapper._zbx_api_version) >= LooseVersion('6.0'):
kwargs[argument_spec['acknowledge_operations']['aliases'][0]] = acknowledge_ops.construct_the_data(acknowledge_operations)
else:
kwargs['acknowledge_operations'] = acknowledge_ops.construct_the_data(acknowledge_operations)

action_id = action.add_action(**kwargs)
module.exit_json(changed=True, msg="Action created: %s, ID: %s" % (name, action_id))


Expand Down

0 comments on commit e16519e

Please sign in to comment.