Cleanup config.nodes_of
[check_mk.git] / checks / mssql_connections
blobf23fa529ecebbb4e2b3300e55c11343bda152d78
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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 # Example output:
28 # <<<mssql_connections>>>
29 # MSSQLSERVER master 16
30 # MSSQLSERVER tempdb 1
32 factory_settings["mssql_connections_default_levels"] = {
33 "levels": (20, 50),
37 def parse_mssql_connections(info):
38 parsed = {}
39 for line in info:
40 try:
41 instance, db_name, connection_count = line
42 connection_count = int(connection_count)
43 parsed.setdefault("%s %s" % (instance, db_name), connection_count)
44 except ValueError:
45 pass
46 return parsed
49 def inventory_mssql_connections(parsed):
50 for item in parsed:
51 yield item, {}
54 def check_mssql_connections(item, params, parsed):
55 # If a database is missing in the agent output there are no
56 # active connections for that database.
57 connection_count = parsed.get(item, 0)
59 warn, crit = params['levels']
60 if connection_count >= crit:
61 state = 2
62 elif connection_count >= warn:
63 state = 1
64 else:
65 state = 0
67 infotext = "Connections: %d" % connection_count
68 if state:
69 infotext += " (warn/crit at %d/%d)" % (warn, crit)
70 return state, infotext, [('connections', connection_count, warn, crit)]
73 check_info['mssql_connections'] = {
74 'parse_function': parse_mssql_connections,
75 'inventory_function': inventory_mssql_connections,
76 'check_function': check_mssql_connections,
77 'service_description': 'MSSQL Connections %s',
78 'group': 'mssql_connections',
79 'default_levels_variable': "mssql_connections_default_levels",
80 'has_perfdata': True,