2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 def parse_ups_cps_battery(info
):
32 parsed
["capacity"] = int(info
[0][0])
34 # The MIB explicitly declares this to be Celsius
36 parsed
["temperature"] = int(info
[0][1])
38 # A TimeTick is 1/100 s
40 parsed
["battime"] = float(info
[0][2]) / 100
45 # .--Temperature---------------------------------------------------------.
47 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
48 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
49 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
50 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
52 # '----------------------------------------------------------------------'
55 def inventory_ups_cps_battery_temp(parsed
):
56 if "temperature" in parsed
:
57 return [("Battery", {})]
60 def check_ups_cps_battery_temp(item
, params
, parsed
):
61 return check_temperature(parsed
["temperature"], params
, "ups_cps_battery_temp")
64 check_info
["ups_cps_battery.temp"] = {
65 "inventory_function": inventory_ups_cps_battery_temp
,
66 "check_function": check_ups_cps_battery_temp
,
67 "service_description": "Temperature %s",
68 "group": "temperature",
69 "includes": ["temperature.include"],
73 # .--Capacity------------------------------------------------------------.
75 # | / ___|__ _ _ __ __ _ ___(_) |_ _ _ |
76 # | | | / _` | '_ \ / _` |/ __| | __| | | | |
77 # | | |__| (_| | |_) | (_| | (__| | |_| |_| | |
78 # | \____\__,_| .__/ \__,_|\___|_|\__|\__, | |
80 # '----------------------------------------------------------------------'
82 factory_settings
["ups_cps_battery"] = {
87 def inventory_ups_cps_battery(parsed
):
88 if "capacity" in parsed
:
92 def check_ups_cps_battery(item
, params
, parsed
):
93 def check_lower_levels(value
, levels
):
103 capacity
= parsed
["capacity"]
104 capacity_params
= params
["capacity"]
105 capacity_status
= check_lower_levels(capacity
, capacity_params
)
107 levelstext
= " (warn/crit at %d/%d%%)" % capacity_params
110 yield capacity_status
, ("Capacity at %d%%" % capacity
) + levelstext
112 battime
= parsed
["battime"]
113 # WATO rule stores remaining time in minutes
114 battime_params
= params
.get("battime")
115 battime_status
= check_lower_levels(battime
/ 60, battime_params
)
117 levelstext
= " (warn/crit at %d/%d min)" % battime_params
120 yield battime_status
, ("%.0f minutes remaining on battery" % (battime
/ 60)) + levelstext
123 check_info
["ups_cps_battery"] = {
124 "parse_function": parse_ups_cps_battery
,
125 "default_levels_variable": "ups_cps_battery",
126 "inventory_function": inventory_ups_cps_battery
,
127 "check_function": check_ups_cps_battery
,
128 "service_description": "UPS Battery",
129 "snmp_scan_function": lambda oid
: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.3808.1.1.1"
132 ".1.3.6.1.4.1.3808.1.1.1.2.2",
134 "1", # upsAdvanceBatteryCapacity
135 "3", # upsAdvanceBatteryTemperature
136 "4", # upsAdvanceBatteryRunTimeRemaining
138 "group": "ups_capacity",