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 returns Invalid parameter #600

Closed
lpossamai opened this issue Jan 4, 2022 · 21 comments · Fixed by #648 or #653
Closed

zabbix_action returns Invalid parameter #600

lpossamai opened this issue Jan 4, 2022 · 21 comments · Fixed by #648 or #653
Labels
bug Something isn't working module The issue or pull request is related to Zabbix module

Comments

@lpossamai
Copy link

I'm trying to add a zabbix_action using the following:

- name: Deploy trigger action
  zabbix_action:
    server_url: "{{ zabbix_url }}"
    login_user: "{{ zabbix_web_user }}"
    login_password: "{{ zabbix_web_password }}"
    name: "Send alerts to the OPS team"
    event_source: 'trigger'
    state: present
    status: enabled
    esc_period: 1h
    conditions:
      - type: host_group
        operator: 'like'
        value: 'Zabbix servers'
    operations:
      - type: send_message
        media_type: 'Slackv2'
        send_to_users:
          - 'Admin'
    acknowledge_operations:
      - type: send_message
        media_type: 'Slackv2'
        send_to_users:
          - 'Admin'
    recovery_operations:
      - type: send_message
        media_type: 'Slackv2'
        send_to_users:
          - 'Admin'

The media type Slackv2 already exists. The error that I get is:

<localhost> ESTABLISH SSH CONNECTION FOR USER: None
<localhost> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=2238 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/lucas/.ansible/cp/9533ba4d4c localhost '/bin/sh -c '"'"'rm -f -r /home/lucas/.ansible/tmp/ansible-tmp-1641272906.19573-89276-206089095450568/ > /dev/null 2>&1 && sleep 0'"'"''
<localhost> (0, b'', b'')
The full traceback is:
  File "/tmp/ansible_********_action_payload_0ewax9qz/ansible_********_action_payload.zip/ansible_collections/community/********/plugins/modules/********_action.py", line 917, in add_action
  File "/usr/local/lib/python3.8/dist-packages/********_api.py", line 341, in method
    return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
  File "/usr/local/lib/python3.8/dist-packages/********_api.py", line 79, in wrapper
    return self.do_request(self.json_obj(method, opts))['result']
  File "/usr/local/lib/python3.8/dist-packages/********_api.py", line 348, in do_request
    return self.parent.do_request(req)
  File "/usr/local/lib/python3.8/dist-packages/********_api.py", line 299, in do_request
    raise ZabbixAPIException(msg, jobj['error']['code'])
fatal: [zabbixsecondary1]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "acknowledge_default_message": "",
            "acknowledge_default_subject": "",
            "acknowledge_operations": [
                {
                    "command": null,
                    "command_type": null,
                    "execute_on": null,
                    "media_type": "Slackv2",
                    "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": null,
                    "type": "send_message",
                    "username": null
                }
            ],
            "conditions": [
                {
                    "formulaid": null,
                    "operator": "like",
                    "type": "host_group",
                    "value": "Zabbix servers",
                    "value2": null
                }
            ],
            "default_message": "",
            "default_subject": "",
            "esc_period": "1h",
            "eval_type": null,
            "event_source": "trigger",
            "formula": null,
            "http_login_password": null,
            "http_login_user": null,
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_user": "Admin",
            "name": "Send alerts to the OPS team",
            "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": "Slackv2",
                    "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": 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": "Slackv2",
                    "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": null,
                    "type": "send_message",
                    "username": null
                }
            ],
            "server_url": "http://********-primary.prod.example.com",
            "state": "present",
            "status": "enabled",
            "timeout": 10,
            "validate_certs": true
        }
    },
    "msg": "Failed to create action 'Send alerts to the OPS team': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"acknowledge_operations\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Send alerts to the OPS team\", \"eventsource\": \"0\", \"esc_period\": \"1h\", \"filter\": {\"conditions\": [{\"conditiontype\": \"0\", \"value\": \"4\", \"operator\": \"2\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"0\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"35\"}, \"opmessage_usr\": [{\"userid\": \"1\"}], \"opconditions\": []}], \"recovery_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"35\"}, \"opmessage_usr\": [{\"userid\": \"1\"}]}], \"acknowledge_operations\": [{\"operationtype\": \"0\", \"opmessage\": {\"default_msg\": \"1\", \"mediatypeid\": \"35\"}, \"opmessage_usr\": [{\"userid\": \"1\"}]}], \"status\": \"0\", \"pause_suppressed\": \"1\"}, \"auth\": \"a7b532f59898902ea21066dc9759151a\", \"id\": 3}', -32602)"
}

Ansible version:

