Module: check_mk
Branch: master
Commit: fe08e8400c9f2932f32dbfce54be1bdb7d5f28bb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe08e8400c9f29…
Author: Marcel Schulte <ms(a)mathias-kettner.de>
Date: Wed Dec 28 13:11:56 2016 +0100
4121 FIX mk_mysql: fixed handling of multiple instances
Change-Id: I9e0d34a5c7d14d3891087a5c9acf7b67884d3e51
---
.werks/4121 | 11 +++++++++++
ChangeLog | 1 +
agents/plugins/mk_mysql | 26 +++++++++++++-------------
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/.werks/4121 b/.werks/4121
new file mode 100644
index 0000000..848eee1
--- /dev/null
+++ b/.werks/4121
@@ -0,0 +1,11 @@
+Title: mk_mysql: fixed handling of multiple instances
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.4.0i4
+Date: 1482927046
+
+
+
diff --git a/ChangeLog b/ChangeLog
index 6aade15..8534eff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@
* 4008 FIX: Windows Agent, dotnet_clrmemory section: prevent indefinite freeze of
windows agent...
* 4209 FIX: mk_jolokia: Setting a default product now works...
* 4120 FIX: fixed checks mysql and mysql.sessions for multiple MySQL instances...
+ * 4121 FIX: mk_mysql: fixed handling of multiple instances
Multisite:
* 4169 View action: Default values of sticky, notification and persistent options can
now be configured via global settings....
diff --git a/agents/plugins/mk_mysql b/agents/plugins/mk_mysql
index 5b29ac1..7e2a04e 100755
--- a/agents/plugins/mk_mysql
+++ b/agents/plugins/mk_mysql
@@ -26,13 +26,13 @@
# gets optional socket as argument
function do_query() {
INSTANCE=$(echo $1|awk -v FS="=" '{print $2}')
- COUNT=$(ps -ef | grep [/]usr/sbin/mysqld | grep socket | wc -l)
+ COUNT=$(ps -efww | grep [/]usr/sbin/mysqld | grep socket | wc -l)
if [ $COUNT -gt 1 ]
then
- INSTANCE_NAME=$(ps -ef|grep socket|grep "${INSTANCE}"|grep
"[u]ser" | sed -ne 's/.*socket=\([^.]*\).*/\1/p')
+ INSTANCE_NAME=$(ps -efww|grep socket|grep "${INSTANCE}"|grep
"[u]ser" | sed -ne 's/.*socket=\([^.]*\).*/\1/p')
INSTANCE_NAME="[[${INSTANCE_NAME##*/}]]"
else
- INSTANCE_NAME="[[$(ps -ef|grep socket|grep "${INSTANCE}"|grep
"[u]ser" | sed -ne 's/.*user=\([^ ]*\).*/\1/p')]]"
+ INSTANCE_NAME="[[$(ps -efww|grep socket|grep "${INSTANCE}"|grep
"[u]ser" | sed -ne 's/.*user=\([^ ]*\).*/\1/p')]]"
fi
@@ -66,22 +66,22 @@ function do_query() {
if which mysqladmin >/dev/null
then
- mysql_sockets="--"$(fgrep socket $MK_CONFDIR/mysql.cfg)
- if [ $mysql_sockets = "--" ] ; then
- mysql_sockets=$(ps -ef | grep mysqld | grep "[s]ocket" | sed -ne
's/.*socket=\([^ ]*\).*/\1/p')
- if [ -z $mysql_sockets ] ; then
- do_query ""
- else
- for socket in $mysql_sockets ; do do_query "--socket="$socket ; done
- fi
- else
+ mysql_sockets=$(fgrep socket $MK_CONFDIR/mysql.cfg|sed -ne 's/.*socket=\([^
]*\).*/\1/p')
+ if [ -z "$mysql_sockets" ] ; then
+ mysql_sockets=$(ps -efww | grep mysqld | grep "[s]ocket" | sed -ne
's/.*socket=\([^ ]*\).*/\1/p')
+ fi
+ if [ -z "$mysql_sockets" ] ; then
do_query ""
+ else
+ for socket in $mysql_sockets ; do
+ do_query "--socket="$socket
+ done
fi
#echo "<<<mysql_version>>>"
#mysql -V
echo "<<<mysql_port>>>"
- ps -ef|grep 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
+ ps -efww|grep 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
#echo "<<<mysql_instances>>>"
#mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -s \