ansible-collections / community.zabbix

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

Unable to create actions in Zabbix 6.0 #661

Closed felix-s84 closed 2 years ago

felix-s84 commented 2 years ago
SUMMARY

Unable to create actions in Zabbix 6.0

ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix_action

ANSIBLE VERSION
  config file = /home/user/ansible_configs/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
CONFIGURATION
ANSIBLE_SSH_ARGS(/home/user/ansible_configs/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=60s
DEFAULT_STRATEGY(env: ANSIBLE_STRATEGY) = linear
DEFAULT_STRATEGY_PLUGIN_PATH(/home/user/ansible_configs/ansible.cfg) = ['/home/user/ansible_configs/plugins/strategy/mitogen-0.2.10/ansible_mitogen/plugins/strategy']
HOST_KEY_CHECKING(/home/user/ansible_configs/ansible.cfg) = False
MAX_FILE_SIZE_FOR_DIFF(/home/user/ansible_configs/ansible.cfg) = 2097152
PERSISTENT_CONNECT_TIMEOUT(/home/user/ansible_configs/ansible.cfg) = 30
OS / ENVIRONMENT / Zabbix Version

zabbix_server --version zabbix_server (Zabbix) 6.0.2 Revision d726a4d 14 March 2022, compilation time: Mar 14 2022 12:17:53

STEPS TO REPRODUCE

run playbook

  community.zabbix.zabbix_action:
    login_user: "{{ zabbix.login_user }}"
    login_password: "{{ zabbix.login_password }}"
    server_url: "{{ zabbix.server_url }}"
    name: '{{item.name}}'
    event_source: '{{item.event_source | default("trigger")}}'
    state: present
    status: enabled
    esc_period: '{{item.esc_period}}'
    conditions: '{{item.conditions}}'
    formula: '{{item.formula | default("A and B")}}'
    eval_type: '{{item.eval_type | default("andor")}}'
    operations: '{{item.operations}}'
    recovery_operations: '{{item.recovery_operations}}'
    acknowledge_operations: '{{item.acknowledge_operations | default([])}}'
    validate_certs: No
  with_items: 
    - '{{actions}}'
  tags: ['zabbix_actions']i
EXPECTED RESULTS

action created

ACTUAL RESULTS
  File "/tmp/ansible_community.zabbix.zabbix_action_payload_zj71sfph/ansible_community.zabbix.zabbix_action_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_action.py", line 917, in add_action
  File "/usr/local/lib/python3.6/site-packages/zabbix_api.py", line 341, in method
    return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
  File "/usr/local/lib/python3.6/site-packages/zabbix_api.py", line 79, in wrapper
    return self.do_request(self.json_obj(method, opts))['result']
  File "/usr/local/lib/python3.6/site-packages/zabbix_api.py", line 348, in do_request
    return self.parent.do_request(req)
  File "/usr/local/lib/python3.6/site-packages/zabbix_api.py", line 299, in do_request
    raise ZabbixAPIException(msg, jobj['error']['code'])
failed: [host.com] (item={'name': 'Jira_notifications', 'pause_in_maintenance': True, 'esc_period': 3600, 'conditions': [{'type': 'event_tag_value', 'operator': 'not like', 'value': 'false', 'value2': 'send_event', 'formulaid': 'A'}, {'type': 'event_tag_value', 'operator': 'not like', 'value': 'false', 'value2': 'create_jira_task', 'formulaid': 'B'}, {'type': 'maintenance_status', 'operator': 'No', 'value': '', 'formulaid': 'C'}, {'type': 'trigger_severity', 'operator': '>=', 'value': 'average', 'formulaid': 'D'}, {'type': 'host_group', 'operator': '<>', 'value': 'dev-linux-servers', 'formulaid': 'E'}], 'formula': '(A or B) and C and D and E', 'eval_type': 'andor', 'operations': [{'type': 'send_message', 'media_type': 'all', 'send_to_users': ['jira-notifications']}], 'recovery_operations': [{'type': 'send_message', 'media_type': 'all', 'send_to_users': ['jira-notifications']}], 'acknowledge_operations': [{'type': 'send_message', 'media_type': 'all', 'send_to_users': ['jira-notifications']}]}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "acknowledge_default_message": "",
            "acknowledge_default_subject": "",
            "acknowledge_operations": [
                {
                    "command": null,
                    "command_type": null,
                    "execute_on": null,
                    "media_type": "all",
                    "message": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": [
                        "jira-notifications"
                    ],
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "type": "send_message",
                    "username": null
                }
            ],
            "conditions": [
                {
                    "formulaid": "A",
                    "operator": "not like",
                    "type": "event_tag_value",
                    "value": "false",
                    "value2": "send_event"
                },
                {
                    "formulaid": "B",
                    "operator": "not like",
                    "type": "event_tag_value",
                    "value": "false",
                    "value2": "create_jira_task"
                },
                {
                    "formulaid": "C",
                    "operator": "No",
                    "type": "maintenance_status",
                    "value": "",
                    "value2": null
                },
                {
                    "formulaid": "D",
                    "operator": ">=",
                    "type": "trigger_severity",
                    "value": "average",
                    "value2": null
                },
                {
                    "formulaid": "E",
                    "operator": "<>",
                    "type": "host_group",
                    "value": "dev-linux-servers",
                    "value2": null
                }
            ],
            "default_message": "",
            "default_subject": "",
            "esc_period": "3600",
            "eval_type": "andor",
            "event_source": "trigger",
            "formula": "(A or B) and C and D and E",
            "http_login_password": null,
            "http_login_user": null,
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_user": "ZabbixSync",
            "name": "Jira_notifications",
            "operations": [
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": null,
                    "esc_step_from": 1,
                    "esc_step_to": 1,
                    "execute_on": null,
                    "host_groups": null,
                    "inventory": null,
                    "media_type": "all",
                    "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": [
                        "jira-notifications"
                    ],
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "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": "all",
                    "message": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": [
                        "jira-notifications"
                    ],
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "type": "send_message",
                    "username": null
                }
            ],
            "server_url": "https://host.com/",
            "state": "present",
            "status": "enabled",
            "timeout": 10,
            "validate_certs": false
        }
    },
    "item": {
        "acknowledge_operations": [
            {
                "media_type": "all",
                "send_to_users": [
                    "jira-notifications"
                ],
                "type": "send_message"
            }
        ],
        "conditions": [
            {
                "formulaid": "A",
                "operator": "not like",
                "type": "event_tag_value",
                "value": "false",
                "value2": "send_event"
            },
            {
                "formulaid": "B",
                "operator": "not like",
                "type": "event_tag_value",
                "value": "false",
                "value2": "create_jira_task"
            },
            {
                "formulaid": "C",
                "operator": "No",
                "type": "maintenance_status",
                "value": ""
            },
            {
                "formulaid": "D",
                "operator": ">=",
                "type": "trigger_severity",
                "value": "average"
            },
            {
                "formulaid": "E",
                "operator": "<>",
                "type": "host_group",
                "value": "dev-linux-servers"
            }
        ],
        "esc_period": 3600,
        "eval_type": "andor",
        "formula": "(A or B) and C and D and E",
        "name": "Jira_notifications",
        "operations": [
            {
                "media_type": "all",
                "send_to_users": [
                    "jira-notifications"
                ],
                "type": "send_message"
            }
        ],
        "pause_in_maintenance": true,
        "recovery_operations": [
            {
                "media_type": "all",
                "send_to_users": [
                    "jira-notifications"
                ],
                "type": "send_message"
            }
        ]
    },
    "msg": "Failed to create action 'Jira_notifications': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"acknowledge_operations\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Jira_notifications\", \"eventsource\": \"0\", \"esc_period\": \"3600\", \"filter\": {\"conditions\": [{\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"send_event\", \"formulaid\": \"A\", \"operator\": \"3\"}, {\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"create_jira_task\", \"formulaid\": \"B\", \"operator\": \"3\"}, {\"conditiontype\": \"16\", \"value\": \"\", \"formulaid\": \"C\", \"operator\": \"11\"}, {\"conditiontype\": \"4\", \"value\": \"3\", \"formulaid\": \"D\", \"operator\": \"5\"}, {\"conditiontype\": \"0\", \"value\": \"79\", \"formulaid\": \"E\", \"operator\": \"1\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"0\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}], \"opconditions\": []}], \"recovery_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"acknowledge_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"d8ae014fedcdb47f89bc8d5c0bc6ddba\", \"id\": 3}', -32602)"
