2008-11-26 17:38:00 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Mysql remote Plugin for Pandora FMS Plugin server
|
2013-01-10 15:05:39 +01:00
|
|
|
# (c) ArticaST, Sancho Lerena 2012
|
2008-11-26 17:38:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Default values
|
|
|
|
PASSWORD=""
|
|
|
|
SERVER=""
|
|
|
|
USER=""
|
|
|
|
|
|
|
|
function help {
|
|
|
|
echo -e "MySQL Plugin for Pandora FMS Plugin server. http://pandorafms.com"
|
|
|
|
echo -e "Syntax:"
|
|
|
|
echo -e "\t\t-u username"
|
|
|
|
echo -e "\t\t-p password"
|
|
|
|
echo -e "\t\t-s server"
|
|
|
|
echo -e "\t\t-q query string (global status), for example 'Aborted_connects'\n"
|
|
|
|
echo -e "Samples:"
|
|
|
|
echo " ./mysql_plugin.sh -u root -p none -s localhost -q Com_select"
|
|
|
|
echo " ./mysql_plugin.sh -u root -p none -s localhost -q Com_update"
|
|
|
|
echo " ./mysql_plugin.sh -u root -p none -s localhost -q Connections"
|
|
|
|
echo " ./mysql_plugin.sh -u root -p anypass -s 192.168.50.24 -q Innodb_rows_read"
|
|
|
|
echo ""
|
2008-12-03 13:18:13 +01:00
|
|
|
exit
|
2008-11-26 17:38:00 +01:00
|
|
|
}
|
|
|
|
|
2008-12-03 13:18:13 +01:00
|
|
|
|
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
help
|
|
|
|
fi
|
|
|
|
|
2008-11-26 17:38:00 +01:00
|
|
|
# Main parsing code
|
|
|
|
|
2008-12-03 13:18:13 +01:00
|
|
|
while getopts ":hu:p:s:q:" optname
|
2008-11-26 17:38:00 +01:00
|
|
|
do
|
|
|
|
case "$optname" in
|
2008-12-03 13:18:13 +01:00
|
|
|
"h")
|
|
|
|
help
|
|
|
|
;;
|
2008-11-26 17:38:00 +01:00
|
|
|
"u")
|
2008-12-03 13:18:13 +01:00
|
|
|
USER=$OPTARG
|
2008-11-26 17:38:00 +01:00
|
|
|
;;
|
|
|
|
"p")
|
|
|
|
PASSWORD=$OPTARG
|
|
|
|
;;
|
|
|
|
"s")
|
|
|
|
SERVER=$OPTARG
|
|
|
|
;;
|
|
|
|
"q")
|
|
|
|
QUERY=$OPTARG
|
|
|
|
;;
|
2008-12-03 13:18:13 +01:00
|
|
|
?)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
default)
|
|
|
|
help
|
|
|
|
;;
|
2008-11-26 17:38:00 +01:00
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Execution
|
|
|
|
|
2012-10-09 19:57:22 +02:00
|
|
|
echo "show global status" | mysql -u $USER -p$PASSWORD -h$SERVER | grep "$QUERY" | head -1 | awk '{ print $2 }'
|
2008-11-26 17:38:00 +01:00
|
|
|
|
2013-01-10 15:05:39 +01:00
|
|
|
exit 0;
|