2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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)>>>
30 # perfdata:NAME=VAL;WARN;CRIT;MIN;MAX NAME=VAL;WARN;CRIT;MIN;MAX ...
31 # perfdata:NAME=VAL;WARN;CRIT;MIN;MAX ...
47 def parse_oracle_sql(info
):
48 def parse_perfdata(line
):
50 for entry
in line
.split():
53 var_name
, data_str
= entry
.split("=", 1)
54 perf_entry
= [var_name
]
55 for data_entry
in data_str
.split(";"):
61 perf_entry
.append(conversion(data_entry
))
63 perf_entry
.append(None)
64 perfdata
.append(tuple(perf_entry
))
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(), {
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":
97 instance
[key
] += parse_perfdata(line
[1])
99 instance
["parsing_error"].setdefault(("perfdata", "Perfdata error", 3), [])\
103 instance
[key
] = int(line
[1])
105 elif key
== "elapsed":
106 instance
[key
] = float(line
[1])
109 instance
["parsing_error"].setdefault(("unknown", "Unknown error", 3), [])\
110 .append(":".join(line
).strip())
115 def inventory_oracle_sql(parsed
):
116 for instance
in parsed
:
120 def check_oracle_sql(item
, params
, parsed
):
121 if item
not in parsed
:
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
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',