Cleanup config.nodes_of
[check_mk.git] / checks / tsm_stagingpools
blob10c14b0d8d446817812084b0307b5a64c3ec6c7a
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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 # <<<tsm_stagingpools>>>
28 # tsmfarm2 SL8500_STGPOOL_05 99.9
29 # tsmfarm2 SL8500_STGPOOL_05 97.9
30 # tsmfarm2 SL8500_LTO4_STGPOOL_01 48.6
31 # tsmfarm2 SL8500_LTO4_STGPOOL_01 35.9
32 # tsmfarm2 SL8500_LTO4_STGPOOL_01 58.9
33 # tsmfarm2 SL8500_LTO4_STGPOOL_01 61.6
35 # Example for params
36 # params = {
37 # "free_below" : 30.0, # consider as free if utilized <= this
38 # "levels" : (5, 2), # warn/crit if less then that many free tapes
39 # }
41 factory_settings["tsm_stagingpools_default_levels"] = {
42 "free_below": 70,
46 def parse_tsm_stagingpools(info):
47 parsed = {}
49 def add_item(node, lineinfo):
50 inst, pool, util = lineinfo
51 if inst == "default":
52 item = pool
53 else:
54 item = inst + " / " + pool
55 parsed.setdefault(item, {})
56 parsed[item].setdefault(node, [])
57 parsed[item][node].append(util.replace(",", "."))
59 for line in info:
60 node = line[0]
61 add_item(node, line[1:4])
62 # The agent plugin sometimes seems to mix two lines together some
63 # times. Detect and fix that.
64 if len(line) == 7:
65 add_item(node, line[4:])
67 return parsed
70 def inventory_tsm_stagingpools(parsed):
71 for item in parsed:
72 yield item, {}
75 def check_tsm_stagingpools(item, params, parsed):
76 if item not in parsed:
77 return 3, "Item not found in agent output"
79 datasets, nodeinfos = [], []
80 for node, data in parsed[item].items():
81 if node is not None:
82 nodeinfos.append(node)
83 datasets.append(tuple(data))
85 num_tapes = 0
86 num_free_tapes = 0
87 utilization = 0.0 # in relation to one tape size
88 for util in datasets[0]:
89 util = float(util) / 100.0
90 utilization += util
91 num_tapes += 1
92 if util <= params["free_below"] / 100.0:
93 num_free_tapes += 1
95 if nodeinfos:
96 infotext = "%s: " % "/".join(nodeinfos)
97 else:
98 infotext = ""
99 infotext += "Total tapes: %d, Tapes less then %d%% full: %d, Utilization: %.1f tapes" % \
100 (num_tapes, params["free_below"], num_free_tapes, utilization)
101 state = 0
102 if "levels" in params:
103 warn, crit = params["levels"]
104 if num_free_tapes < crit:
105 state = 2
106 infotext += "(!!)"
107 elif num_free_tapes < warn:
108 state = 1
109 infotext += "(!)"
110 else:
111 warn, crit = None, None
113 if state == 0 and num_tapes == 0:
114 state = 3
115 infotext = "no tapes in this pool or pool not existant"
117 # In cluster mode we check if data sets are equal from all nodes
118 # else we have only one data set
119 if len(set(datasets)) > 1:
120 state = 3
121 infotext += ", Cluster: data from nodes are not equal"
123 return state, infotext, [("tapes", num_tapes), ("free", num_free_tapes, warn, crit),
124 ("util", utilization)]
127 check_info['tsm_stagingpools'] = {
128 "parse_function": parse_tsm_stagingpools,
129 "check_function": check_tsm_stagingpools,
130 "inventory_function": inventory_tsm_stagingpools,
131 "service_description": "TSM Stagingpool %s",
132 "has_perfdata": True,
133 "group": "tsm_stagingpools",
134 "default_levels_variable": "tsm_stagingpools_default_levels",
135 "node_info": True,