Skip to content

Commit

Permalink
Update Action Module
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrodie18 committed Oct 31, 2023
1 parent 29090f2 commit 589ae6a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugins-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
# As we need to connect to an existing docker container we can't use `--docker` here as the VMs would be on different
# (non-routing) networks, so we run them locally and ensure any required dependencies are installed via `--requirements`
- name: Run integration test
run: ansible-test integration -v --color --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
run: ansible-test integration zabbix_action v --color --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
working-directory: ./ansible_collections/community/zabbix

# ansible-test support producing code coverage date
Expand Down
46 changes: 23 additions & 23 deletions plugins/modules/zabbix_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@
type: str
description:
- Type of operation.
- "Valid choices when setting type for I(recovery_operations) and I(acknowledge_operations):"
- "Valid choices when setting type for I(recovery_operations) and I(update_operations):"
- " - C(send_message)"
- " - C(remote_command)"
- " - C(notify_all_involved)"
- Choice C(notify_all_involved) only supported in I(recovery_operations) and I(acknowledge_operations).
- Choice C(notify_all_involved) only supported in I(recovery_operations) and I(update_operations).
choices:
- send_message
- remote_command
Expand Down Expand Up @@ -276,7 +276,7 @@
type: str
description:
- Media type that will be used to send the message.
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(acknowledge_operations).
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(update_operations).
- Set to C(all) for all media types
default: "all"
operation_condition:
Expand Down Expand Up @@ -476,7 +476,7 @@
type: str
description:
- Media type that will be used to send the message.
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(acknowledge_operations).
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(update_operations).
- Set to C(all) for all media types
default: "all"
op_message:
Expand Down Expand Up @@ -512,12 +512,12 @@
- The name of script used for global script commands.
- Required when I(command_type=global_script).
- Can be used when I(type=remote_command).
acknowledge_operations:
update_operations:
type: list
elements: dict
description:
- List of acknowledge operations.
- Action acknowledge operations are known as update operations since Zabbix 4.0.
- List of update operations.
- Action update operations are known as acknowledge operations prior to Zabbix 4.0.
- C(Suboptions) are the same as for I(operations).
suboptions:
type:
Expand Down Expand Up @@ -601,7 +601,7 @@
type: str
description:
- Media type that will be used to send the message.
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(acknowledge_operations).
- Can be used with I(type=send_message) or I(type=notify_all_involved) inside I(update_operations).
- Set to C(all) for all media types
default: "all"
op_message:
Expand Down Expand Up @@ -637,7 +637,7 @@
- The name of script used for global script commands.
- Required when I(command_type=global_script).
- Can be used when I(type=remote_command).
aliases: [ update_operations ]
aliases: [ acknowledge_operations ]
default: []
pause_symptoms:
type: bool
Expand Down Expand Up @@ -734,7 +734,7 @@
run_on_hosts:
- 0
# Trigger action with recovery and acknowledge operations
# Trigger action with recovery and update operations
- name: Deploy trigger action
# set task level variables as we change ansible_connection plugin here
vars:
Expand Down Expand Up @@ -769,7 +769,7 @@
media_type: "Email"
send_to_users:
- "Admin"
acknowledge_operations:
update_operations:
- type: send_message
media_type: "Email"
send_to_users:
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def _construct_parameters(self, **kwargs):
"filter": kwargs["conditions"],
"operations": kwargs["operations"],
"recovery_operations": kwargs.get("recovery_operations"),
"acknowledge_operations": kwargs.get("acknowledge_operations"),
"update_operations": kwargs.get("update_operations"),
"status": zabbix_utils.helper_to_numeric_value([
"enabled",
"disabled"], kwargs["status"])
Expand Down Expand Up @@ -1576,9 +1576,9 @@ def construct_the_data(self, operations):
return zabbix_utils.helper_cleanup_data(constructed_data)


class AcknowledgeOperations(Operations):
class UpdateOperations(Operations):
"""
Restructures the user defined acknowledge operations data to fit the Zabbix API requirements
Restructures the user defined update operations data to fit the Zabbix API requirements
"""

def _construct_operationtype(self, operation):
Expand Down Expand Up @@ -1607,16 +1607,16 @@ def _construct_operationtype(self, operation):
"notify_all_involved"], operation["type"]
)
except Exception:
self._module.fail_json(msg="Unsupported value '%s' for acknowledge operation type." % operation["type"])
self._module.fail_json(msg="Unsupported value '%s' for update operation type." % operation["type"])

