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
Trying to create my own check_mysql_query
-
mariomario89
- Posts: 2
- Joined: Thu Aug 07, 2014 10:36 am
-
sreinhardt
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: Trying to create my own check_mysql_query
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 1Nagios-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
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
#!/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
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
/Luke
#!/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