Cleanup config.nodes_of
[check_mk.git] / checks / informix_logusage
blob60bdc6c7ec9de802abfeff8c6484fe6dbfdbb698
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 factory_settings['informix_logusage_default_levels'] = {'levels_perc': (80.0, 85.0)}
30 def parse_informix_logusage(info):
31 parsed = {}
32 instance = None
33 entry = None
34 for line in info:
35 if instance is not None and line == ["(constant)", "LOGUSAGE"]:
36 entry = {}
37 parsed.setdefault(instance, [])
38 parsed[instance].append(entry)
40 elif line[0].startswith("[[[") and line[0].endswith("]]]"):
41 instance = line[0][3:-3]
43 elif entry is not None:
44 if line[0] == "(expression)":
45 k, v = line[1].split(":")
46 else:
47 k, v = line[0], line[1]
48 entry.setdefault(k, v)
50 return parsed
53 def inventory_informix_logusage(parsed):
54 return [(instance, {}) for instance in parsed]
57 def check_informix_logusage(item, params, parsed):
58 if item in parsed:
59 data = parsed[item]
60 logfiles = len(data)
61 if not logfiles:
62 yield 1, "Log information missing"
63 return
65 size = 0
66 used = 0
67 for entry in data:
68 pagesize = int(entry['sh_pagesize'])
69 size += int(entry['size']) * pagesize
70 used += int(entry['used']) * pagesize
72 infotext = "Files: %s, Size: %s, Used: %s" % \
73 (logfiles, get_bytes_human_readable(size),
74 get_bytes_human_readable(used))
75 state = 0
76 if 'levels' in params:
77 warn, crit = params['levels']
78 if size >= crit:
79 state = 2
80 elif size >= warn:
81 state = 1
82 if state:
83 infotext += " (warn/crit at %s/%s)" % \
84 (get_bytes_human_readable(warn),
85 get_bytes_human_readable(crit))
87 yield state, infotext, [("file_count", logfiles), ("log_files_total", size),
88 ("log_files_used", used)]
90 if size:
91 used_perc = used * 100.0 / size
92 infotext = "%.2f%%" % used_perc
93 warn_perc, crit_perc = params['levels_perc']
94 state = 0
95 if used_perc >= crit_perc:
96 state = 2
97 elif used_perc >= warn_perc:
98 state = 1
99 if state:
100 infotext += " (warn/crit at %.2f%%/%.2f%%)" % (warn_perc, crit_perc)
102 yield state, infotext
105 check_info['informix_logusage'] = {
106 'parse_function': parse_informix_logusage,
107 'inventory_function': inventory_informix_logusage,
108 'check_function': check_informix_logusage,
109 'has_perfdata': True,
110 'service_description': 'Informix Log Usage %s',
111 'default_levels_variable': 'informix_logusage_default_levels',