Trying to create my own check_mysql_query

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mariomario89
Posts: 2
Joined: Thu Aug 07, 2014 10:36 am

Trying to create my own check_mysql_query

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Trying to create my own check_mysql_query

Post 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
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
mariomario89
Posts: 2
Joined: Thu Aug 07, 2014 10:36 am

Re: Trying to create my own check_mysql_query

Post 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
User avatar
lgroschen
Posts: 384
Joined: Wed Nov 27, 2013 1:17 pm

Re: Trying to create my own check_mysql_query

Post 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
/Luke
Locked