Page 1 of 1

Need help on MSSQL query in Nagios

Posted: Tue Feb 05, 2019 7:38 am
by manojkonda
Hi Team,

We are planning to monitor Database availability using below query via Nagios 

[root@Nagios ~]# /usr/local/nagios/libexec/check_mssql -H remotesqlhost --username XXXX --password XXXX --database XXXX --port 2056 --query "IF (master.sys.fn_hadr_is_primary_replica ('TestDB') = 1 OR master.sys.fn_hadr_is_primary_replica ('TestDB') IS NULL) BEGIN select top 1 1 from cloudcms.sys.sysobjects END"
PHP Notice: Undefined variable: column_name in /usr/local/nagios/libexec/nagios/libexec/check_mssql on line 487
PHP Notice: Undefined variable: query_result in /usr/local/nagios/libexec/nagios/libexec/check_mssql on line 487
OK: Query duration=0.001599 seconds.|query_duration=0.001599s;; ''=;
You have new mail in /var/spool/mail/root
[root@Nagios ~]#

But somehow it is not getting into IF statement in query and producing always OK message in output even for wrong query execution.

Kindly advice how to monitor this query ?

Thank You !

Re: Need help on MSSQL query in Nagios

Posted: Tue Feb 05, 2019 4:16 pm
by npolovenko
Hello, @manojkonda. Can you manually run the same query against the database and show me the output? I would like to see what it looks like when IF statement is actually included.

Re: Need help on MSSQL query in Nagios

Posted: Wed Feb 06, 2019 7:22 am
by manojkonda
npolovenko wrote:Hello, @manojkonda. Can you manually run the same query against the database and show me the output? I would like to see what it looks like when IF statement is actually included.
Hi npolovenko,

Please find the output below,

query output is 1.
1 means Query execution OK and able to connect database.

select top 1 'Connected' from cloudcms.sys.sysobjects
output is Connected.

and there is no definite output when it cannot establish connection to the database, the output can vary based on the issue.

Thank You !

Re: Need help on MSSQL query in Nagios

Posted: Wed Feb 06, 2019 4:18 pm
by npolovenko
@manojkonda, Do other types of queries work as expected with the check_mssql plugin? Please download and try using the latest version of the plugin from here:
https://gist.github.com/radleta/5f2476f ... 392883becd