Cleanup config.nodes_of
[check_mk.git] / checks / oracle_sql
blob8bef52b916c579d7e8c80404057b90789a1ace21
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 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 # <<<oracle_sql:sep(58)>>>
28 # [[[SID-1|SQL-A]]]
29 # details:DETAILS
30 # perfdata:NAME=VAL;WARN;CRIT;MIN;MAX NAME=VAL;WARN;CRIT;MIN;MAX ...
31 # perfdata:NAME=VAL;WARN;CRIT;MIN;MAX ...
32 # long:LONG
33 # long:LONG
34 # ...
35 # exit:CODE
36 # elapsed:TS
37 # [[[SID-2|SQL-B]]]
38 # details:DETAILS
39 # perfdata:
40 # long:LONG
41 # long:LONG
42 # ...
43 # exit:CODE
44 # elapsed:TS
47 def parse_oracle_sql(info):
48 def parse_perfdata(line):
49 perfdata = []
50 for entry in line.split():
51 if not entry:
52 continue
53 var_name, data_str = entry.split("=", 1)
54 perf_entry = [var_name]
55 for data_entry in data_str.split(";"):
56 if "." in data_entry:
57 conversion = float
58 else:
59 conversion = int
60 try:
61 perf_entry.append(conversion(data_entry))
62 except:
63 perf_entry.append(None)
64 perfdata.append(tuple(perf_entry))
65 return perfdata
67 parsed = {}
68 instance = None
69 for line in info:
70 if line[0].startswith("[[[") and line[0].endswith("]]]"):
71 item_name = tuple(line[0][3:-3].split("|"))
72 instance = parsed.setdefault(
73 ("%s SQL %s" % item_name).upper(), {
74 "details": [],
75 "perfdata": [],
76 "long": [],
77 "exit": 0,
78 "elapsed": None,
79 "parsing_error": {},
81 continue
83 if instance is None:
84 continue
86 key = line[0]
87 infotext = ":".join(line[1:]).strip()
88 if key.endswith("ERROR") or key.startswith('ERROR at line') or "|FAILURE|" in key:
89 instance["parsing_error"].setdefault(("instance", "PL/SQL failure", 2), [])\
90 .append("%s: %s" % (key.split("|")[-1], infotext))
92 elif key in ["details", "long"]:
93 instance[key].append(infotext)
95 elif key == "perfdata":
96 try:
97 instance[key] += parse_perfdata(line[1])
98 except:
99 instance["parsing_error"].setdefault(("perfdata", "Perfdata error", 3), [])\
100 .append(infotext)
102 elif key == "exit":
103 instance[key] = int(line[1])
105 elif key == "elapsed":
106 instance[key] = float(line[1])
108 else:
109 instance["parsing_error"].setdefault(("unknown", "Unknown error", 3), [])\
110 .append(":".join(line).strip())
112 return parsed
115 def inventory_oracle_sql(parsed):
116 for instance in parsed:
117 yield instance, {}
120 def check_oracle_sql(item, params, parsed):
121 if item not in parsed:
122 return
124 data = parsed[item]
125 for (error_key, error_title, error_state), error_lines in data["parsing_error"].iteritems():
126 error_state = params.get("%s_error_state" % error_key, error_state)
127 yield error_state, "%s: %s" % (error_title, " ".join(error_lines))
129 perfdata = data["perfdata"]
130 elapsed_time = data["elapsed"]
131 if elapsed_time is not None:
132 perfdata.append(("elapsed_time", elapsed_time))
134 yield data["exit"], ", ".join(data["details"]), perfdata
136 if data["long"]:
137 yield 0, "\n%s" % "\n".join(data["long"])
140 check_info['oracle_sql'] = {
141 'parse_function': parse_oracle_sql,
142 'inventory_function': inventory_oracle_sql,
143 'check_function': check_oracle_sql,
144 'service_description': 'ORA %s',
145 'has_perfdata': True,
146 'group': 'oracle_sql',