Page 1 of 1

check_mssql: Error CRITICAL: Could not execute the Query

Posted: Fri May 11, 2018 11:08 am
by paulconca
Hi

I am doing some test as we may be moving from our current monitoring tool, to Nagios XI

The query is as follows: (works fine on our current monitoring tool and on the database)


select *****_*******.epr_id, *****_*******.app, *****_*******.Entity_ID, *****_*******.app_env, *****_*******_connect_expiry, *****_*******_connect_cn from *****_*******, *****_*******_connection where (*****_*******.tracking_id = *****_*******_.tracking_id and *****_*******.app_env = 'itg' ) and (*****_*******_connection.Validation_expiry between cast(getdate()as date) and dateadd(day,7,cast(getdate()as date)))

A simple query works so it is not a connection or access issue. :!:

Variations I have tried (Single quotes, double quotes, etc)

./check_mssql -H '**********.net' -U '****' -P *******' -I '***' -d 'master' -q select *****_*******.epr_id, *****_*******.app, *****_*******.Entity_ID, *****_*******.app_env, *****_*******_connect_expiry, *****_*******_connect_cn from *****_*******, *****_*******_connection where (*****_*******.tracking_id = *****_*******_.tracking_id and *****_*******.app_env = 'itg' ) and (*****_*******_connection.Validation_expiry between cast(getdate()as date) and dateadd(day,7,cast(getdate()as date)))

-bash: syntax error near unexpected token `('

"Eror CRITICAL: Could not execute the Query"for all the below
./check_mssql -H '**********.net' -U '****' -P *******' -I '***' -d 'master' -q "select *****_*******.epr_id, *****_*******.app_techlead, *****_*******.Entity_ID, *****_*******.app_env, *****_*******_expiry, *****_*******_connection.Validation_cn from *****_*******, *****_*******_connection where (*****_*******.tracking_id = *****_*******.tracking_id and *****_*******.app_env = 'itg' ) and (*****_*******_connect_expiry between cast(getdate()as date) and dateadd(day,7,cast(getdate()as date)))”

'select ‘*****_*******.epr_id, *****_*******.app_techlead, *****_*******.Entity_ID, *****_*******.app_env, *****_*******_connect_expiry, *****_*******_connect_cn from *****_*******, *****_*******_connection where (*****_*******.tracking_id = *****_*******_connecttrack_id and *****_*******.app_env = 'itg' ) and (*****_*******_connect.Valid_expiry between cast(getdate()as date) and dateadd(day,7,cast(getdate()as date)))’


select “’*****_*******.epr_id’, ‘*****_*******.app_techlead’, ‘*****_*******.Entity_ID’, ‘*****_*******.app_env’, ‘*****_*******_connect.Valid_expiry’, ‘*****_*******_connect._cn’ from ‘*****_*******’, ‘*****_*******_connection where’ (‘*****_*******.tracking_id’ = ‘*****_*******_connect.track_id’ and ‘*****_*******.app_env’ = 'itg' ) and (‘*****_*******_connect.Valid_expiry’ between cast(getdate()as date) and dateadd(day,7,cast(getdate()as date)))”

Any assistance is much appreciated

Re: check_mssql: Error CRITICAL: Could not execute the Query

Posted: Fri May 11, 2018 11:47 am
by mcapra
Are there any SPs, views, or triggers included in this query's execution?

You could also try this Perl based plugin and see if it produces the same issues:
https://github.com/nagios-plugins/nagio ... k_mssql.pl

Re: check_mssql: Error CRITICAL: Could not execute the Query

Posted: Fri May 11, 2018 3:36 pm
by npolovenko
Thanks, @mcapra!
@paulconca, Let us know if the check_mssql.pl plugin works for you.

Re: check_mssql: Error CRITICAL: Could not execute the Query

Posted: Mon May 14, 2018 8:30 am
by paulconca
That plugin does not seem to work at all, for me

/check_mssql.pl -H ******* -U '**********' -P '***************' -I '*********' -d '*********' -q "select getdate()"
-bash: ./check_mssql.pl: @PERL@: bad interpreter: No such file or directory

Tried this, but still not working
6 # Requires freetds and DBD::Sybase
7 # http://www.freetds.org
8 # http://www.mbay.net/~mpeppler/


Any ideas why the orginal ./check_mssql works for some queries and not others?

Thank you

Re: check_mssql: Error CRITICAL: Could not execute the Query

Posted: Mon May 14, 2018 8:40 am
by mcapra
paulconca wrote:Any ideas why the orginal ./check_mssql works for some queries and not others?
Yes. Certain ODBC connection libs, specifically the ones used in the check_mssql PHP script, don't handle the following objects very gracefully in my experience:
mcapra wrote:Are there any SPs, views, or triggers included in this query's execution?
Understanding the underlying objects involved in the query would be useful in reproducing any "weirdness" with this plugin. Have you tried fiddling with the usage of GETDATE()? Either hard-coding the result or removing the call?

Re: check_mssql: Error CRITICAL: Could not execute the Query

Posted: Tue May 15, 2018 8:19 am
by scottwilkerson
paulconca wrote:That plugin does not seem to work at all, for me

/check_mssql.pl -H ******* -U '**********' -P '***************' -I '*********' -d '*********' -q "select getdate()"
-bash: ./check_mssql.pl: @PERL@: bad interpreter: No such file or directory
This error is because you cannot use the plugin without compiling them, it still has the @PERL@ at the top because you have not run configure on the nagios plugin package

https://support.nagios.com/kb/article.php?id=569