2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<mssql_instance:sep(124)>>>
28 # MSSQL_MSSQLSERVER|config|10.50.1600.1|Enterprise Edition|BLABLA
29 # <<<mssql_instance:sep(124)>>>
30 # MSSQL_SQLEXPRESS|config|10.50.1600.1|Express Edition|
31 # <<<mssql_instance:sep(124)>>>
32 # MSSQL_MICROSOFT##SSEE|config|9.00.5000.00|Windows Internal Database|
33 # <<<mssql_instance:sep(124)>>>
34 # MSSQL_MSSQLSERVER|state|0|[DBNETLIB][ConnectionOpen (Connect()).]SQL Server existiert nicht oder Zugriff verweigert.
35 # <<<mssql_instance:sep(124)>>>
36 # MSSQL_SQLEXPRESS|state|1|[DBNETLIB][ConnectionOpen (Connect()).]SQL Server existiert nicht oder Zugriff verweigert.
37 # <<<mssql_instance:sep(124)>>>
38 # MSSQL_MICROSOFT##SSEE|state|0|[DBNETLIB][ConnectionOpen (Connect()).]SQL Server existiert nicht oder Zugriff verweigert.
40 # <<<mssql_instance:sep(124)>>>
41 # ERROR: Failed to gather SQL server instances
44 def _parse_prod_version(entry
):
45 if entry
.startswith("8."):
47 elif entry
.startswith("9."):
49 elif entry
.startswith("10.0"):
51 elif entry
.startswith("10.50"):
53 elif entry
.startswith("11."):
55 elif entry
.startswith("12."):
57 elif entry
.startswith("13."):
59 elif entry
.startswith("14."):
62 return "unknown[%s]" % entry
63 return "Microsoft SQL Server %s" % version
66 def parse_mssql_instance(info
):
69 if line
[0].startswith("ERROR:"):
71 elif line
[0][:6] == "MSSQL_":
72 # Remove the MSSQL_ prefix from the ID for this check
73 instance_id
= line
[0][6:]
77 instance
= parsed
.setdefault(
80 # it may happen that the state line is missing, add some fallback as default here
82 "error_msg": "Unable to connect to database (Agent reported no state)",
85 if line
[1] == "config":
87 "version_info": "%s - %s" % (line
[2], line
[3]),
88 "cluster_name": line
[4],
90 elif line
[1] == "state":
93 "error_msg": "|".join(line
[3:]),
96 elif line
[1] == "details":
97 _parse_prod_version(line
[2])
99 "prod_version_info": "%s (%s) (%s) - %s" % (_parse_prod_version(line
[2]), line
[3],
106 def inventory_mssql_instance(parsed
):
107 for instance_id
in parsed
.iterkeys():
108 yield instance_id
, {}
111 def check_mssql_instance(item
, params
, parsed
):
112 instance
= parsed
.get(item
)
117 if params
is not None and \
118 params
.get("map_connection_state") is not None:
119 state
= params
["map_connection_state"]
121 if instance
["state"] == "0":
122 yield state
, "Failed to connect to database (%s)" % instance
["error_msg"]
124 yield 0, "Version: %s" % instance
.get("prod_version_info", instance
["version_info"])
125 if instance
["cluster_name"] != "":
126 yield 0, "Clustered as %s" % instance
["cluster_name"]
129 check_info
["mssql_instance"] = {
130 'parse_function': parse_mssql_instance
,
131 'check_function': check_mssql_instance
,
132 'inventory_function': inventory_mssql_instance
,
133 'service_description': 'MSSQL %s Instance',
134 'group': 'mssql_instance',