[ZBX-20038] Zabbix-agent2 mysql plugin replication slave status monitoring is broken Created: 2021 Oct 01  Updated: 2024 Apr 10  Resolved: 2023 Oct 13

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent2 plugin (G)
Affects Version/s: None
Fix Version/s: 6.0.23rc1, 6.4.8rc1, 7.0.0alpha6, 7.0 (plan)

Type: Patch request Priority: Trivial
Reporter: Vlad Assignee: Eriks Sneiders
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Ubuntu 20.04.2 LTS
Zabbix-agent2: 5.0.16-1+focal
DB Template: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent2/template_db_mysql_agent2.yaml (05.06.2021)
MySQL: 5.7.32-35, 8.0.25-15
jq: jq-1.6


Attachments: File git_zabbix_mysql.replication.get_slave_status_fix.patch    
Team: Team INT
Sprint: Sprint 103 (Aug 2023), Sprint 104 (Sep 2023), Sprint 105 (Oct 2023)
Story Points: 1

 Description   

Summary
MySQL slave's replication status always shows status of the first slave channel in SHOW SLAVE STATUS query output (ignoring {#MASTER_HOST} parameter) due to an error in /src/go/plugins/mysql/handler_replication_status.go

Steps to reproduce:

  1. Set up zabbix_agent2 of a latest version (5.0.16-1+focal)
  2. Install a MySQL server (5.7 or 8.0)
  3. Set up 2 replication channels with master hosts: host1.mydomain.com, host2.my_domain.com
  4. Execute
    zabbix_get -s mysql-host.mydomain.com -p 10050 -k mysql.replication.get_slave_status["Main","","","","","","","host1.mydomain.com"] | jq '.["Channel_Name"]'.

    Return: "host1.mydomain.com" - that's correct

  1. Execute
    zabbix_get -s mysql-host.mydomain.com -p 10050 -k mysql.replication.get_slave_status["Main","","","","","","","host2.mydomain.com"] | jq '.["Channel_Name"]'.

    Return: "host1.mydomain.com" - that's WRONG data that belongs to host1.mydomain.com

Explanation:
The declaration of replicationSlaveStatusHandler() function doesn't have a 'params' array like databaseSizeHandler() does. Instead Master_Name parameter passed by zabbix_get is assigned to '_' (empty variable).
After the 'SHOW SLAVE STATUS' query gets executed it's result is parsed by rows2data() function which returns an array of objects with each item representing it's own replication channel's status. It is saved to 'data' variable.
In /src/go/plugins/mysql/handler_replication_status.go file, line 46 during conversion to JSON the value of 'data[0]' is taken which can only return status of the first slave channel status there is in 'data' array.

Patch:
The git patch file is attached to this issue. It fixes the issue and implements the check of Master_Name replication channel existence.



 Comments   
Comment by Eriks Sneiders [ 2023 Oct 02 ]

FIXED INĀ 

Comment by Martins Valkovskis [ 2023 Oct 09 ]

Updated documentation:

  • Zabbix agent 2 items: 6.0, 6.4, 7.0 ('mysql.replication.get_slave_status' updated)
  • Upgrade notes: 6.0.23, 6.4.8
Generated at Sun Jun 08 08:03:44 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.