Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / plugins / mk_mysql
blobbe2254e927c7919cbad3c62e44a4beee89f5317e
1 #!/bin/bash
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 # gets optional socket as argument
27 function do_query() {
28 INSTANCE=$(echo $1|awk -v FS="=" '{print $2}')
29 COUNT=$(ps -fww -C mysqld | grep socket | wc -l)
30 if [ $COUNT -gt 1 ]
31 then
32 INSTANCE_NAME=$(ps -efww|grep socket|grep "${INSTANCE}"|grep "[u]ser" | sed -ne 's/.*socket=\([^.]*\).*/\1/p')
33 INSTANCE_NAME="[[${INSTANCE_NAME##*/}]]"
34 else
35 INSTANCE_NAME="[[$(ps -efww|grep socket|grep "${INSTANCE}"|grep "[u]ser" | sed -ne 's/.*user=\([^ ]*\).*/\1/p')]]"
40 # Check if mysqld is running and root password setup
41 echo "<<<mysql_ping>>>"
42 echo $INSTANCE_NAME
43 mysqladmin --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 ping 2>&1
45 if [ $? -eq 0 ]; then
47 echo "<<<mysql>>>"
48 echo $INSTANCE_NAME
49 mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -sN \
50 -e "show global status ; show global variables ;"
52 echo "<<<mysql_capacity>>>"
53 echo $INSTANCE_NAME
54 mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -sN \
55 -e "SELECT table_schema, sum(data_length + index_length), sum(data_free)
56 FROM information_schema.TABLES GROUP BY table_schema"
58 echo "<<<mysql_slave>>>"
59 echo $INSTANCE_NAME
60 mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -s \
61 -e "show slave status\G"
67 if which mysqladmin >/dev/null
68 then
69 mysql_sockets=$(fgrep socket $MK_CONFDIR/mysql.cfg|sed -ne 's/.*socket=\([^ ]*\).*/\1/p')
70 if [ -z "$mysql_sockets" ] ; then
71 mysql_sockets=$(ps -fww -C mysqld | grep "[s]ocket" | sed -ne 's/.*socket=\([^ ]*\).*/\1/p')
73 if [ -z "$mysql_sockets" ] ; then
74 do_query ""
75 else
76 for socket in $mysql_sockets ; do
77 do_query "--socket="$socket
78 done
80 #echo "<<<mysql_version>>>"
81 #mysql -V
83 echo "<<<mysql_port>>>"
84 ps -fww -C mysqld |while read LINE; do echo $LINE|grep "[u]ser" | sed -ne 's/.*user=\([^ ]*\).*/\1/p'; echo $LINE|grep mysqld | grep "[p]ort"|sed -ne 's/.*port=\([^ ]*\).*/\1/p' ; done|xargs -n2
86 #echo "<<<mysql_instances>>>"
87 #mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -s \
88 # -e "show INSTANCES"