MSSQL check that will return query value as perf data

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.
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

MSSQL check that will return query value as perf data

Post by vAJ »

I'm in need of a check to run a query against a MSSQL DB and alert/chart the value returned.

Several checks out there are great at showing response times, SQL stats, etc. I've attempted to modify the check_mssql, but I'm not having much success.

Any ideas to help me get this knocked out?
Andrew J. - Do you even grok?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: MSSQL check that will return query value as perf data

Post by sreinhardt »

Have you taken a look at the mssql query wizard that is included with XI by default? I guess I'm assuming that this is for your XI system, correct me if I am wrong there.
http://exchange.nagios.org/directory/Ad ... rd/details
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

Yes, the XI wizard only charts/alerts the response time of the query. I'm looking to monitoring the integer value returned by the query. Response time in addition to that would be fine, similar to check_http where it shows time & size.
Andrew J. - Do you even grok?
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

mssql_query_check.JPG
So, maybe the Wizard changed with 2014 and I'm looking at something new here?

The query I need to run tells me how many records were written to given table in the last X minutes.

I want it to return a low value and warn if >15, critical >30. But I usually expect around 1-5.

The "expected result" field here in the wizard appears to want a higher expected value or it ignores it?

-Andrew
Andrew J. - Do you even grok?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: MSSQL check that will return query value as perf data

Post by sreinhardt »

Is it that the plugin is ignoring it, or the wizard is? Once you've gone through the wizard could you provide the command within the service definition that it is giving? I just want to be sure we are getting the same things.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

Charts
Charts
I've got the query running successfully with the MS SQL Query wizard, but as you can see, it's only charting the response time...
Andrew J. - Do you even grok?
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_mssql -H sqldbc1*********.com --username nagiossqluser --password '*************' --database DataCenters_Logs --port 1433 --query 'SELECT count\(\*\) 'PaymentProcessingErrors' FROM DataCenters_Logs.dbo.DataVaultErrorLog WITH \(NOLOCK\) WHERE ErrorTime \> DATEADD\(MI,-5,getdate\(\)\)' --result "1" --decode --warning 1 --critical 2 --querywarning 3 --querycritical 5 --result 0
Andrew J. - Do you even grok?
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

I can tell you that the wizard used double quotes instead of singles, also adds special chars in the spaces...

CCM won't run this as a test, but once it's committed, the engine runs it just fine.
Andrew J. - Do you even grok?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: MSSQL check that will return query value as perf data

Post by tmcdonald »

Can you go to the Advanced tab of the service view and see what perfdata is being returned? If you want to graph the actual SQL result it will need to be in the perfdata.
Former Nagios employee
vAJ
Posts: 456
Joined: Thu Nov 08, 2012 5:09 pm
Location: Austin, TX

Re: MSSQL check that will return query value as perf data

Post by vAJ »

Code: Select all

Performance Data:	query_duration=0.053464s;1;2;0;
Andrew J. - Do you even grok?
Locked