[ZBX-19917] Database monitor items failing while the same working fine with ODBC usage Created: 2021 Sep 06  Updated: 2024 Apr 10  Resolved: 2022 Sep 23

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Proxy (P), Server (S)
Affects Version/s: 4.0.33, 5.0.15, 5.4.4
Fix Version/s: 6.4 (plan)

Type: Problem report Priority: Major
Reporter: Igor Gorbach (Inactive) Assignee: Vladislavs Sokurenko
Resolution: Workaround proposed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Zabbix 4.0.5.4
Microsoft SQL Server 2012


Attachments: PNG File image-2021-09-06-16-02-22-881.png     PNG File image.png    
Issue Links:
Causes
Team: Team A
Sprint: Sprint 92 (Sep 2022)
Story Points: 1

 Description   

Steps to reproduce:

  1. Create a basic MSSQL instance
  2. Configure ODBC connection
  3. Connect to MSSQL Instance with isql
  4. Run the query
SQL> DECLARE @strsql NVARCHAR(max) SET @strsql = 'if exists (select name from sys.databases where name=''dba_ops'') begin if exists (select 1 from dba_ops.sys.tables where name = ''dbm_rebuild_reorg_history'') begin if exists (select top 1 reindex_type from dba_ops.dbo.dbm_rebuild_reorg_history where entry_timestamp >= DATEADD(day, -3, GetDate())) begin select 0 as condition end else begin if exists (select 1 from dba_ops.dbo.dbm_gather_frag_details where scan_date >= DATEADD(day, -3, GetDate()) and fragmentation > 20 and page_count >10) begin Select 1 as condition end else Begin Select 0 as condition end end end else begin Select 0 as condition end end else begin Select 0 as condition end' BEGIN TRY IF (SELECT SERVERPROPERTY('IsHadrEnabled')) = 1 BEGIN IF NOT EXISTS ( SELECT 1 FROM sys.availability_groups_cluster AS AGC LEFT JOIN sys.dm_hadr_availability_replica_cluster_states AS RCS ON RCS.group_id = AGC.group_id LEFT JOIN sys.dm_hadr_availability_replica_states AS ARS ON ARS.replica_id = RCS.replica_id LEFT JOIN sys.availability_group_listeners AS AGL ON AGL.group_id = ARS.group_id WHERE RCS.replica_server_name = @@SERVERNAME AND ARS.role_desc = 'SECONDARY') BEGIN EXEC sp_executesql @strsql END ELSE BEGIN Select 0 as condition END END ELSE BEGIN EXEC sp_executesql @strsql END END TRY BEGIN CATCH Select 1 as condition END CATCH;
+------------+
| condition  |
+------------+
| 0          |
+------------+

All working fine

  5. Create an item with database monitor type
  6. Try to test it or wait for new data in Zabbix before 5.0
Result
Empty result

Expected

Query working fine



 Comments   
Comment by Vladislavs Sokurenko [ 2022 Sep 09 ]

Could not reproduce the issue, tested with:

select 0; 

It returned 0.

What was the expected behaviour of query mentioned in description, is it simply empty string ?

Comment by Vladislavs Sokurenko [ 2022 Sep 13 ]

Workaround is to SET NOCOUNT so that count of affected rows is not returned, but can also be fixed in Zabbix to skip automatically:

SET NOCOUNT ON DECLARE @strsql NVARCHAR(max) SET @strsql = 'if exists (select name from sys.databases where name=''dba_ops'') begin if exists (select 1 from dba_ops.sys.tables where name = ''dbm_rebuild_reorg_history'') begin if exists (select top 1 reindex_type from dba_ops.dbo.dbm_rebuild_reorg_history where entry_timestamp >= DATEADD(day, -3, GetDate())) begin select 0 as condition end else begin if exists (select 1 from dba_ops.dbo.dbm_gather_frag_details where scan_date >= DATEADD(day, -3, GetDate()) and fragmentation > 20 and page_count >10) begin Select 1 as condition end else Begin Select 0 as condition end end end else begin Select 0 as condition end end else begin Select 0 as condition end' BEGIN TRY IF (SELECT SERVERPROPERTY('IsHadrEnabled')) = 1 BEGIN IF NOT EXISTS ( SELECT 1 FROM sys.availability_groups_cluster AS AGC LEFT JOIN sys.dm_hadr_availability_replica_cluster_states AS RCS ON RCS.group_id = AGC.group_id LEFT JOIN sys.dm_hadr_availability_replica_states AS ARS ON ARS.replica_id = RCS.replica_id LEFT JOIN sys.availability_group_listeners AS AGL ON AGL.group_id = ARS.group_id WHERE RCS.replica_server_name = @@SERVERNAME AND ARS.role_desc = 'SECONDARY') BEGIN EXEC sp_executesql @strsql END ELSE BEGIN Select 0 as condition END END ELSE BEGIN EXEC sp_executesql @strsql END END TRY BEGIN CATCH Select 1 as condition END CATCH; 

wiper: Also worked normally with ODBC driver from Microsoft.

Comment by Alex Kalimulin [ 2022 Sep 20 ]

This looks like a problem of FreeTDS, because this behavior is not observed in Microsoft ODBC driver. A workaround by prepending 'SET NOCOUNT ON' as suggested here can be used in such situations.

Comment by Vladislavs Sokurenko [ 2022 Sep 21 ]

Workaround is proposed, issue can be closed.

Comment by Marina Generalova [ 2022 Sep 23 ]

The workaround has been documented as a Known issue in 4.0, 5.0, 6.0, 6.2, 6.4.

Generated at Thu Sep 04 23:03:47 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.