def construct_the_data(self, operations):
"""Construct the acknowledge operations data using helper methods.
"""Construct the update operations data using helper methods.
Args:
operation: operation to construct
Returns:
list: constructed acknowledge operations data
list: constructed update operations data
"""
constructed_data = []
for op in operations:
Expand Down Expand Up @@ -1655,7 +1655,7 @@ def _construct_evaltype(self, _eval_type, _formula, _conditions):
_conditions: list of conditions to check
Returns:
dict: constructed acknowledge operations data
dict: constructed update operations data
"""
if len(_conditions) <= 1:
return {
Expand Down Expand Up @@ -2117,7 +2117,7 @@ def main():
["type", "send_message", ["send_to_users", "send_to_groups"], True]
]
),
acknowledge_operations=dict(
update_operations=dict(
type="list",
required=False,
default=[],
Expand Down Expand Up @@ -2210,7 +2210,7 @@ def main():
eval_type = module.params["eval_type"]
operations = module.params["operations"]
recovery_operations = module.params["recovery_operations"]
acknowledge_operations = module.params["acknowledge_operations"]
update_operations = module.params["update_operations"]
pause_symptoms = module.params["pause_symptoms"]
notify_if_canceled = module.params["notify_if_canceled"]

Expand All @@ -2220,7 +2220,7 @@ def main():
action_exists = zapi_wrapper.check_if_action_exists(name)
ops = Operations(module, zapi_wrapper)
recovery_ops = RecoveryOperations(module, zapi_wrapper)
acknowledge_ops = AcknowledgeOperations(module, zapi_wrapper)
update_ops = UpdateOperations(module, zapi_wrapper)
fltr = Filter(module, zapi_wrapper)

if action_exists:
Expand All @@ -2245,7 +2245,7 @@ def main():
if LooseVersion(zapi_wrapper._zbx_api_version) >= LooseVersion("6.4"):
kwargs["pause_symptoms"] = pause_symptoms

kwargs[argument_spec["acknowledge_operations"]["aliases"][0]] = acknowledge_ops.construct_the_data(acknowledge_operations)
kwargs[argument_spec["update_operations"]["aliases"][0]] = update_ops.construct_the_data(update_operations)

difference = action.check_difference(**kwargs)

Expand Down Expand Up @@ -2273,7 +2273,7 @@ def main():
notify_if_canceled=notify_if_canceled
)

kwargs[argument_spec["acknowledge_operations"]["aliases"][0]] = acknowledge_ops.construct_the_data(acknowledge_operations)
kwargs[argument_spec["update_operations"]["aliases"][0]] = update_ops.construct_the_data(update_operations)

if LooseVersion(zapi_wrapper._zbx_api_version) >= LooseVersion("6.4"):
kwargs["pause_symptoms"] = pause_symptoms
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/test_zabbix_action/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@
- Admin

block:
- name: test - create new action with recovery and acknowledge operations
- name: test - create new action with recovery and update operations
community.zabbix.zabbix_action:
recovery_operations:
- type: send_message
Expand All @@ -910,7 +910,7 @@
- type: notify_all_involved
subject: RecoverySubject
op_message: RecoveryMessage
acknowledge_operations:
update_operations:
- type: send_message
subject: ExampleSubject
op_message: ExampleMessage
Expand All @@ -926,7 +926,7 @@
- ansible.builtin.assert:
that: zbxaction_recack_new.changed is sameas True

- name: test - create new action with recovery and acknowledge operations (again)
- name: test - create new action with recovery and update operations (again)
community.zabbix.zabbix_action:
recovery_operations:
- type: send_message
Expand All @@ -938,7 +938,7 @@
- type: notify_all_involved
subject: RecoverySubject
op_message: RecoveryMessage
acknowledge_operations:
update_operations:
- type: send_message
subject: ExampleSubject
op_message: ExampleMessage
Expand Down Expand Up @@ -968,7 +968,7 @@
- type: notify_all_involved
subject: RecoverySubject
op_message: RecoveryMessage
acknowledge_operations:
update_operations:
- type: send_message
subject: ExampleSubject
op_message: ExampleMessage
Expand Down Expand Up @@ -997,7 +997,7 @@
- type: notify_all_involved
subject: RecoverySubject
op_message: RecoveryMessage
acknowledge_operations:
update_operations:
- type: send_message
subject: ExampleSubject
op_message: ExampleMessage
Expand Down

0 comments on commit 589ae6a

Please sign in to comment.