ansible [core 2.12.1]
  config file = None
  configured module search path = ['/Users/lucas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/lucas/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.9.9 (main, Nov 21 2021, 03:16:13) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 2.11.3
  libyaml = False

Zabbix version: 6.0.0beta1

Not sure if this is a bug or if I'm missing something?

@D3DeFi
Copy link
Contributor

D3DeFi commented Jan 5, 2022

@lpossamai hi and thank you for reporting this. It may very well be a bug and needs more investigation, we are currently in process to optimize 5.4, which will (atleast we hope) fix some of the bugs present on 6.0 in advance. Unfortunately, we haven't had time to cover 6.0 yet.

@D3DeFi D3DeFi added bug Something isn't working module The issue or pull request is related to Zabbix module labels Jan 5, 2022
@lpossamai
Copy link
Author

Thanks @D3DeFi . I'll re-install Zabbix version 5.4. Was using version 6 just because of its HA feature. But I can wait. Thanks.

@lpossamai
Copy link
Author

I can confirm this is working on Zabbix version 5.4.9. It is not working on Zabbix 6.0.

@dj-wasabi
Copy link
Contributor

Thanks @D3DeFi . I'll re-install Zabbix version 5.4. Was using version 6 just because of its HA feature. But I can wait. Thanks.

Ha! Waiting on that feature as well with my new deployment.. 😉

@lpossamai
Copy link
Author

Thanks @D3DeFi . I'll re-install Zabbix version 5.4. Was using version 6 just because of its HA feature. But I can wait. Thanks.

Ha! Waiting on that feature as well with my new deployment.. 😉

It's so cool! And so easy to setup! Been trying it out on 6.0.

@crashwind
Copy link
Contributor

same problem

@valintinr
Copy link

valintinr commented Mar 9, 2022

Hello,
same issue when creating autoregistration action

Zabbix 6.0.0

[valintinr@xps-arch zabbix]$ git branch 
* main
[valintinr@xps-arch zabbix]$ git log | head -n 3
commit fa779d31b32457a4f8d89b5d0385df6ac3c6ba5a
Author: Dusan Matejka <[email protected]>
Date:   Tue Mar 8 14:56:02 2022 +0100
TASK [Add autoregistration] ***************************************************************************************************************************************************************************************************************************************************************************
failed: [zabbix-bos] (item={'name': 'Servers/Admin', 'host_name_match': '^admin[0-9]-c[0-9].(inap|bos)', 'templates': ['admin', 'DEFAULT']}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "ansible_loop_var": "item", "changed": false, "item": {"host_name_match": "^admin[0-9]-c[0-9].(inap|bos)", "name": "Servers/Admin", "templates": ["admin", "DEFAULT"]}, "msg": "Failed to create action 'Servers/Admin': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"acknowledge_operations\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Servers/Admin\", \"eventsource\": \"2\", \"esc_period\": \"1m\", \"filter\": {\"conditions\": [{\"conditiontype\": \"22\", \"value\": \"^admin[0-9]-c[0-9].(inap|bos)\", \"operator\": \"8\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"4\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"opgroup\": [{\"groupid\": \"21\"}]}, {\"operationtype\": \"6\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"optemplate\": [{\"templateid\": \"10831\"}, {\"templateid\": \"10839\"}]}], \"recovery_operations\": [], \"acknowledge_operations\": [], \"status\": \"0\"}, \"auth\": \"ad5fc5a5ed29a28d36b82bb45fd01c72\", \"id\": 3}', -32602)"}

Example

    - name: Add autoregistration
      community.zabbix.zabbix_action:
        server_url: "https://{{ server_hostname }}"
        login_user: "{{ zabbix_default_http_user }}"
        login_password: "{{ zabbix_default_http_password }}"
        event_source: "auto_registration"
        state: present
        status: enabled
        esc_period: 1m
        name: "{{ item.name }}"
        conditions:
          - type: "host_name"
            operator: "matches"
            value: "{{ item.host_name_match }}"
        operations:
          - type: "add_to_host_group"
            host_groups: "{{ item.name }}"
          - type: "link_to_template"
            templates: "{{ item.templates }}"
      with_items:
        - "{{ zabbix_server_data_autoregistrations }}"

zabbix_server_data_autoregistrations:
  - { name: "Servers/Admin", host_name_match: "^admin[0-9]-c[0-9].(inap|bos)", templates: [admin, DEFAULT] }

@valintinr
Copy link

Is this really fixed If I still has same error during ansible task?

@D3DeFi
Copy link
Contributor

D3DeFi commented Mar 11, 2022

are you using zabbix community from master branch or 1.5.0 version? Because this patch has not been released yet to ansible galaxy

Edit: ok I see from your last comment that you are running from source. Have you tried to checkout latest changes? Does it still occur?

@valintinr
Copy link

Ok, tried latest git commit

[valintinr@xps-arch zabbix]$ git branch 
* main
[valintinr@xps-arch zabbix]$ git log | head -n 3
commit e16519e24ca349ca684ef4547229a889e7ff5864
Author: Kirill Petrov <[email protected]>
Date:   Fri Mar 11 11:20:28 2022 +0200

now error msg changed
playbook same

Full
failed: [zabbix-bos] (item={'name': 'Servers/Admin', 'host_name_match': '^admin[0-9]-c[0-9].(inap|bos)', 'templates': ['admin', 'DEFAULT']}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "ansible_loop_var": "item", "changed": false, "item": {"host_name_match": "^admin[0-9]-c[0-9].(inap|bos)", "name": "Servers/Admin", "templates": ["admin", "DEFAULT"]}, "msg": "Failed to create action 'Servers/Admin': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"esc_period\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"action.create\", \"params\": {\"name\": \"Servers/Admin\", \"eventsource\": \"2\", \"esc_period\": \"1m\", \"filter\": {\"conditions\": [{\"conditiontype\": \"22\", \"value\": \"^admin[0-9]-c[0-9].(inap|bos)\", \"operator\": \"8\"}], \"evaltype\": \"0\"}, \"operations\": [{\"operationtype\": \"4\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"opgroup\": [{\"groupid\": \"21\"}]}, {\"operationtype\": \"6\", \"esc_step_from\": 1, \"esc_step_to\": 1, \"optemplate\": [{\"templateid\": \"10831\"}, {\"templateid\": \"10839\"}]}], \"recovery_operations\": [], \"status\": \"0\", \"update_operations\": []}, \"auth\": \"0dc5b96d217b0d6827014cd1c050ba73\", \"id\": 3}', -32602)"}

Short
"msg": "Failed to create action 'Servers/Admin': ('Error -32602: Invalid params., Invalid parameter \"/1\": unexpected parameter \"esc_period\"

removed esc_period from playbook

failed: [zabbix-bos] (item={'name': 'Servers/Admin', 'host_name_match': '^admin[0-9]-c[0-9].(inap|bos)', 'templates': ['admin', 'DEFAULT']}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "ansible_loop_var": "item", "changed": false, "item": {"host_name_match": "^admin[0-9]-c[0-9].(inap|bos)", "name": "Servers/Admin", "templates": ["admin", "DEFAULT"]}, "msg": "state is present but all of the following are missing: esc_period"}

@D3DeFi D3DeFi reopened this Mar 11, 2022
@valintinr
Copy link

I can set up a clean zabbix 6.0 test server for you (if required)

@D3DeFi
Copy link
Contributor

D3DeFi commented Mar 11, 2022

@valintinr I reopened the issue, but I will not have time to address it in the near future. Perhaps @crashwind can investigate a bit more?

@valintinr
Copy link

Tried to query the api directly

Original ansible query (auth_token and req_id my internal variables)

    data = {
        'jsonrpc': '2.0',
        'method': 'action.create',
        'params': {
            'name': 'Servers/Admin',
            'eventsource': '2',
            'esc_period': '1m',
            'filter': {
                'conditions': [
                    {
                        'conditiontype': '22',
                        'value': '^admin[0-9]-c[0-9].(inap|bos)',
                        'operator': '8'
                    }
                ],
                'evaltype': '0'
            },
            'operations': [
                {
                    'operationtype': '4',
                    'esc_step_from': 1,
                    'esc_step_to': 1,
                    'opgroup': [
                        {
                            'groupid': '21'
                        }
                    ]
                },
                {
                    'operationtype': '6',
                    'esc_step_from': 1,
                    'esc_step_to': 1,
                    'optemplate': [
                        {
                            'templateid': '10831'
                        },
                        {
                            'templateid': '10839'
                        }
                    ]
                }
            ],
            'recovery_operations': [
            ],
            'status': '0',
            'update_operations': [
            ]
        },
        'auth': auth_token,
        'id': req_id
    }

working query

    data = {
        'jsonrpc': '2.0',
        'method': 'action.create',
        'params': {
            'name': 'Servers/Admin',
            'eventsource': '2',
            'filter': {
                'conditions': [
                    {
                        'conditiontype': '22',
                        'value': '^admin[0-9]-c[0-9].(inap|bos)',
                        'operator': '8'
                    }
                ],
                'evaltype': '0'
            },
            'operations': [
                {
                    'operationtype': '4',
                    'opgroup': [
                        {
                            'groupid': '21'
                        }
                    ]
                },
                {
                    'operationtype': '6',
                    'optemplate': [
                        {
                            'templateid': '10831'
                        },
                        {
                            'templateid': '10839'
                        }
                    ]
                }
            ],
            'status': '0',
        },
        'auth': auth_token,
        'id': req_id
    }

diff (removed esc_* and empty recovery_operations and empty update_operations)

48d47
<             'esc_period': '1m',
62,63d60
<                     'esc_step_from': 1,
<                     'esc_step_to': 1,
72,73d68
<                     'esc_step_from': 1,
<                     'esc_step_to': 1,
84,85d78
<             'recovery_operations': [
<             ],
87,88d79
<             'update_operations': [
<             ]

@valintinr
Copy link

So I assume when
event_source = discovery or event_source = auto_registration (event_source = discovery I will test a bit later)
params
esc_period, esc_step_from, esc_step_to, recovery_operations, update_operations should NOT be added to api query.

@crashwind
Copy link
Contributor

ok, i will check it as soon as i can

@valintinr
Copy link

Great, thanks

@valintinr
Copy link

Works fine, thank you (merged pr locally)


TASK [Add autoregistration] ***************************************************************************************************************************************************************************************************************************************************************************
changed: [zabbix-bos] => (item={'name': 'Servers/Admin', 'host_name_match': '^admin[0-9]-c[0-9].(inap|bos)', 'templates': ['admin', 'DEFAULT']})

PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************************************
zabbix-bos                 : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@valintinr
Copy link

I found another issue - an incorrect message when authentication fails. This happens when I try to create a new discovery action.

Some example:

    - name: Add discovery old servers
      community.zabbix.zabbix_action:
        server_url: "https://{{ server_hostname }}"
        login_user: "{{ zabbix_server_data_api_user }}"
        login_password: "{{ zabbix_server_data_api_password }}"
        event_source: "discovery"
        state: present
        status: enabled
        name: "{{ item.name }}"
        conditions:
          - type: "host_IP"
            operator: "="
            value: "{{ item.host_ip_equals }}"
        operations:
          - type: "add_to_host_group"
            host_groups: "{{ item.hostgroup }}"
          - type: "link_to_template"
            templates: "{{ item.templates }}"
      with_items:
        - "{{ zabbix_server_data_discovery }}"


zabbix_server_data_discovery:
  - { name: "Servers/Old-inap", hostgroup: "Servers/Old", host_ip_equals: "SOME_IP", templates: [old] }

and result

TASK [Add discovery old servers] **********************************************************************************************************************************************************************************************************************************************************************
failed: [zabbix-bos] (item={'name': 'Servers/Old-inap', 'hostgroup': 'Servers/Old', 'host_ip_equals': 'SOME_IP', 'templates': ['old']}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "ansible_loop_var": "item", "changed": false, "item": {"host_ip_equals": "SOME_IP", "hostgroup": "Servers/Old", "name": "Servers/Old-inap", "templates": ["old"]}, "msg": "Host group not found: Servers/Old"}
"msg": "Host group not found: Servers/Old"

Hostgroup Servers/Old exists and when I fixed the login/password this code started working fine.

@crashwind
Copy link
Contributor

yeah right, it`s another issue, not related to #600

@D3DeFi
Copy link
Contributor

D3DeFi commented Mar 21, 2022

Thank you both for participating on solving this problem! Much appreciated :)

@D3DeFi
Copy link
Contributor

D3DeFi commented Mar 21, 2022

I found another issue - an incorrect message when authentication fails. This happens when I try to create a new discovery action.

Some example:

    - name: Add discovery old servers
      community.zabbix.zabbix_action:
        server_url: "https://{{ server_hostname }}"
        login_user: "{{ zabbix_server_data_api_user }}"
        login_password: "{{ zabbix_server_data_api_password }}"
        event_source: "discovery"
        state: present
        status: enabled
        name: "{{ item.name }}"
        conditions:
          - type: "host_IP"
            operator: "="
            value: "{{ item.host_ip_equals }}"
        operations:
          - type: "add_to_host_group"
            host_groups: "{{ item.hostgroup }}"
          - type: "link_to_template"
            templates: "{{ item.templates }}"
      with_items:
        - "{{ zabbix_server_data_discovery }}"


zabbix_server_data_discovery:
  - { name: "Servers/Old-inap", hostgroup: "Servers/Old", host_ip_equals: "SOME_IP", templates: [old] }

and result

TASK [Add discovery old servers] **********************************************************************************************************************************************************************************************************************************************************************
failed: [zabbix-bos] (item={'name': 'Servers/Old-inap', 'hostgroup': 'Servers/Old', 'host_ip_equals': 'SOME_IP', 'templates': ['old']}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "ansible_loop_var": "item", "changed": false, "item": {"host_ip_equals": "SOME_IP", "hostgroup": "Servers/Old", "name": "Servers/Old-inap", "templates": ["old"]}, "msg": "Host group not found: Servers/Old"}
"msg": "Host group not found: Servers/Old"

Hostgroup Servers/Old exists and when I fixed the login/password this code started working fine.

would you mind opening new issue for this please? Or PR would work too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module The issue or pull request is related to Zabbix module
Projects
None yet
5 participants