MSSQL Plugin - How to show the query results

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
infrati.fornecedores
Posts: 17
Joined: Tue Jan 08, 2013 6:49 pm

MSSQL Plugin - How to show the query results

Post 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]
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: MSSQL Plugin - How to show the query results

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
infrati.fornecedores
Posts: 17
Joined: Tue Jan 08, 2013 6:49 pm

Re: MSSQL Plugin - How to show the query results

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

Re: MSSQL Plugin - How to show the query results

Post 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'
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
nscott
Posts: 1040
Joined: Wed May 11, 2011 8:54 am

Re: MSSQL Plugin - How to show the query results

Post 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
Nicholas Scott
Former Nagios employee
infrati.fornecedores
Posts: 17
Joined: Tue Jan 08, 2013 6:49 pm

Re: MSSQL Plugin - How to show the query results

Post by infrati.fornecedores »

Hello Nicolas,

there any provision for this update MSSQL plugin?

thanks

Romário Faria
Infrastructure Analyst
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: MSSQL Plugin - How to show the query results

Post 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'
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
infrati.fornecedores
Posts: 17
Joined: Tue Jan 08, 2013 6:49 pm

Re: MSSQL Plugin - How to show the query results

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

Re: MSSQL Plugin - How to show the query results

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
infrati.fornecedores
Posts: 17
Joined: Tue Jan 08, 2013 6:49 pm

Re: MSSQL Plugin - How to show the query results

Post 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?
Locked