Module: check_mk
Branch: master
Commit: 703d76f8b3422d19d090145745859793c8f1b5e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=703d76f8b3422d…
Author: Marcel Schulte <ms(a)mathias-kettner.de>
Date: Mon Aug 28 15:30:46 2017 +0200
4859 FIX MSSQL: plugin detects 32bit and 64bit instances now
Previously the plugin did not detect 32bit instances on 64bit OS. This has been fixed
now.
Change-Id: Iae24b05e6ea16a2b6de957509eb86f847698cfe8
---
.werks/4859 | 19 +++++++
agents/windows/plugins/mssql.vbs | 119 ++++++++++++++++++++++-----------------
2 files changed, 86 insertions(+), 52 deletions(-)
diff --git a/.werks/4859 b/.werks/4859
new file mode 100644
index 0000000..1f92dfb
--- /dev/null
+++ b/.werks/4859
@@ -0,0 +1,19 @@
+Title: MSSQL: plugin detects 32bit and 64bit instances now
+Level: 2
+Component: checks
+<<<<<<< HEAD
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1503906598
+=======
+Compatible: compat
+Edition: cre
+Version: 1.4.0p10
+Date: 1503906598
+Class: fix
+>>>>>>> bf0efbc... 4859 FIX MSSQL: plugin detects 32bit and 64bit
instances now
+
+Previously the plugin did not detect 32bit instances on 64bit OS. This has been fixed
now.
diff --git a/agents/windows/plugins/mssql.vbs b/agents/windows/plugins/mssql.vbs
index 0b592d1..738caef 100644
--- a/agents/windows/plugins/mssql.vbs
+++ b/agents/windows/plugins/mssql.vbs
@@ -81,18 +81,6 @@ Set sources = CreateObject("Scripting.Dictionary")
Dim service, i, version, edition, value_types, value_names, value_raw, cluster_name
Set WMI =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
-'
-' Gather instances on this host, store instance in instances and output version
section for it
-'
-registry.EnumValues HKLM, "SOFTWARE\Microsoft\Microsoft SQL Server\Instance
Names\SQL", _
- value_names, value_types
-
-If Not IsArray(value_names) Then
- addOutput("<<<mssql_instance:sep(124)>>>")
- addOutput("ERROR: Failed to gather SQL server instances")
- wscript.quit(1)
-End If
-
' Make sure that always all sections are present, even in case of an error.
' Note: the section <<<mssql_instance>>> section shows the general
state
' of a database instance. If that section fails for an instance then all
@@ -118,56 +106,83 @@ For Each section_id In sections.Keys
addOutput(sections(section_id))
Next
-For i = LBound(value_names) To UBound(value_names)
- instance_id = value_names(i)
+addOutput(sections("instance"))
- registry.GetStringValue HKLM, "SOFTWARE\Microsoft\Microsoft SQL Server\"
& _
- "Instance Names\SQL", _
- instance_id, instance_name
+'
+' Gather instances on this host, store instance in instances and output version
section for it
+'
- ' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\CurrentVersion
- registry.GetStringValue HKLM, "SOFTWARE\Microsoft\Microsoft SQL Server\"
& _
- instance_name &
"\MSSQLServer\CurrentVersion", _
- "CurrentVersion", version
+Dim regkeys, rk
+regkeys = Array( "", "Wow6432Node") ' gather all instances, also
32bit ones on 64bit Windows
- ' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\Setup
- registry.GetStringValue HKLM, "SOFTWARE\Microsoft\Microsoft SQL Server\"
& _
- instance_name & "\Setup", _
- "Edition", edition
+For Each rk In regkeys
+ Do
+ registry.EnumValues HKLM, "SOFTWARE\" & rk &
"\Microsoft\Microsoft SQL Server\Instance Names\SQL", _
+ value_names, value_types
- ' Check whether or not this instance is clustered
- registry.GetStringValue HKLM, "SOFTWARE\Microsoft\Microsoft SQL Server\"
& _
- instance_name & "\Cluster",
"ClusterName", cluster_name
+ If Not IsArray(value_names) Then
+ 'addOutput("ERROR: Failed to gather SQL server instances: "
& rk)
+ 'wscript.quit(1)
+ Exit Do
+ End If
- If IsNull(cluster_name) Then
- cluster_name = ""
+ For i = LBound(value_names) To UBound(value_names)
+ instance_id = value_names(i)
- ' In case of instance name "MSSQLSERVER" always use (local) as
connect string
- If instance_id = "MSSQLSERVER" Then
- sources.add instance_id, "(local)"
- Else
- sources.add instance_id, hostname & "\" & instance_id
- End If
- Else
- ' In case the instance name is "MSSQLSERVER" always use the virtual
server name
- If instance_id = "MSSQLSERVER" Then
- sources.add instance_id, cluster_name
- Else
- sources.add instance_id, cluster_name & "\" & instance_id
- End If
- End If
+ registry.GetStringValue HKLM, "SOFTWARE\" & rk &
"\Microsoft\Microsoft SQL Server\" & _
+ "Instance Names\SQL", _
+ instance_id, instance_name
- addOutput(sections("instance"))
- addOutput("MSSQL_" & instance_id & "|config|" &
version & "|" & edition & "|" & cluster_name)
+ ' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\CurrentVersion
+ registry.GetStringValue HKLM, "SOFTWARE\" & rk &
"\Microsoft\Microsoft SQL Server\" & _
+ instance_name &
"\MSSQLServer\CurrentVersion", _
+ "CurrentVersion", version
- ' Only collect results for instances which services are currently running
- Set service = WMI.ExecQuery("SELECT State FROM Win32_Service " & _
- "WHERE Name = 'MSSQL$" & instance_id &
"' AND State = 'Running'")
- If Not IsNull(service) Then
- instances.add instance_id, cluster_name
- End If
+ ' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\Setup
+ registry.GetStringValue HKLM, "SOFTWARE\" & rk &
"\Microsoft\Microsoft SQL Server\" & _
+ instance_name & "\Setup", _
+ "Edition", edition
+
+ ' Check whether or not this instance is clustered
+ registry.GetStringValue HKLM, "SOFTWARE\" & rk &
"\Microsoft\Microsoft SQL Server\" & _
+ instance_name & "\Cluster",
"ClusterName", cluster_name
+
+ If IsNull(cluster_name) Then
+ cluster_name = ""
+
+ ' In case of instance name "MSSQLSERVER" always use (local)
as connect string
+ If instance_id = "MSSQLSERVER" Then
+ sources.add instance_id, "(local)"
+ Else
+ sources.add instance_id, hostname & "\" &
instance_id
+ End If
+ Else
+ ' In case the instance name is "MSSQLSERVER" always use the
virtual server name
+ If instance_id = "MSSQLSERVER" Then
+ sources.add instance_id, cluster_name
+ Else
+ sources.add instance_id, cluster_name & "\" &
instance_id
+ End If
+ End If
+
+ addOutput(sections("instance"))
+ addOutput("MSSQL_" & instance_id & "|config|"
& version & "|" & edition & "|" & cluster_name)
+
+ ' Only collect results for instances which services are currently
running
+ Set service = WMI.ExecQuery("SELECT State FROM Win32_Service "
& _
+ "WHERE Name = 'MSSQL$" & instance_id
& "' AND State = 'Running'")
+ If Not IsNull(service) Then
+ instances.add instance_id, cluster_name
+ End If
+ Next
+ Loop While False
Next
+If instances.Count = 0 Then
+ addOutput("ERROR: Failed to gather SQL server instances")
+ wscript.quit(1)
+End IF
+
Set service = Nothing
Set WMI = Nothing
Set registry = Nothing