check_mssql installation problem

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
idropedro
Posts: 10
Joined: Wed Dec 23, 2015 8:05 pm

Re: check_mssql installation problem

Post by idropedro »

tgriep wrote:The plugin for you query for some reason isn't returning any data.
Can you post the query you are running so we can review it?
Can you check the log file on the MSSQL server for any errors and post them here?
i have no errors..

this is what i have in mysql.sql file


Declare @date1 datetime
Declare @date2 datetime

Select @date1 = GETDATE();
Select @date2 = (Select max(dateinserted) from mydb..mytable with (nolock) where portal='xxxxx')

IF (select DATEDIFF(hh, @date2, @date1)) > 1 BEGIN
PRINT DATEDIFF(hh, @date2, @date1)
PRINT '0'
END
ELSE
BEGIN
PRINT '1'
END



when i execute the query or the sp on management studio, works fine..
the check_mssql connection works but it doesnt have any result...
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: check_mssql installation problem

Post by lmiltchev »

What happens if you use the "-s" flag in your check (instead of "-q")?

For example:

Code: Select all

/usr/local/nagios/libexec/check_mssql -H x.x.x.x --username <username> --password "<password>" --database <database> --instance <instance> -s /path/to/your/file.sql
Be sure to check out our Knowledgebase for helpful articles and solutions!
idropedro
Posts: 10
Joined: Wed Dec 23, 2015 8:05 pm

Re: check_mssql installation problem

Post by idropedro »

lmiltchev wrote:What happens if you use the "-s" flag in your check (instead of "-q")?

For example:

Code: Select all

/usr/local/nagios/libexec/check_mssql -H x.x.x.x --username <username> --password "<password>" --database <database> --instance <instance> -s /path/to/your/file.sql
it returns this.

Code: Select all

-s '/tmp/execsql.sql'
OK: Query duration=0.049058 seconds.|query_duration=0.049058s;;
the query returns 1 or 0... very simple.....
someone already have to use this plugin...and get any results :D
idropedro
Posts: 10
Joined: Wed Dec 23, 2015 8:05 pm

Re: check_mssql installation problem

Post by idropedro »

its seems that the query is executing .. because of the execution time.

without query string.

idleh@idleh-VBox:/tmp$ sudo /usr/local/nagios/libexec/check_mssql -H x.x.x.x --port xxxx--username sa --password mypass
OK: Connect time=0.148633 seconds.|query_duration=0.148633s;;

without --result

idleh@idleh-VBox:/tmp$ sudo /usr/local/nagios/libexec/check_mssql -H x.x.x.x --port xxxx --username sa --password mypass --database XXXXXX --query /tmp/query.sql
OK: Query duration=0.716242 seconds.|query_duration=0.716242s;;

with --result 0

idleh@idleh-VBox:/tmp$ sudo /usr/local/nagios/libexec/check_mssql -H x.x.x.x --port xxxx --username sa --password mypass --database XXXXXX --query /tmp/query.sql --result 0
PHP Warning: mssql_num_rows() expects parameter 1 to be resource, boolean given in /usr/local/nagios/libexec/check_mssql on line 432
PHP Notice: Undefined variable: query_result in /usr/local/nagios/libexec/check_mssql on line 467
PHP Notice: Undefined variable: query_result in /usr/local/nagios/libexec/check_mssql on line 471
OK: CRITICAL: Query expected "0" but got "".|query_duration=0.618313s;;

with --result 1

idleh@idleh-VBox:/tmp$ sudo /usr/local/nagios/libexec/check_mssql -H x.x.x.x --port xxxx--username sa --password mypass --database xxxxxx --query /tmp/query.sql --result 1
PHP Warning: mssql_num_rows() expects parameter 1 to be resource, boolean given in /usr/local/nagios/libexec/check_mssql on line 432
PHP Notice: Undefined variable: query_result in /usr/local/nagios/libexec/check_mssql on line 467
PHP Notice: Undefined variable: query_result in /usr/local/nagios/libexec/check_mssql on line 471
OK: CRITICAL: Query expected "1" but got "".|query_duration=0.723673s;;

and the query.sql

has this inside.

Declare @date1 datetime
Declare @date2 datetime

Select @date1 = GETDATE();
Select @date2 = (Select max(dateinserted) from XXXXXX..XXXXXX with (nolock) where XXXXXX='XXXXXX')

IF (select DATEDIFF(hh, @date2, @date1)) > 1 BEGIN
--PRINT DATEDIFF(hh, @date2, @date1)
PRINT 1
END
ELSE
BEGIN
PRINT 0
--PRINT CONVERT(varchar(11), DATEDIFF(minute, @date1, @date2) / 60) + '1' -- + ' Hours'
END
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_mssql installation problem

Post by rkennedy »

Can you check the permissions of /tmp/query.sql and post the output of the command below back to us?

Code: Select all

ls -l /tmp/query.sql
Former Nagios Employee
idropedro
Posts: 10
Joined: Wed Dec 23, 2015 8:05 pm

Re: check_mssql installation problem

Post by idropedro »

root@idleh-VBox:/home/idleh# ls -l /nagios-scripts/query.sql
-rwxr-xr-x 1 root root 429 Dec 30 18:38 /nagios-scripts/query.sql

now i get it working just fine.

i am trying to add as a service on a host.. but i dont know how to add --hostame --username and etc etc to the check_command string.


define service {
use generic-service
host_name myhostname.mymy
service_description MSSQL
check_command check_mssql -H xxx.xxx.xxx.xxx -U myuser -P mypass <------ if i put it here nagios won´t start...
notifications_enabled 0

}

thanks :D
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_mssql installation problem

Post by rkennedy »

Did you fix the permissions of query.sql to get it working?

Does your password contain any special characters? This may be halting Nagios. If so, try putting your password in double quotes "" to see if that works.
Former Nagios Employee
idropedro
Posts: 10
Joined: Wed Dec 23, 2015 8:05 pm

Re: check_mssql installation problem

Post by idropedro »

rkennedy wrote:Did you fix the permissions of query.sql to get it working?

Does your password contain any special characters? This may be halting Nagios. If so, try putting your password in double quotes "" to see if that works.
i do fix it.. and it´s working just fine.

i was using 0 when OK and 1 when KO
now.. i am trying to get more than 0K or 0 and sometext
i mean.. i need to get the OK from the first part of the result...
like a simple % after the 1 or the 0.

and example.. when i run my query, i also include a note right after the result. " 0 sometext" and when the result is 0 % means OK without critical alerts.
just the result and the lastthingupdated according to my query.

thanksss

g.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_mssql installation problem

Post by rkennedy »

What is the output when you run the check over the CLI? Just trying to get a grasp on what you'd like to see with the check_mssql.

I'm confused about what's working - did you need help changing your check_command or is it working fine now with your password?
Former Nagios Employee
Locked