Fix login and session issues connecting to zabbix #1380
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
Fixes #1209 because reset_connection will no longer be necessary in that context
Disconnect when a failed login happens
Why do we need this ?
In the case of writing an Ansible role to:
We may need to use a test login call to see if our new password works or if its still the default
failed_when: false
on the task so our play doesn't fail if we get a failed loginWhere this fails
Currently the codebase doesn't mark the connection as disconnected when a login fails so subsequent attempts will assume we are logged in and provide a bad auth token
The fix
In
community/zabbix/plugins/httpapi/zabbix.py
we update thelogin()
method so that when the login is failed, the connection is marked as disconnected.Update zabbix_user module to notify on successful password changes
Why do we have to do this?
It would be nice if we could detect changing the current Zabbix API user's password and re-login the user instead of seeing session terminated errors on subsequent calls
The original intent was to do this all from inside the Zabbix HTTPAPI class but it turns out the update user request is actually two separate requests made by the zabbix_user module:
Zabbix_user module User::update_user() method
password_changed_for_user()
method of theZabbixApiRequest
classcommunity/zabbix/plugins/modules/zabbix_user.py
:Add the password_changed_for_user method to ZabbixApiRequest
community/zabbix/plugins/module_utils/api_request.py
:Add password_changed_for_user method to Zabbix Ansible/HTTPAPI
community/zabbix/plugins/httpapi/zabbix.py
If so, we login with the new credentials
JSON-RPC communication between module and connection
password_changed_for_user()
method, the marshaller for the json-rpc requests automatically adds the header data including the correct request idISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
See the integration test for a playbook on how to reproduce the issue: tests/integration/targets/test_zabbix_user/tasks/change_api_user_pass.yml