check_mssql stopped working
Posted: Mon Jun 06, 2016 10:51 am
I had several check_mssql services that have since two upgrades ago stopped working and I need to get them working again. I'm not a SQL guy by any stretch but the SQL script still runs on the SQL server correctly and no longer does on the NagiosXI server. The service would run a SQL query and would return with a value. If the value exceeded the warning or critical numbers, it would warn or alert, otherwise it would return OK. Now the check fails with OUTPUT: CRITICAL: Could not execute the query.
I didn't write the SQL nor the original service check I just know that these worked for two years and now don't so the burden now lies on me to get it working again. I am not able to change the SQL query but I can make whatever changes in Nagios to get it to work.
Here's the original SQL query that would return the number of minutes UTC between current and last entry in the table.
This SQL was then URL encoded so it would parse correctly through NagiosXI plugin and looks like:
The service was then defined :
A cleaner and abbreviated service definition so that it's easier to read without the URL encoding breaking the eyeballs
I didn't write the SQL nor the original service check I just know that these worked for two years and now don't so the burden now lies on me to get it working again. I am not able to change the SQL query but I can make whatever changes in Nagios to get it to work.
Here's the original SQL query that would return the number of minutes UTC between current and last entry in the table.
Code: Select all
DECLARE @min datetime
SELECT @min = fielddate FROM [CUSTOMER1DB1].[dbo].[TABLE1]
where TABLE1_id = (SELECT max(TABLE1_id)
FROM [CUSTOMER1DB1].[dbo].[TABLE1]
where app_id like '<P%')
select DATEDIFF (ss,@min, GETUTCDATE())Code: Select all
DECLARE+%40min+datetime%0D%0ASELECT+%40min+%3D+fielddate+FROM+%5BCUSTOMER1DB1%5D.%5Bdbo%5D.%5BTABLE1%5D++%0D%0Awhere+TABLE1_id+%3D+%28SELECT+max%28TABLE1_id%29++%0D%0AFROM+%5BCUSTOMER1DB1%5D.%5Bdbo%5D.%5BTABLE1%5D++%0D%0Awhere+app_id+like+%27%3CP%25%27%29%0D%0Aselect+DATEDIFF+%28ss%2C%40min%2C+GETUTCDATE%28%29%29Code: Select all
-H X.X.X.X --username "XXX" --password "XXX" --database master --instance XXXX --query "DECLARE+%40min+datetime%0D%0ASELECT+%40min+%3D+fielddate+FROM+%5BCUSTOMER1DB1%5D.%5Bdbo%5D.%5BTABLE1%5D++%0D%0Awhere+TABLE1_id+%3D+%28SELECT+max%28TABLE1_id%29++%0D%0AFROM+%5BCUSTOMER1DB1%5D.%5Bdbo%5D.%5BTABLE1%5D++%0D%0Awhere+app_id+like+%27%3CP%25%27%29%0D%0Aselect+DATEDIFF+%28ss%2C%40min%2C+GETUTCDATE%28%29%29" --result "" --decode --warning 60 --critical 90 --querywarning 45000 --querycritical 86400Code: Select all
-H X.X.X.X --username "XXX" --password "XXX" --database master --instance XXXX --query "THIS QUERY" --result "" --decode --warning 60 --critical 90 --querywarning 45000 --querycritical 86400