ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
322 stars 284 forks source link

Zabbix_action: recovery_operations uses default media_type with type `send_messages` #728

Closed hiddenshadow21 closed 2 years ago

hiddenshadow21 commented 2 years ago
SUMMARY

When recovery_operations type is set to send_message it always uses default media_type (All). It ignores media_type property.

ISSUE TYPE
COMPONENT NAME

Zabbix_action: recovery_operation

ANSIBLE VERSION
ansible [core 2.13.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True
CONFIGURATION
OS / ENVIRONMENT / Zabbix Version

TargetOS: Ubuntu 20.04 LTS Zabbix Version: 6.0.6 LTS

STEPS TO REPRODUCE

Create action with recovery operation type set to send_message and specify media_type

- name: Notify 
  zabbix_action:
    url: "{{ custom_url }}"
    login_user: "user"
    login_password: "pass"
    name: "Send alerts"
    event_source: trigger
    state: present
    status: enabled
    esc_period: 600
    conditions:
      - type: host
        operator: '='
        value: 'Zabbix server'
    formula: A
    operations:
      - type: send_message
        esc_step_from: 2
        esc_step_to: 99
        media_type: 'Slack'
        subject: "{{ custom_subject }}"
        message: "{{ custom_message }}"
        operation_condition: 'not_acknowledged'
        send_to_users:
          - 'Admin'

    recovery_operations: 
      - type: send_message
        media_type: 'Slack'
        subject: "{{ custom_subject }}"
        message: "{{ custom_message }}"
        send_to_users:
          - 'Admin'
EXPECTED RESULTS

Action is created with operations and recovery_operations sending messages using specified media.

ACTUAL RESULTS

Action is created with operations using specified media but recovery_operations media_type is set to All.

changed: [127.0.0.1] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "acknowledge_default_message": "",
            "acknowledge_default_subject": "",
            "acknowledge_operations": [],
            "conditions": [
                {
                    "formulaid": null,
                    "operator": "=",
                    "type": "host",
                    "value": "Zabbix server",
                    "value2": null
                }
            ],
            "default_message": "",
            "default_subject": "",
            "esc_period": "600",
            "eval_type": null,
            "event_source": "trigger",
            "formula": "A",
            "http_login_password": null,
            "http_login_user": null,
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_user": "Admin",
            "name": "Send alerts",
            "operations": [
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": null,
                    "esc_step_from": 2,
                    "esc_step_to": 99,
                    "execute_on": null,
                    "host_groups": null,
                    "inventory": null,
                    "media_type": "Slack",
                    "message": null,
                    "operation_condition": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": [
                        "Admin"
                    ],
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": "subject",
                    "templates": null,
                    "type": "send_message",
                    "username": null
                }
            ],
            "pause_in_maintenance": true,
            "recovery_default_message": "",
            "recovery_default_subject": "",
            "recovery_operations": [
                {
                    "command": null,
                    "command_type": null,
                    "execute_on": null,
                    "media_type": "Slack",
                    "message": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": [
                        "Admin"
                    ],
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": "subject",
                    "type": "send_message",
                    "username": null
                }
            ],
            "server_url": "server_url",
            "state": "present",
            "status": "enabled",
            "timeout": 10,
            "url": "url",
            "validate_certs": true
        }
    },
    "msg": "Action Updated: Send alerts, ID: {'actionids': ['32']}"
}

image

jurruh commented 2 years ago

Same problem here, looks like something wrong on https://github.com/ansible-collections/community.zabbix/blob/e62cd33202a4e795f3d9cc179996680069748eff/plugins/modules/zabbix_action.py#L1333 or https://github.com/ansible-collections/community.zabbix/blob/e62cd33202a4e795f3d9cc179996680069748eff/plugins/modules/zabbix_action.py#L1338

jurruh commented 2 years ago

Fixed proposed: https://github.com/ansible-collections/community.zabbix/pull/734

BGmot commented 2 years ago

In your very first post I see in the module invocation media_type set properly.

changed: [127.0.0.1] => {
    "changed": true,
    "invocation": {
        "module_args": {
<snip>
            "recovery_operations": [
                {
                    "media_type": "Slack",

how is that possible without your PR?

jurruh commented 2 years ago

The invocation of @hiddenshadow21 is done correctly. But https://github.com/ansible-collections/community.zabbix/blob/e62cd33202a4e795f3d9cc179996680069748eff/plugins/modules/zabbix_action.py#L1332-L1333

removes it before sending to the Zabbix api.

BGmot commented 2 years ago

Ok, makes sense, thanks. I don't remember why I put this .pop() code, we'll see how your tests are running.