2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 def inventory_mrpe(info
):
32 # New Linux agent sends (check_name) in first column. Stay
33 # compatible with MRPE versions not providing this info
34 if line
[0].startswith("("):
38 item
= urllib
.unquote(item
)
39 items
.append((item
, None))
43 def mrpe_parse_perfdata(perfinfo
):
44 varname
, valuetxt
= perfinfo
.split("=", 1)
45 values
= valuetxt
.split(";")
46 return tuple([varname
] + values
)
49 def check_mrpe(item
, params
, info
):
51 # This check is cluster-aware. An item might be found
52 # more than once. In that case we use the best of the
58 if line
[0].startswith("("):
59 check_name
= line
[0][1:-1]
63 if urllib
.unquote(line
[0]) == item
:
69 # convert to original format by joining and replacing \1 back with \n
70 rest
= " ".join(line
[2:]).replace("\1", "\n")
72 lines
= rest
.split('\n')
73 # First line: OUTPUT|PERFDATA
74 parts
= lines
[0].split("|", 1)
75 output
= [parts
[0].strip()]
76 if state
is None or state
not in [0, 1, 2, 3]:
77 output
[0] = "Invalid plugin status %s. Output is: %s" % (state
, output
[0])
80 perfdata
= parts
[1].strip().split()
85 now_comes_perfdata
= False
87 if now_comes_perfdata
:
90 parts
= l
.split("|", 1)
91 output
.append(parts
[0].strip())
93 perfdata
+= parts
[1].strip().split()
94 now_comes_perfdata
= True
97 if best_state
in [ None, 2 ] \
98 or (state
< best_state
and state
!= 2):
100 for perfvalue
in perfdata
:
102 perf_parsed
.append(mrpe_parse_perfdata(perfvalue
))
106 # name of check command needed for PNP to choose the correct template
108 perf_parsed
.append(check_name
)
109 best_result
= state
, "\n".join(output
), perf_parsed
112 if best_state
is None:
113 return (3, "Check output not found in output of MRPE")
117 check_info
["mrpe"] = {
118 'check_function': check_mrpe
,
119 'inventory_function': inventory_mrpe
,
120 'service_description': '%s',
121 'has_perfdata': True,