Module: check_mk
Branch: master
Commit: a1265a6ced3fb0688094966c28b2af6c77d78d74
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a1265a6ced3fb0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 21 16:35:19 2015 +0200
#2256 mk_mysql: MySQL monitoring is now available for windows
The mk_mysql plugin which already existed for some time has been
ported to Windows. It is now available as windows agent plugin.
You can use the exact same checks as on linux hosts. To make the
agent plugin working, you need to configure the credentials
to access the database just like on linux systems with the
difference that the configuration file needs to be placed in
the directory of the <tt>check_mk_agent.exe</tt> and named
<tt>mysql.ini</tt>. In case you have multiple instances running
on a single host and need different credentials, you can create
multiple files named <tt>mysql_<instance>.ini</tt> while you need
to replace instance with the ident of the mysql process.
For further details take a look at the
<a
href="http://mathias-kettner.de/checkmk_mysql.html">documentation</a>.
---
.werks/2256 | 22 ++++++
ChangeLog | 1 +
agents/windows/plugins/mk_mysql.vbs | 130 +++++++++++++++++++++++++++++++++++
3 files changed, 153 insertions(+)
diff --git a/.werks/2256 b/.werks/2256
new file mode 100644
index 0000000..61978cc
--- /dev/null
+++ b/.werks/2256
@@ -0,0 +1,22 @@
+Title: mk_mysql: MySQL monitoring is now available for windows
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i1
+Date: 1432218553
+Class: feature
+
+The mk_mysql plugin which already existed for some time has been
+ported to Windows. It is now available as windows agent plugin.
+You can use the exact same checks as on linux hosts. To make the
+agent plugin working, you need to configure the credentials
+to access the database just like on linux systems with the
+difference that the configuration file needs to be placed in
+the directory of the <tt>check_mk_agent.exe</tt> and named
+<tt>mysql.ini</tt>. In case you have multiple instances running
+on a single host and need different credentials, you can create
+multiple files named <tt>mysql_<instance>.ini</tt> while you need
+to replace instance with the ident of the mysql process.
+
+For further details take a look at the
+<a
href="http://mathias-kettner.de/checkmk_mysql.html">documentation</a>.
diff --git a/ChangeLog b/ChangeLog
index fbc5677..433d721 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -189,6 +189,7 @@
* 2293 logwatch: Remove global setting logwatch_service_output from WATO...
* 2294 if, if64: Move global option for padding port numbers with zeroes into
rule...
* 2296 win_dhcp_pools: Convert global option for discovery empty pools into rule
set...
+ * 2256 mk_mysql: MySQL monitoring is now available for windows...
* 1457 FIX: logins: new check renamed from "users" check...
NOTE: Please refer to the migration notes!
* 1762 FIX: lnx_thermal: Now ignoring trip points with level 0...
diff --git a/agents/windows/plugins/mk_mysql.vbs b/agents/windows/plugins/mk_mysql.vbs
new file mode 100644
index 0000000..b479205
--- /dev/null
+++ b/agents/windows/plugins/mk_mysql.vbs
@@ -0,0 +1,130 @@
+' +------------------------------------------------------------------+
+' | ____ _ _ __ __ _ __ |
+' | / ___| |__ ___ ___| | __ | \/ | |/ / |
+' | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+' | | |___| | | | __/ (__| < | | | | . \ |
+' | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+' | |
+' | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+' +------------------------------------------------------------------+
+'
+' This file is part of Check_MK.
+' The official homepage is at
http://mathias-kettner.de/check_mk.
+'
+' check_mk is free software; you can redistribute it and/or modify it
+' under the terms of the GNU General Public License as published by
+' the Free Software Foundation in version 2. check_mk is distributed
+' in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+' out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+' PARTICULAR PURPOSE. See the GNU General Public License for more de-
+' ails. You should have received a copy of the GNU General Public
+' License along with GNU Make; see the file COPYING. If not, write
+' to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+' Boston, MA 02110-1301 USA.
+
+' This agent plugin is meant to be used on a windows server which
+' is running one or multiple MySQL server instances locally.
+
+Option Explicit
+
+Dim SHO, FSO, WMI, PROC
+Dim cfg_dir, cfg_file, service_list, service, instances, instance, cmd
+Dim output, pos, conn_args
+
+Set instances = CreateObject("Scripting.Dictionary")
+Set FSO = CreateObject("Scripting.FileSystemObject")
+Set SHO = CreateObject("WScript.Shell")
+
+cfg_dir = FSO.GetParentFolderName(FSO.GetParentFolderName(WScript.ScriptFullName))
+
+'
+' First detect all local instances. We only add services of instances
+' which service is currently reported as running
+'
+
+Set WMI =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
+Set service_list = WMI.ExecQuery("SELECT * FROM Win32_Service WHERE Name LIKE
'%MySQL%' and State = 'Running'")
+For Each service in service_list
+ ' add the internal service name as key and the launch command line as value
+ instances.add service.Name, service.PathName
+Next
+
+Set WMI = Nothing
+
+'
+' Now query these instances
+'
+
+' don't blame me for the stupid tempfile. I am aware of SHO.Exec, but in context
of
+' the agent this lead into strang hanging process problems. Propably because of some
+' filled buffer or whatever. Could not get this working. But SHO.Run works fine.
+Sub Run(cmd)
+ Dim FILE, tmp_file
+ tmp_file = "mk_mysql.out"
+ SHO.Run "cmd.exe /s /c "" " & cmd & "
1>>" & tmp_file & " 2>&1 """, 0, 1
+ Set FILE = FSO.GetFile(tmp_file)
+ If FILE.size <> 0 Then
+ wscript.echo FSO.OpenTextFile(tmp_file, 1).ReadAll()
+ End If
+ FILE.Delete()
+ Set FILE = Nothing
+End Sub
+
+For Each instance In instances.Keys
+ ' Use either an instance specific config file named
mysql_<instance-id>.ini
+ ' or the default mysql.ini file.
+ cfg_file = cfg_dir & "\mysql_" & instance & ".ini"
+ If Not fso.FileExists(cfg_file) Then
+ cfg_file = cfg_dir & "\mysql.ini"
+ If Not fso.FileExists(cfg_file) Then
+ cfg_file = ""
+ End If
+ End If
+
+ ' Now detect the correct socket / port to connect to this instance. This can be
done by executing
+ ' mysql.exe with the --defaults-file found in the command line of the windows
process together
+ ' with the option --print-defaults
+ cmd = instances.Item(instance)
+ cmd = Replace(cmd, "mysqld.exe", "mysql.exe")
+ cmd = Left(cmd, InStrRev(cmd, " ")) & " --print-defaults"
+ Set PROC = SHO.Exec(cmd)
+ PROC.StdIn.Close()
+ PROC.StdErr.Close()
+ output = PROC.StdOut.ReadAll()
+ pos = InStrRev(output, vbCrLf, Len(output)-1)
+ conn_args = Mid(output, pos+2, Len(output)-pos-4)
+
+ ' Now we try to construct a mysql.exe client command which is able to connect to
this database
+ ' based on the command uses by the database service.
+ ' In our development setup, where MySQL 5.6 has been used, the server command
is:
+ ' "C:\Programme\MySQL\MySQL Server 5.6\bin\mysqld.exe"
--defaults-file="C:\Dokumente und Einstellungen\All Users\Anwendungsdaten\MySQL\MySQL
Server 5.6\my.ini" MySQL56
+ ' To get the client command we simply need to replace mysqld.exe with mysql.exe,
remove the
+ ' my.ini and instance name from the end of the command and add our config as
--defaults-extra-file.
+ cmd = instances.Item(instance)
+ cmd = Replace(cmd, "mysqld.exe", "mysql.exe")
+ cmd = Left(cmd, InStr(cmd, "mysql.exe""")+9)
+ If cfg_file <> "" Then
+ cmd = cmd & " --defaults-extra-file=""" & cfg_file
& """"
+ End If
+ cmd = cmd & " " & conn_args
+
+ wscript.echo "<<<mysql_ping>>>"
+ wscript.echo "[[" & instance & "]]"
+ Run Replace(cmd, "mysql.exe", "mysqladmin.exe") & "
ping"
+
+ wscript.echo "<<<mysql>>>"
+ wscript.echo "[[" & instance & "]]"
+ Run cmd & " -B -sN -e ""show global status ; show global variables
;"""
+
+ wscript.echo "<<<mysql_capacity>>>"
+ wscript.echo "[[" & instance & "]]"
+ Run cmd & " -B -sN -e ""SELECT table_schema, sum(data_length +
index_length), sum(data_free)" & _
+ "FROM information_schema.TABLES GROUP BY
table_schema"""
+
+ wscript.echo "<<<mysql_slave>>>"
+ wscript.echo "[[" & instance & "]]"
+ Run cmd & " -B -s -e ""show slave status\G"""
+Next
+
+Set SHO = Nothing
+Set FSO = Nothing