-
Type:
Problem report
-
Resolution: Unresolved
-
Priority:
Trivial
-
None
-
Affects Version/s: 7.0.25
-
Component/s: Agent2 plugin (G)
-
None
Steps to reproduce:
- Deploy Zabbix agent 2 with MSSQL plugin on both nodes of a 2-node Always On Availability Group cluster
- Configure template "MSSQL by Zabbix agent 2" on both nodes
- Collect data from mssql.last.backup.get on the secondary replica
Result:
On the secondary replica, the item returns only system databases (master, model, msdb). All AG-member databases are excluded.
Example output from secondary:
[
{"db_recovery_model":3,"dbname":"master","duration":1,"time_since_last_backup":38916,"type":"D"},
{"db_recovery_model":1,"dbname":"model","duration":1,"time_since_last_backup":38916,"type":"D"},
{"db_recovery_model":3,"dbname":"msdb","duration":1,"time_since_last_backup":38916,"type":"D"}
]
Expected:
Per the official plugin documentation (pkg.go.dev/golang.zabbix.com/plugin/mssql):
"Returns the last backup time for all databases. Returns databases that are participating in an Always On availability group and replica (primary or secondary) and are located on the server that the connection was established to."
AG-member databases should be returned on both primary and secondary replicas.
Root cause analysis: The embedded SQL query in last.backup.get.sql contains a WHERE exclusion subquery filtering on:
WHERE primary_replica != @@Servername OR primary_replica IS NULL
On the secondary replica, primary_replica always differs from @@Servername, so the condition is always TRUE for all AG databases — causing all of them to be excluded. Only non-AG databases (system DBs) survive the filter.
The logic is inverted with respect to the documented intent.
Suggested fix: Remove the AG exclusion subquery entirely from last.backup.get.sql, allowing data collection from both replicas unconditionally. Alert suppression for non-preferred replicas should be delegated to trigger logic (as the template already partially supports via context macros).
Alternatively, invert the condition to WHERE primary_replica = @@Servername to exclude only the databases whose primary is the current node.