Need help on MSSQL query in Nagios

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
manojkonda
Posts: 10
Joined: Tue Aug 09, 2016 12:04 pm

Need help on MSSQL query in Nagios

Post 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 !
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Need help on MSSQL query in Nagios

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
manojkonda
Posts: 10
Joined: Tue Aug 09, 2016 12:04 pm

Re: Need help on MSSQL query in Nagios

Post 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 !
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Need help on MSSQL query in Nagios

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked