Closed felix-s84 closed 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
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)
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)"
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?
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'])
}
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?
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.
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.
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)"
remote formulaid. First forumula in conditions list will be assigned 'A', the second - 'B' etc
remote formulaid. First forumula in conditions list will be assigned 'A', the second - 'B' etc
What do you mean "remote"?
Sorry, meant "remove" in here:
community.zabbix.zabbix_action:
...
formula: '{{item.formula | default("A and B")}}'
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)"
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?
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
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.
@felix-s84 can you please test with latest changes in main
branch once again? thank you in advance!
@felix-s84 what does your "community.zabbix.zabbix_action:" look like right now?
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']
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
@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.
This issue happens during value attribued marked 'required' in module arguments. FIxed in https://github.com/ansible-collections/community.zabbix/pull/667
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.
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
@felix-s84 please post what you actually provide to community.zabbix.zabbix_action: (run your playbook with -vvv)
@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 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
@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:'
Not fixed
msg": "module (community.zabbix.zabbix_action) is missing interpreter line"
you copied something wrong - it is there https://github.com/BGmot/community.zabbix/blob/main/plugins/modules/zabbix_action.py#L1
Yeah, sorry, wrong download. Everything works now. Thank you very much! Please take a look #670
SUMMARY
Unable to create actions in Zabbix 6.0
ISSUE TYPE
COMPONENT NAME
community.zabbix.zabbix_action
ANSIBLE VERSION
CONFIGURATION
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
EXPECTED RESULTS
action created
ACTUAL RESULTS