Check MSSQL run custom query

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
jkinning
Posts: 748
Joined: Wed Oct 09, 2013 2:54 pm

Re: Check MSSQL run custom query

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Check MSSQL run custom query

Post 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'
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jkinning
Posts: 748
Joined: Wed Oct 09, 2013 2:54 pm

Re: Check MSSQL run custom query

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Check MSSQL run custom query

Post 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'
Attachments
check_mssql.zip
(6.77 KiB) Downloaded 171 times
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jkinning
Posts: 748
Joined: Wed Oct 09, 2013 2:54 pm

Re: Check MSSQL run custom query

Post 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!!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Check MSSQL run custom query

Post 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!
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked