Page 1 of 2

MSSQL Plugin - How to show the query results

Posted: Tue Jan 22, 2013 1:03 pm
by infrati.fornecedores
Hello there,

We created a rule to check a table result from MSSQL Server 2008 R2 but the command only show the follow result:
OK: Query duration=0.352565 seconds.|query_duration=0.352565s;2;5;0;

Running the query direct from MSSQL Server we see the following result:

Query: select COUNT(*) from tableXPTO
Result: 100

Why the check_mssql plugin doesn't show the result like that? It shows only the time duration of the query.

I'm looking forward to your feedback.

Many Thanks

[email protected]

Re: MSSQL Plugin - How to show the query results

Posted: Tue Jan 22, 2013 2:20 pm
by lmiltchev
Can you show us the exact command that you are running from the command line? You've shown us the output of the command, but not the command itself. Hide the sensitive data.

Re: MSSQL Plugin - How to show the query results

Posted: Wed Jan 23, 2013 12:04 pm
by infrati.fornecedores
The exact command is:

check_xi_mssql_query!-H myIP --username myuser --password 'myPWD' --database myDB --port 1433 --query 'select COUNT(*) from LogImpExp where LogImpExp.DataRec >= dateadd(MI, -10, GETDATE())'--result '>0' --warning 0 --critical 0

So, I´ll tell what I want to do... I would like to check if the result is greater than 0. If the result is greater than 0 it´s ok, but if the result of the query is 0 is a critical issue.

Thanks

Re: MSSQL Plugin - How to show the query results

Posted: Wed Jan 23, 2013 5:55 pm
by scottwilkerson
I believe for the results you want you should make the command

Code: Select all

check_xi_mssql_query!-H myIP --username myuser --password 'myPWD' --database myDB --port 1433 --query 'select COUNT(*) from LogImpExp where LogImpExp.DataRec >= dateadd(MI, -10, GETDATE())' --result '0'

Re: MSSQL Plugin - How to show the query results

Posted: Wed Jan 23, 2013 6:03 pm
by nscott
Romario,

This functionality does not currently exist in the plugin. However, I was just looking at the code and it seems like it would be a valuable addition to the wizard, I'll send you something tomorrow with an updated wizard.

/Nick

Re: MSSQL Plugin - How to show the query results

Posted: Fri Jan 25, 2013 12:27 pm
by infrati.fornecedores
Hello Nicolas,

there any provision for this update MSSQL plugin?

thanks

Romário Faria
Infrastructure Analyst

Re: MSSQL Plugin - How to show the query results

Posted: Sun Jan 27, 2013 11:00 pm
by scottwilkerson
@infrati.fornecedores - did you try this?
scottwilkerson wrote:I believe for the results you want you should make the command

Code: Select all

check_xi_mssql_query!-H myIP --username myuser --password 'myPWD' --database myDB --port 1433 --query 'select COUNT(*) from LogImpExp where LogImpExp.DataRec >= dateadd(MI, -10, GETDATE())' --result '0'

Re: MSSQL Plugin - How to show the query results

Posted: Fri Feb 01, 2013 5:19 am
by infrati.fornecedores
Hi Nicolas,

This query show us the result of Warning or Error by a fixed number as for example, 100.

But the monitor way that we must implement works through a dynamic numbers, so 100 can be 10, 108, 209, 1000100 and etc.

Is there any possibility that check_xi_mssql_query! just show us the result (stdout) from the query? then through shell script we can create variables to make IF ELSE and etc...

I appreciate your feedback as soon as possible.

Re: MSSQL Plugin - How to show the query results

Posted: Tue Feb 05, 2013 11:49 am
by scottwilkerson
the plugin /usr/local/nagios/libexec/check_mssql is just a php script you could modify.

I believe the changes you would need to make are around line 295-297

Re: MSSQL Plugin - How to show the query results

Posted: Tue Feb 05, 2013 4:59 pm
by infrati.fornecedores
In which variable the stdout must be in that case?

// Attempt to execute the query/stored procedure
$time_start = microtime(true);
if (!$query_data = @mssql_query("$query")) {
$exit_code = 2;
$output_msg = "CRITICAL: Could not execute the $querytype.\n";
display_output($exit_code, $output_msg);
} else {
$time_end = microtime(true);
$query_duration = round(($time_end - $time_start), 6);
$output_msg = "Query duration=$query_duration seconds.";

We suppose that must be $output_msg, so it must show us the result from the query?

For example, if the query result is "XPTO" then the result from $output_msg must be "XPTO".

Is there any possibility to send us this script set up like this?