You are here

Check the stautus of a SQL query

3 posts / 0 new
Last post
stevebattman
stevebattman's picture
Check the stautus of a SQL query

HI,

I'd like to use/create a service check that can run a SQL query (MSSQL) and alert on the results?

I'll have the data in a table and want to create a service check (or multiple service checks)  that'll look at a singe result in the table

and alert on a set threshold.

Thanks

Steve

smarsh
smarsh's picture
Hi Steve,

Hi Steve,

Sorry didnt notice this as it was in the Core section!

So what you want to do is what ive just been playing with here. Essentially, Im SSH'ing into our database server running a query locally using a command like below:

check_by_ssh -t 30 -H $HOSTADDRESS$ -C "/usr/local/nagios/libexec/check_sql_advanced -u username -p password -q 'select COUNT(*) FROM x WHERE x.y LIKE \"% string %\" AND x.updated_at > now()-interval 1 week' -H localhost -d database -t mysql -e"

 

Be careful of escaping things, as Nagios likes to gobble things up and treat them weirdly. i.e. '$' is the macro variable, so if you use a $ make sure you put a backslash infront, etc. Its rather annoying I know but it can be worked around.

Hope this helps!

Sam

stevebattman
stevebattman's picture
HI,

HI,

Does this work for MSSQL (as I can't seem to get it to work). I see you've used the -t mysql argument in your example above.

Thanks

Steve