Page 2 of 2
Re: check_mssql installation problem
Posted: Tue Dec 29, 2015 2:17 pm
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...
Re: check_mssql installation problem
Posted: Tue Dec 29, 2015 3:19 pm
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
Re: check_mssql installation problem
Posted: Tue Dec 29, 2015 7:52 pm
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

Re: check_mssql installation problem
Posted: Wed Dec 30, 2015 12:28 am
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
Re: check_mssql installation problem
Posted: Wed Dec 30, 2015 10:55 am
by rkennedy
Can you check the permissions of /tmp/query.sql and post the output of the command below back to us?
Re: check_mssql installation problem
Posted: Wed Dec 30, 2015 8:58 pm
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

Re: check_mssql installation problem
Posted: Mon Jan 04, 2016 11:12 am
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.
Re: check_mssql installation problem
Posted: Mon Jan 04, 2016 6:25 pm
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.
Re: check_mssql installation problem
Posted: Tue Jan 05, 2016 11:35 am
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?