Page 1 of 1

Trying to create my own check_mysql_query

Posted: Fri Oct 24, 2014 4:21 am
by mariomario89
Hi everyone!

Im trying to create my own check_mysql_query (check_mysql_query2) as I want to add some features to the output but first need it to work.

This is the bash script I've created:

#!/bin/bash
SESIONES=$(/usr/lib/nagios/plugins/check_mysql_query -q $1 -u $2 -p $3 -H $4 -d $5 -P $6 -c -w 1)
ESTADO=$?
METRICA=$(echo ${SESIONES} | awk '{print $3}')
echo "$SESIONES | Result=${METRICA}"
exit ${ESTADO}


And this is how I call the check which is failing:

[user@icinga ~]#/usr/lib/nagios/plugins/check_mysql_query2 "select func_monitoring('optins',0,0,0,0,0) from dual;" 'user' 'password' 'host' 'database' 'port'
QUERY CRITICAL: Error with query - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 | Result=Error

If I call default check_mysql_query it works:

[user@icinga ~]#/usr/lib/nagios/plugins/check_mysql_query -q "select func_monitoring('optins',0,0,0,0,0) from dual;" -u 'user' -p 'password' -H 'host' -d 'database' -P 'port' -c -w 1
QUERY OK: 'select func_monitoring('optins',0,0,0,0,0) from dual;' returned 0,000000


Could someone help with with this issue?? Thanks

Regards

Mario

Re: Trying to create my own check_mysql_query

Posted: Fri Oct 24, 2014 1:38 pm
by sreinhardt
I'm not sure if this is going to work the way your script is set, mainly due to command expansion and argument handling with bash. Can you run the query like these?:

Code: Select all

$(/usr/lib/nagios/plugins/check_mysql_query -q "select func_monitoring('optins',0,0,0,0,0) from dual;" -u 'user' -p 'password' -H 'host' -d 'database' -P 'port' -c -w 1)

command="select func_monitoring('optins',0,0,0,0,0) from dual;"
/usr/lib/nagios/plugins/check_mysql_query -q "$command" -u 'user' -p 'password' -H 'host' -d 'database' -P 'port' -c -w 1

Re: Trying to create my own check_mysql_query

Posted: Mon Oct 27, 2014 11:33 am
by mariomario89
I finally managed to sove the problem adding double quotes to $1:

#!/bin/bash

SESIONES=$(/usr/lib64/nagios/plugins/check_mysql_query -q "$1" -u $2 -p $3 -H $4 -d $5 -P $6 -c -w $7)
ESTADO=$?
METRICA=$(echo ${SESIONES} | awk '{print $8}')
echo "$SESIONES | Output = ${METRICA}"
if [ ${METRICA} == 1,000000 ]; then
curl "url"
exit 2
fi
exit ${ESTADO}

But Im having other problem.
When I call the check manually it sends QUERY OK or QUERY CRITICAL and executes the curl command but when its is from nagios pannel it doesnt execute curl command and just show if QUERY is OK or CRITICAL.
Could it be because Im missing some priviledges?? Thanks

Mario

Re: Trying to create my own check_mysql_query

Posted: Mon Oct 27, 2014 2:34 pm
by lgroschen
I do see one problem so far as I can tell from the script you are missing a value after -c so maybe the arguments are not being sent properly
#!/bin/bash

SESIONES=$(/usr/lib64/nagios/plugins/check_mysql_query -q "$1" -u $2 -p $3 -H $4 -d $5 -P $6 -c -w $7)
ESTADO=$?
METRICA=$(echo ${SESIONES} | awk '{print $8}')
echo "$SESIONES | Output = ${METRICA}"
if [ ${METRICA} == 1,000000 ]; then
curl "url"
exit 2
fi
exit ${ESTADO}

/Luke