Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / vnx_quotas
blob8bb3b749c692ad51793008417a35381475e4db42
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2016 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 # ..|..,total,avail,used,totalKB
28 # <<<vnx_quotas:sep(124)>>>
29 # [[[fs]]]
30 # fv51_01|806636,806636,0,0,825996248
31 # fv51_02|100774,100773,0,0,103193048
32 # fv52_01|252030,252030,0,0,258079448
33 # fv52_04|20104,20103,0,0,20586968
34 # fv53_01|1032512,1032512,0,0,1057293272
35 # fv53_04|20104,20103,0,0,20586968
36 # fv54_01|50355,50355,0,0,51564248
37 # fv54_02|120941,120941,0,0,123844568
38 # fv56_01|50355,50355,0,0,51564248
39 # fv56_02|50355,50355,0,0,51564248
40 # fv56_03|352868,352867,0,0,361337048
41 # fv56_04|100774,100773,0,0,103193048
42 # fv56_05|30188,30187,0,0,30912728
43 # fv56_06|857055,857055,0,0,877625048
44 # fv58_01|30188,30187,0,0,30912728
45 # fv61_01|201611,201611,0,0,206450648
46 # fv61_02|70523,70522,0,0,72215768
47 # fv61_03|30188,30187,0,0,30912728
48 # fv61_04|10020,10020,0,0,10261208
50 # ..|..|blochusage|blockhardlimit
51 # [[[quotas]]]
52 # vdmfv51|fv51_01|/hmtest|0|0
53 # vdmfv51|fv51_01|/BOEINT|0|1048576
54 # vdmfv51|fv51_01|/BOEPROD|0|73400320
55 # vdmfv51|fv51_01|/QIA|0|1048576
56 # vdmfv51|fv51_01|/DEV|0|157286400
57 # vdmfv51|fv51_01|/P90|0|52428800
58 # vdmfv51|fv51_01|/P62|0|786432000
59 # vdmfv51|fv51_02|/bo_transfer|0|205520896
60 # vdmfv52|fv52_01|/saptrans|0|471859200
61 # vdmfv52|fv52_04|/b10_gkretail|0|134217728
62 # vdmfv53|fv53_01|/sapcd|0|1073741824
63 # vdmfv53|fv53_04|/sap-template|0|104857600
64 # vdmfv54|fv54_01|/p22_archiv|0|1048576
65 # vdmfv54|fv54_01|/f22_archiv|0|1048576
66 # vdmfv54|fv54_01|/e22_archiv|0|1048576
67 # vdmfv54|fv54_01|/u1_ebv_zr|0|52428800
69 discovery_rules_vnx_quotas = []
72 def parse_vnx_quotas(info):
73 parsed = {"fs": {}, "quotas": {}}
74 section = None
75 for line in info:
76 if line[0].startswith("[[[") and line[0].endswith("]]]"):
77 section = line[0][3:-3]
78 continue
80 stripped_entries = [x.strip() for x in line]
81 if section == "fs":
82 parsed["fs"].setdefault(stripped_entries[0], {"data": stripped_entries[1].split(",")})
84 elif section == "quotas":
85 if len(stripped_entries) <> 5:
86 continue
88 dms, fs, mp, used_str, limit_str = stripped_entries
89 name = "%s %s" % (dms, mp)
90 parsed["quotas"].setdefault(name, {"fs": fs, "usage": None})
91 parsed["quotas"][name]["usage"] = used_str, limit_str, 0
93 return parsed
96 def vnx_quotas_renaming(name, mappings):
97 for match, substitution in mappings:
98 if match.startswith("~"):
99 num_perc_s = substitution.count("%s")
100 reg = regex(match[1:])
101 matchobj = reg.match(name)
102 if matchobj:
103 matches = [g and g or "" for g in matchobj.groups()]
104 for nr, group in enumerate(matches):
105 substitution = substitution.replace("%%%d" % (nr + 1), group)
106 substitution = substitution % tuple(matches[:num_perc_s])
107 return substitution
109 elif name == match:
110 return substitution
112 return name
115 def inventory_vnx_quotas(parsed):
116 discovery = []
117 settings = host_extra_conf(host_name(), discovery_rules_vnx_quotas)
118 for name in parsed["quotas"].iterkeys():
119 dms, mp = name.split(" ")
120 if settings:
121 dms = vnx_quotas_renaming(dms, settings[0].get("dms_names"))
122 mp = vnx_quotas_renaming(mp, settings[0].get("mp_names"))
123 discovery.append(("%s %s" % (dms, mp), {"pattern": name}))
124 return discovery
127 def check_vnx_quotas(item, params, parsed):
128 for quota_name in parsed["quotas"]:
129 if item == quota_name or quota_name == params["pattern"]:
130 data = parsed["quotas"][quota_name]
131 fs = data.get("fs")
132 used_kb, limit_kb_str, reserved_kb = data["usage"]
134 # Special case as customer said:
135 # if BlockHardLimit == "0" or "NoLimit" then we take filesystem size
136 if limit_kb_str in ["0", "NoLimit"] and fs in parsed["fs"]:
137 _total_size_mb, available_mb, _used_mb, \
138 _used_perc, total_size_kb = parsed["fs"][fs]["data"]
139 size_mb = int(total_size_kb) / 1024.0
140 else:
141 size_mb = int(limit_kb_str) / 1024.0
143 available_mb = size_mb - int(used_kb) / 1024.0
144 reserved_mb = reserved_kb / 1024.0
145 state, infotext, perfdata = df_check_filesystem_single(item, size_mb, available_mb,
146 reserved_mb, None, None, params)
148 return state, infotext.replace("filesystem", "quota"), perfdata
151 check_info['vnx_quotas'] = {
152 'parse_function': parse_vnx_quotas,
153 'inventory_function': inventory_vnx_quotas,
154 'check_function': check_vnx_quotas,
155 'service_description': 'VNX Quota %s',
156 'has_perfdata': True,
157 'group': "filesystem",
158 'default_levels_variable': 'filesystem_default_levels',
159 'includes': ['df.include', 'size_trend.include'],