Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zabbix action: Added operation condition #53173

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/ansible/modules/monitoring/zabbix/zabbix_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@
- Media type that will be used to send the message.
- Set to C(all) for all media types
default: 'all'
operation_condition:
type: 'str'
description:
- The action operation condition object defines a condition that must be met to perform the current operation.
choices:
- acknowledged
- not_acknowledged
host_groups:
type: list
description:
Expand Down Expand Up @@ -1059,6 +1066,28 @@ def _construct_opinventory(self, operation):
"""
return {'inventory_mode': operation.get('inventory')}

def _construct_opconditions(self, operation):
"""Construct operation conditions.

Args:
operation: operation to construct the conditions

Returns:
list: constructed operaration conditions
"""
_opcond = operation.get('operation_condition')
if _opcond is not None:
if _opcond == 'acknowledged':
_value = '1'
elif _opcond == 'not_acknowledged':
_value = '0'
return [{
'conditiontype': '14',
'operator': '0',
'value': _value
}]
return []

def construct_the_data(self, operations):
"""Construct the operation data using helper methods.

Expand All @@ -1082,12 +1111,14 @@ def construct_the_data(self, operations):
constructed_operation['opmessage'] = self._construct_opmessage(op)
constructed_operation['opmessage_usr'] = self._construct_opmessage_usr(op)
constructed_operation['opmessage_grp'] = self._construct_opmessage_grp(op)
constructed_operation['opconditions'] = self._construct_opconditions(op)

# Send Command type
if constructed_operation['operationtype'] == '1':
constructed_operation['opcommand'] = self._construct_opcommand(op)
constructed_operation['opcommand_hst'] = self._construct_opcommand_hst(op)
constructed_operation['opcommand_grp'] = self._construct_opcommand_grp(op)
constructed_operation['opconditions'] = self._construct_opconditions(op)

# Add to/Remove from host group
if constructed_operation['operationtype'] in ('4', '5'):
Expand Down Expand Up @@ -1673,6 +1704,12 @@ def main():
esc_period=dict(type='int', required=False),
esc_step_from=dict(type='int', required=False, default=1),
esc_step_to=dict(type='int', required=False, default=1),
operation_condition=dict(
type='str',
required=False,
default=None,
choices=['acknowledged', 'not_acknowledged']
),
# when type is remote_command
command_type=dict(
type='str',
Expand Down