Page 2 of 2

Re: Check MSSQL run custom query

Posted: Thu Jan 16, 2020 8:24 am
by jkinning
Still the same. Good call out, been trying to get this work so long my eyes are becoming crossed.

Code: Select all

check_mssql -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -Q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked \> 0 and p2.spid = p1.blocked'
UNKNOWN - Could not interpret server response.

Code: Select all

check_mssql -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -Q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked > 0 and p2.spid = p1.blocked'
UNKNOWN - Could not interpret server response.

Re: Check MSSQL run custom query

Posted: Thu Jan 16, 2020 8:33 am
by scottwilkerson
Also, looks like you are passing -Q instead of -q

Try

Code: Select all

check_mssql -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked > 0 and p2.spid = p1.blocked'

Re: Check MSSQL run custom query

Posted: Thu Jan 16, 2020 8:38 am
by jkinning
check_mssql -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked > 0 and p2.spid = p1.blocked'
Unknown option: q
UNKNOWN - online or query is required.
Is there a different plugin you are using?

check_mssql --help
Usage: check_mssql.pl -H <host> -U <user> -P <password> [-p <port>] [-t <timeout>] [-D <dbname>]
[-o] [-Q <sqlquery>] [-S <string> | [-w <warn_range> [-c <crit_range>]]
Options:
<host> = The address of the host running SQLServer
<user> = The user to log in as, if a domain is specified the name has to be embraced by ' signs
<password> = The user's password
<port> = The port on which the SQL Server is listening, default 1433
<timeout> = Timeout in seconds for plugin execution, default 10
<dbname> = The name of the database to use
-o or --online = Check if database is online (databasepropertyex('<dbname>', 'STATUS') equals ONLINE).
<sqlquery> = The SQL query to run on the server, the default is to check the number of logged in users
<string> = A string to look for in the result set
<warn_range> = The warning limit for the result of the query, default 50
<crit_range> = The critical limit for the result of the query, default 100
Warning and critical threshold support ranges on the form <start>:<end> which
defines the range that should _not_ trigger an alarm. A single numeric threshold
is equal to a range 0 to the thresh. IE -w 50 is equal to -w 0:50 which means
trigger alarm if returned value is outside range, IE larger then 50
Instead of the short argument names shown above the following can be used:
-H --hostname
-U --user
-P --password
-p --port
-t --timeout
-D --database
-o --online
-Q --sqlquery
-S --string
-w --warning
-c --critical

Usage examples:

To check that Northwind database is ONLINE:
check_mssql.sh -H localhost -U name -P pass -D Northwind -o

Select number of messages from Northwind.messages, warn if > 10, crit if > 15
check_mssql.sh -H localhost -U name -P pass -D Northwind -Q "select count(id) from messages" -w 10 -c 15

Re: Check MSSQL run custom query

Posted: Thu Jan 16, 2020 8:51 am
by scottwilkerson
I'm sorry, I just realized you were using a different plugin that I was....

You may have to add the database to your current command

Code: Select all

-D master
so

Code: Select all

check_mssql -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -D master -Q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked > 0 and p2.spid = p1.blocked'
If you want to try the plugin I have confirmed working you can try the attached, I successfully ran with:

Code: Select all

/usr/local/nagios/libexec/check_mssql -H 192.168.223.12 --username '<username>' --password '<password>' --database master -p 4000 -q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked > 0 and p2.spid = p1.blocked'

Re: Check MSSQL run custom query

Posted: Fri Jan 17, 2020 1:30 pm
by jkinning
WooHoo! I used your plugin and syntax and things look like they are working.

Code: Select all

check_mssql_nagios -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -d master -Q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked \> 0 and p2.spid = p1.blocked'
OK: Connect time=0.010067 seconds.|query_duration=0.010067s;;
I have some other custom queries I am going to try and run through but this looks good.

Greatly appreciate everyone's assistance!!

Re: Check MSSQL run custom query

Posted: Fri Jan 17, 2020 1:54 pm
by scottwilkerson
jkinning wrote:WooHoo! I used your plugin and syntax and things look like they are working.

Code: Select all

check_mssql_nagios -H <server> -U '<domain\username>' -P '<password>' -p 4000 -t 60 -d master -Q 'select * from sysprocesses p1, sysprocesses p2 where p1.blocked \> 0 and p2.spid = p1.blocked'
OK: Connect time=0.010067 seconds.|query_duration=0.010067s;;
I have some other custom queries I am going to try and run through but this looks good.

Greatly appreciate everyone's assistance!!
Great!