Module: check_mk
Branch: master
Commit: 13efe633afa23d17096056b1b394d396f58e2886
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=13efe633afa23d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jun 9 08:52:25 2016 +0200
3591 mssql_clusters: Added information about nodes to MSSQL instance inventory
---
.werks/3591 | 9 ++++++
ChangeLog | 1 +
agents/windows/plugins/mssql.vbs | 36 +++++++++++++++++++++++-
inventory/mssql_clusters | 56 ++++++++++++++++++++++++++++++++++++++
inventory/mssql_versions | 14 ++++++++--
web/plugins/views/inventory.py | 6 +++-
6 files changed, 117 insertions(+), 5 deletions(-)
diff --git a/.werks/3591 b/.werks/3591
new file mode 100644
index 0000000..d5d39c8
--- /dev/null
+++ b/.werks/3591
@@ -0,0 +1,9 @@
+Title: mssql_clusters: Added information about nodes to MSSQL instance inventory
+Level: 1
+Component: inv
+Compatible: compat
+Version: 1.4.0i1
+Date: 1465455101
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 33abde6..6e81dc8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -493,6 +493,7 @@
* 3447 mssql_versions: Added inventory plugin for MSSQL instances
* 3581 mssql_versions: Added product name to inventory information
* 3585 Implemented API for exporting the full host inventory...
+ * 3591 mssql_clusters: Added information about nodes to MSSQL instance inventory
* 3219 FIX: lnx_distro: Now detecting Oracle VM Server correctly
* 3229 FIX: lnx_distro: SLES based systems have now an OS name inventorized\
* 3265 FIX: mk_inventory.solaris: fix problem on Solaris 10, do prtdiag and prtpicl
only in global zone
diff --git a/agents/windows/plugins/mssql.vbs b/agents/windows/plugins/mssql.vbs
index 75052df..4a529af 100644
--- a/agents/windows/plugins/mssql.vbs
+++ b/agents/windows/plugins/mssql.vbs
@@ -317,7 +317,6 @@ For Each instance_id In instances.Keys
'Loop all databases to get the size of the transaction log
addOutput( "<<<mssql_datafiles>>>" )
-
For Each dbName in dbNames.Keys
RS.Open "USE [" & dbName & "];", CONN
RS.Open "SELECT name, physical_name," &_
@@ -335,6 +334,41 @@ For Each instance_id In instances.Keys
Loop
RS.Close
Next
+
+ addOutput("<<<mssql_clusters>>>")
+ Dim active_node, nodes
+ For Each dbName in dbNames.Keys
+ RS.Open "USE [" & dbName & "];", CONN
+
+ ' Skip non cluster instances
+ RS.Open "SELECT SERVERPROPERTY('IsClustered') AS is_clustered",
CONN
+ If RS("is_clustered") = 0 Then
+ RS.Close
+ Continue
+ End If
+ RS.Close
+
+ nodes = ""
+ RS.Open "SELECT nodename FROM sys.dm_os_cluster_nodes", CONN
+ Do While Not RS.Eof
+ If nodes <> "" Then
+ nodes = nodes & ","
+ End If
+ nodes = nodes & RS("nodename")
+ RS.MoveNext
+ Loop
+ RS.Close
+
+ active_node = "-"
+ RS.Open "SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS
active_node", CONN
+ Do While Not RS.Eof
+ active_node = RS("active_node")
+ RS.MoveNext
+ Loop
+ RS.Close
+
+ addOutput(instance_id & " " & Replace(dbName, " ",
"_") & " " & active_node & " " & nodes)
+ Next
CONN.Close
Next
diff --git a/inventory/mssql_clusters b/inventory/mssql_clusters
new file mode 100644
index 0000000..e38a5e7
--- /dev/null
+++ b/inventory/mssql_clusters
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 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-
+# tails. 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.
+
+# <<<mssql_clusters>>>
+# MSSQL_VIM_SQLEXP node1 node1,node2
+
+def inv_mssql_clusters(info):
+ node = inv_tree_list("software.applications.mssql.instances:")
+
+ def get_list_item(key, val):
+ for item in node:
+ if item[key] == val:
+ return item
+
+ node.append({})
+ return node[-1]
+
+ for line in info:
+ instance_id = line[0]
+ database = line[1]
+ active_node = line[2]
+ nodes = line[3].split(",")
+
+ instance = get_list_item("name", instance_id)
+ instance.update({
+ "name" : instance_id,
+ "active_node" : active_node,
+ "node_names" : nodes,
+ })
+
+inv_info["mssql_clusters"] = {
+ "inv_function" : inv_mssql_clusters,
+}
diff --git a/inventory/mssql_versions b/inventory/mssql_versions
index 2d9c8bd..646aafa 100644
--- a/inventory/mssql_versions
+++ b/inventory/mssql_versions
@@ -55,6 +55,14 @@ def inv_mssql_versions(info):
else:
return "Unknown Product"
+ def get_list_item(key, val):
+ for item in node:
+ if item[key] == val:
+ return item
+
+ node.append({})
+ return node[-1]
+
for line in info:
if len(line) not in [2, 4]:
continue
@@ -65,15 +73,15 @@ def inv_mssql_versions(info):
clustered = len(line) == 4 and line[3] != ""
cluster_name = len(line) == 4 and line[3] or ""
- instance = {
+ instance = get_list_item("name", instance_id)
+ instance.update({
"name" : instance_id,
"version" : version,
"product" : product(version),
"edition" : edition,
"clustered" : clustered,
"cluster_name" : cluster_name,
- }
- node.append(instance)
+ })
inv_info["mssql_versions"] = {
"inv_function" : inv_mssql_versions,
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 012ee83..0cfcfc8 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -479,6 +479,9 @@ def inv_paint_mssql_is_clustered(clustered):
return "mssql_" + (clustered and "is_clustered" or
"is_not_clustered"), \
(clustered and _("is clustered") or _("is not clustered"))
+def inv_paint_mssql_node_names(node_names):
+ return "", ", ".join(node_names)
+
def inv_paint_ipv4_network(nw):
if nw == "0.0.0.0/0":
return "", _("Default")
@@ -695,7 +698,8 @@ inventory_displayhints.update({
".software.applications.mssql." : { "title" :
_("MSSQL") },
".software.applications.mssql.instances:" : { "title" :
_("Instances"), "render" : render_inv_dicttable,
- "keyorder" : [
"name", "product", "edition", "version",
"clustered", "cluster_name" ],
+ "keyorder" : [
"name", "product", "edition", "version",
"clustered",
+
"cluster_name", "active_node", "node_names" ],
},
".software.applications.mssql.instances:*.clustered" : { "title"
: _("Clustered"), "paint" : "mssql_is_clustered"},