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.
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 »

Looks like the plugin itself does not give performance data for the actual query result, and this makes sense given that many SQL queries will return a whole row which doesn't fit well into perfdata. Making the change will require an edit to the plugin. It's a relatively short PHP plugin so I can probably tackle this here, though actually getting that perfdata in the graph is another story.

Can you run the command manually from the CLI and post the output? I want to see if there is anything in your output we can use in the perfdata.
Former Nagios employee
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

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

Post by lmiltchev »

What is the plugin's version that you are using?

Code: Select all

./check_mssql -V
Be sure to check out our Knowledgebase for helpful articles and solutions!
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 »

Here's output from the CLI:

Code: Select all

PHP Notice:  Undefined variable: exit_code in /usr/local/nagios/libexec/check_mssql on line 315
OK: Query duration=0.104882 seconds.|query_duration=0.104882s;1;2;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 »

lmiltchev wrote:What is the plugin's version that you are using?

Code: Select all

./check_mssql -V
0.6.8
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 include the actual command you are running in addition to the output it provides? That notice about the undefined variable is a bit odd. But it does not look like your query result is included either in the output or in the performance data. I can take a look at it but not being a developer there is only so much I can do.
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 »

Command is on page one of this thread. Is that not what you need?
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 »

I just wanted to make sure that the output you posted above is indeed the result of that command, so it helps to see them together on one page. But yes, that is what I was looking for. Let me poke around the code a bit and see what I can find. I might ask you to test out a few changes to make sure they are working properly for you.

ADD: So it looks like the $query_result holds the result of the SQL query, so if you know it will be a consistent format (always a decimal, always a lower-case string, etc.) you can modify the perfdata like so (line 347):

Code: Select all

$perfdata = "query_duration={$query_duration}s;{$warning};{$critical};0;query_result={$query_result};";
Bear in mind that this will likely screw up any existing graphing you have for that service (since it adds new perfdata), so I would create a copy of check_mssql specifically for the checks that need this result.

Let me know how this works out.
Former Nagios employee
reinaldo.gomes
Posts: 59
Joined: Wed Apr 02, 2014 9:29 am

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

Post by reinaldo.gomes »

Speaking of check_mssql, is there a reason for blocking underlines at the username, like in "user_name" ?
I was getting an annyoing "invalid characters in the username" until I edited the code and added a simple "\_" to the username's regex.
Will there be any downside to it?
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 »

I can't say for sure if there would be any downsides, but underscores aren't particularly special in SQL queries or bash so I don't see why it would be a concern.
Former Nagios employee
Locked