D3DeFi commented 2 years ago

Hi @felix-s84 , thank you for reporting this issue. Would you be able to test with with community.zabbix checked out from master branch? There were a few PRs merged specifically for zabbix_action with zbx 5.4/6.0

waldo323 commented 2 years ago

for zabbix 6.0.2 I'm getting the same error code while trying to create an email media type.

I am using the git repo https://github.com/ansible-collections/community.zabbix.git the setup uses python 3.9, vagrant, ansible on Rocky 8.x virtualbox vms: is in this github repo

ansible [core 2.12.3] config file = /ansible/ansible.cfg configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.9/site-packages/ansible ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.9.6 (default, Nov 9 2021, 13:31:27) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] jinja version = 3.1.0 libyaml = True

TASK [Create an email mediatype with message templates] ** FAILED - RETRYING: [node-1]: Create an email mediatype with message templates (3 retries left). FAILED - RETRYING: [node-1]: Create an email mediatype with message templates (2 retries left). FAILED - RETRYING: [node-1]: Create an email mediatype with message templates (1 retries left). fatal: [node-1]: FAILED! => {"attempts": 3, "changed": false, "msg": "Failed to create mediatype 'A: Ops email': ('Error -32602: Invalid params., Invalid parameter \"/1/username\": a character string is expected. while sending {\"jsonrpc\": \"2.0\", \"method\": \"mediatype.create\", \"params\": {\"status\": \"0\", \"type\": \"0\", \"name\": \"A: Ops email\", \"description\": \"\", \"maxsessions\": \"1\", \"maxattempts\": \"3\", \"attempt_interval\": \"10\", \"message_templates\": [{\"eventsource\": \"0\", \"recovery\": \"0\", \"subject\": \"Problem: {EVENT.NAME}\", \"message\": \"Problem started at {EVENT.TIME} on {EVENT.DATE}\\r\\nProblem name: {EVENT.NAME}\\r\\n\"}, {\"eventsource\": \"0\", \"recovery\": \"1\", \"subject\": \"Resolved: {EVENT.NAME}\", \"message\": \"Problem resolved at {EVENT.TIME} on {EVENT.DATE}\\r\\nProblem name: {EVENT.NAME}\\r\\n\"}, {\"eventsource\": \"0\", \"recovery\": \"2\", \"subject\": \"Updated problem: {EVENT.NAME}\", \"message\": \"{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.\\r\\n\"}, {\"eventsource\": \"1\", \"recovery\": \"0\", \"subject\": \"Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}\", \"message\": \"Discovery rule: {DISCOVERY.RULE.NAME}\\r\\n\\r\\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}\"}, {\"eventsource\": \"2\", \"recovery\": \"0\", \"subject\": \"Autoregistration: {HOST.HOST}\", \"message\": \"Host name: {HOST.HOST}\\r\\nHost IP: {HOST.IP}\\r\\nAgent port: {HOST.PORT}\"}], \"smtp_server\": \"mail.example.com\", \"smtp_port\": \"25\", \"smtp_helo\": \"example.com\", \"smtp_email\": \"ops@example.com\", \"smtp_security\": \"0\", \"smtp_authentication\": \"0\", \"smtp_verify_host\": \"0\", \"smtp_verify_peer\": \"0\", \"username\": null, \"passwd\": null}, \"auth\": \"c92eefa6610f9effff91b09b59c0de97\", \"id\": 3}', -32602)

felix-s84 commented 2 years ago

Hi @felix-s84 , thank you for reporting this issue. Would you be able to test with with community.zabbix checked out from master branch? There were a few PRs merged specifically for zabbix_action with zbx 5.4/6.0

Hi! Tested with latest version from master branch:

"msg": "Failed to create action 'Jira_notifications': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"def_longdata\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Jira_notifications\", \"eventsource\": \"0\", \"esc_period\": 3600, \"filter\": {\"conditions\": [{\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"send_event\", \"formulaid\": \"A\", \"operator\": \"3\"}, {\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"create_jira_task\", \"formulaid\": \"B\", \"operator\": \"3\"}, {\"conditiontype\": \"16\", \"value\": \"\", \"formulaid\": \"C\", \"operator\": \"11\"}, {\"conditiontype\": \"4\", \"value\": \"3\", \"formulaid\": \"D\", \"operator\": \"5\"}, {\"conditiontype\": \"0\", \"value\": \"79\", \"formulaid\": \"E\", \"operator\": \"1\"}], \"evaltype\": \"0\"}, \"def_longdata\": \"\", \"def_shortdata\": \"\", \"r_longdata\": \"\", \"r_shortdata\": \"\", \"ack_longdata\": \"\", \"ack_shortdata\": \"\", \"operations\": [{\"operationtype\": \"0\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"89\"}], \"opconditions\": []}], \"recovery_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"89\"}]}], \"acknowledge_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"89\"}]}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"86ab2cac91bf8479901889884840e0a1\", \"id\": 7}', -32602)"

BGmot commented 2 years ago

The error does not make any sense unexpected parameter \"def_longdata\" Parameter def_longdata is removed for Zabbix version >= 5.0 here https://github.com/ansible-collections/community.zabbix/blob/main/plugins/modules/zabbix_action.py#L865 Can you double check zabbix_action.py for this piece of code for the collection you have in place?

felix-s84 commented 2 years ago

Hi! Cheked my zabbix_action.py: `requirements:

Found "def_longdata" here:

            # remove some fields regarding
            # https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object
            _params.pop('def_longdata', None)
            _params.pop('def_shortdata', None)
            _params.pop('r_longdata', None)
            _params.pop('r_shortdata', None)
_params = {
            'name': kwargs['name'],
            'eventsource': to_numeric_value([
                'trigger',
                'discovery',
                'auto_registration',
                'internal'], kwargs['event_source']),
            'esc_period': kwargs.get('esc_period'),
            'filter': kwargs['conditions'],
            'def_longdata': kwargs['default_message'],
            'def_shortdata': kwargs['default_subject'],
            'r_longdata': kwargs['recovery_default_message'],
            'r_shortdata': kwargs['recovery_default_subject'],
            'ack_longdata': kwargs['acknowledge_default_message'],
            'ack_shortdata': kwargs['acknowledge_default_subject'],
            'operations': kwargs['operations'],
            'recovery_operations': kwargs.get('recovery_operations'),
            'acknowledge_operations': kwargs.get('acknowledge_operations'),
            'status': to_numeric_value([
                'enabled',
                'disabled'], kwargs['status'])
}
BGmot commented 2 years ago

Hi! does not make any sense to me. You either use the collection from different place or your Zabbix version is < 5.0. For debugging can you temporarily insert one line prior to https://github.com/ansible-collections/community.zabbix/blob/main/plugins/modules/zabbix_action.py#L862 so it looks this way:

        self._module.fail_json(msg="Zabbix version=%s" % LooseVersion(self._zbx_api_version)
        if LooseVersion(self._zbx_api_version) >= LooseVersion('5.0'):
            # remove some fields regarding
            # https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object
            _params.pop('def_longdata', None)
            _params.pop('def_shortdata', None)
            _params.pop('r_longdata', None)
            _params.pop('r_shortdata', None)

and give us the message you get when the run fails?

felix-s84 commented 2 years ago

I think i figured out: my new ansible-collection modules are in: /home/user/.ansible/collections/ansible_collections/community/zabbix/ But playbook output shows: Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/monitoring/zabbix/zabbix_action.py which is outdated.

BGmot commented 2 years ago

Run ansible --version it will tell you all the paths it searches collections in. In my case it takes ~/.ansible/collections/ansible_collections first then goes to /usr/local/lib/... In any case if you don't need this collection for all users then just remove it from /usr/local/lib/... or update it with

umask 0022
sudo ansible-galaxy collection install -U ...

See the docs for your ansible version.

felix-s84 commented 2 years ago

Hi! I've updated zabbix_action.py and other modules to recent version and got another error: "msg": "Failed to create action 'Jira_notifications': ('Error -32602: Invalid params., Invalid parameter \"/1/filter/conditions/1\": unexpected parameter \"formulaid\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Jira_notifications\", \"eventsource\": \"0\", \"esc_period\": \"3600\", \"filter\": {\"conditions\": [{\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"send_event\", \"formulaid\": \"A\", \"operator\": \"3\"}, {\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"create_jira_task\", \"formulaid\": \"B\", \"operator\": \"3\"}, {\"conditiontype\": \"16\", \"value\": \"\", \"formulaid\": \"C\", \"operator\": \"11\"}, {\"conditiontype\": \"4\", \"value\": \"3\", \"formulaid\": \"D\", \"operator\": \"5\"}, {\"conditiontype\": \"0\", \"value\": \"79\", \"formulaid\": \"E\", \"operator\": \"1\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"recovery_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"1502016f5bc8945f46a62254f11f915f\", \"id\": 3}', -32602)"

BGmot commented 2 years ago

remote formulaid. First forumula in conditions list will be assigned 'A', the second - 'B' etc

felix-s84 commented 2 years ago

remote formulaid. First forumula in conditions list will be assigned 'A', the second - 'B' etc

What do you mean "remote"?

BGmot commented 2 years ago

Sorry, meant "remove" in here:

community.zabbix.zabbix_action:
    ...
    formula: '{{item.formula | default("A and B")}}'
felix-s84 commented 2 years ago

But what if we have custom formula formula: '(A or B) and C and D and E'? Now i removed this line and all 'formulaid' strings and got another error: "msg": "Failed to create action 'Jira_notifications': ('Error -32602: Invalid params., Invalid parameter \"/1/filter/conditions/3\": unexpected parameter \"value\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Jira_notifications\", \"eventsource\": \"0\", \"esc_period\": \"3600\", \"filter\": {\"conditions\": [{\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"send_event\", \"operator\": \"3\"}, {\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"create_jira_task\", \"operator\": \"3\"}, {\"conditiontype\": \"16\", \"value\": \"\", \"operator\": \"11\"}, {\"conditiontype\": \"4\", \"value\": \"3\", \"operator\": \"5\"}, {\"conditiontype\": \"0\", \"value\": \"79\", \"operator\": \"1\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"recovery_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}, \"opmessage_usr\": [{\"userid\": \"91\"}]}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"7031741eb721eb1672845fa909026d77\", \"id\": 3}', -32602)"

ogenstad commented 2 years ago

I can confirm that the error we saw against Zabbix 6.x related to acknowledge_operations as below is broken in 1.5.1 but works when the main branch (tested from commit d8c9a3545b943bcdc4e150298cc963ff320a6f43)

Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"acknowledge_operations\".

Is there any estimate as to when the next version will be published?

BGmot commented 2 years ago

There are numerious fixes for zabbix_action in https://github.com/ansible-collections/community.zabbix/pull/664 for Zabbix 6.0. Most of them due to introduced "added strict validation of the methods parameters" https://www.zabbix.com/documentation/current/en/manual/api/changes_5.4_-_6.0#action

D3DeFi commented 2 years ago

Thank you folks for working this issue out! @BGmot big thanks for contributing PR to address this.

@ogenstad release was pre-prepared in #659 . Since I got at least one approval now, I would like to merge few of the PRs and then proceed with release. Hopefully over the weekend.

D3DeFi commented 2 years ago

@felix-s84 can you please test with latest changes in main branch once again? thank you in advance!

felix-s84 commented 2 years ago

still the same https://github.com/ansible-collections/community.zabbix/issues/661#issuecomment-1091615971

BGmot commented 2 years ago

@felix-s84 what does your "community.zabbix.zabbix_action:" look like right now?

felix-s84 commented 2 years ago

  community.zabbix.zabbix_action:
    login_user: "{{ zabbix.login_user }}"
    login_password: "{{ zabbix.login_password }}"
    server_url: "{{ zabbix.server_url }}"
    name: '{{item.name}}'
    event_source: '{{item.event_source | default("trigger")}}'
    state: present
    status: enabled
    esc_period: '{{item.esc_period}}'
    conditions: '{{item.conditions}}'
    eval_type: '{{item.eval_type | default("and")}}'
    operations: '{{item.operations}}'
    recovery_operations: '{{item.recovery_operations}}'
    acknowledge_operations: '{{item.acknowledge_operations | default([])}}'
    validate_certs: No
  with_items: 
    - '{{actions}}'
  tags: ['zabbix_actions']
BGmot commented 2 years ago

we need to see what your variables are when the error happens... please attache the log from ansible-playbook run, similar to https://github.com/ansible-collections/community.zabbix/issues/661#issue-1175642269 "Actual result" section

BGmot commented 2 years ago

@felix-s84 I reproduced your error. One of your conditions is: conditions:

- type: 'maintenance_status'
  operator: 'No'
  value: ''

According to https://www.zabbix.com/documentation/current/en/manual/api/reference/action/object it should not have 'value' No value required: using the "Yes" operator means that problem must be suppressed, "No" - not suppressed.

so it should be:

conditions:
- type: 'maintenance_status'
  operator: 'No'

But if we run it this way we'll get a response: fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: value found in conditions"} as according to the same documentation 'value' attribute is mandotary for any condition. Looks like a bug in Zabbix to me. Will dig a bit further and file a bug report to Zabbix. As of now I don't think you can do 'maintenance_status' condition via API.

BGmot commented 2 years ago

This issue happens during value attribued marked 'required' in module arguments. FIxed in https://github.com/ansible-collections/community.zabbix/pull/667

D3DeFi commented 2 years ago

With latest patch from @BGmot merged to master, I will now push for 1.6.0 release. @felix-s84 please feel free to re-open this issue if #667 and advice given is this thread wasn't enough to help your issue.

felix-s84 commented 2 years ago

I downloaded latest zabbix_action.py and removed value: '' from variables Now another error: ('Error -32602: Invalid params., Invalid parameter \"/1/recovery_operations/1/opmessage\": unexpected parameter \"mediatypeid\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Report problems to Zabbix administrators\", \"eventsource\": \"0\", \"filter\": {\"conditions\": [{\"conditiontype\": \"26\", \"value\": \"false\", \"value2\": \"send_event\", \"operator\": \"3\"}, {\"conditiontype\": \"16\", \"operator\": \"11\"}, {\"conditiontype\": \"3\", \"value\": \"XenServer Backup Succeeded\", \"operator\": \"3\"}, {\"conditiontype\": \"3\", \"value\": \"XenServer Backup Started\", \"operator\": \"3\"}, {\"conditiontype\": \"3\", \"value\": \"Host information was changed on\", \"operator\": \"3\"}, {\"conditiontype\": \"3\", \"value\": \"has just been restarted\", \"operator\": \"3\"}], \"evaltype\": \"1\"}, \"operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"5\"}, \"opmessage_grp\": [{\"usrgrpid\": \"22\"}]}], \"recovery_operations\": [{\"operationtype\": \"11\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"0\"}}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"51ae7f1ba6e9631cb4f6d8fb92a26163\", \"id\": 3}', -32602)"

But we don't use mediatypeid field in variables

BGmot commented 2 years ago

@felix-s84 please post what you actually provide to community.zabbix.zabbix_action: (run your playbook with -vvv)

BGmot commented 2 years ago

@D3DeFi can we not wait for a bit with pushing 1.6.0? @felix-s84 is a master in finding bugs and I feel like we need much more testing -(.

D3DeFi commented 2 years ago

@D3DeFi can we not wait for a bit with pushing 1.6.0? @felix-s84 is a master in finding bugs and I feel like we need much more testing -(.

Yeah, I will not wait with 1.6.0 on further development in this issue. We are lucky @felix-s84 reports hip findings :) Thank you both for testing/contributing and involving yourself! Much appreciated

BGmot commented 2 years ago

@felix-s84 you last problem should be fixed by https://github.com/ansible-collections/community.zabbix/issues/661 . Plus fixed similar issues with 'update_operations:'

felix-s84 commented 2 years ago

Not fixed msg": "module (community.zabbix.zabbix_action) is missing interpreter line"

BGmot commented 2 years ago

you copied something wrong - it is there https://github.com/BGmot/community.zabbix/blob/main/plugins/modules/zabbix_action.py#L1

felix-s84 commented 2 years ago

Yeah, sorry, wrong download. Everything works now. Thank you very much! Please take a look #670