Module: check_mk
Branch: master
Commit: 633714f1bc12fdad5f12384c482813abd777b54a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=633714f1bc12fd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Oct 22 11:57:19 2015 +0200
#2688 mssql agent plugin can now handle clustered MSSQL instances
---
.werks/2688 | 9 ++++++++
ChangeLog | 1 +
agents/windows/plugins/mssql.vbs | 44 +++++++++++++++++++++++++++++++-------
3 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/.werks/2688 b/.werks/2688
new file mode 100644
index 0000000..df8dc64
--- /dev/null
+++ b/.werks/2688
@@ -0,0 +1,9 @@
+Title: mssql agent plugin can now handle clustered MSSQL instances
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1445507809
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index d0fab2e..b87a66e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
* 2695 hp_msa_disk, hp_msa_volume: these checks now report more information about
disks and volumes of a HP MSA 2040 Storage System
* 2663 knuerr_rms_temp: switch to new generic temperature logic, allow e.g. lower
levels...
NOTE: Please refer to the migration notes!
+ * 2688 mssql agent plugin can now handle clustered MSSQL instances
* 2660 FIX: fixed windows agent using the wrong working directory...
* 2664 FIX: ps: Speedup in situation with many matching processes...
* 2661 FIX: windows agent: fixed incomplete process list...
diff --git a/agents/windows/plugins/mssql.vbs b/agents/windows/plugins/mssql.vbs
index 95d68bb..89baa8e 100644
--- a/agents/windows/plugins/mssql.vbs
+++ b/agents/windows/plugins/mssql.vbs
@@ -29,7 +29,8 @@
Option Explicit
-Dim WMI, FSO, SHO, prop, instId, instIdx, instVersion, instIds, instName, output
+Dim WMI, FSO, SHO, items, objItem, prop, instId, instIdx, instVersion
+Dim instIds, instName, output, isClustered
Dim WMIservice, colRunningServices, objService, cfg_dir, cfg_file, hostname
WScript.Timeout = 10
@@ -72,6 +73,26 @@ Function readIniFile(path)
Set readIniFile = parsed
End Function
+' Detect whether or not the script is called in a clustered environment.
+' Saves the virtual server names of the DB instances
+Set instServers = CreateObject("Scripting.Dictionary")
+On Error Resume Next
+Set WMI = GetObject("WINMGMTS:\\.\root\mscluster")
+Set items = WMI.execQuery("SELECT Name, Status, State, Type, PrivateProperties
" & _
+ "FROM MsCluster_Resource WHERE Type = 'SQL
Server'")
+For Each objItem in items
+ instName = objItem.PrivateProperties.InstanceName
+ instServers(instName) = objItem.PrivateProperties.VirtualServerName
+Next
+
+If Err.Number <> 0 Then
+ Err.Clear()
+ isClustered = FALSE
+Else
+ isClustered = TRUE
+End If
+On Error Goto 0
+
' Dummy empty output.
' Contains timeout error if this scripts runtime exceeds the timeout
WScript.echo "<<<mssql_versions>>>"
@@ -111,7 +132,8 @@ For Each prop In WMI.ExecQuery("SELECT * FROM
SqlServiceAdvancedProperty WHERE "
"SQLServiceType = 1 AND PropertyName =
'VERSION'")
- Set colRunningServices = WMIservice.ExecQuery("SELECT State FROM Win32_Service
WHERE Name = '" & prop.ServiceName & "'")
+ Set colRunningServices = WMIservice.ExecQuery("SELECT State FROM Win32_Service
" & _
+ "WHERE Name = '" &
prop.ServiceName & "'")
instId = Replace(prop.ServiceName, "$", "__")
instVersion = prop.PropertyStrValue
instIdx = Replace(instId, "__", "_")
@@ -136,9 +158,6 @@ Set CONN = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
CONN.Provider = "sqloledb"
-' Select a special DB
-'CONN.Properties("Initial Catalog").Value = "test123"
-
' Loop all found server instances and connect to them
' In my tests only the connect using the "named instance" string worked
For Each instId In instIds.Keys
@@ -175,10 +194,19 @@ For Each instId In instIds.Keys
End If
' In case of instance name "MSSQLSERVER" always use (local) as connect
string
- If instName = "MSSQLSERVER" Then
- CONN.Properties("Data Source").Value = "(local)"
+ If Not isClustered Then
+ If instName = "MSSQLSERVER" Then
+ CONN.Properties("Data Source").Value = "(local)"
+ Else
+ CONN.Properties("Data Source").Value = hostname & "\"
& instName
+ End If
Else
- CONN.Properties("Data Source").Value = hostname & "\"
& instName
+ ' In case the instance name is "MSSQLSERVER" always use the virtual
server name
+ If instName = "MSSQLSERVER" Then
+ CONN.Properties("Data Source").Value = instServers(instName)
+ Else
+ CONN.Properties("Data Source").Value = instServers(instName) &
"\" & instName
+ End If
End If
CONN.Open