Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / apc_symmetra_test
blobf369bfbc5a34129ba7692e73f47037bba5c0867f
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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.
27 # We use the following OIDs:
29 # PowerNet-MIB::upsAdvTestDiagnosticsResults .1.3.6.1.4.1.318.1.1.1.7.2.3
30 # upsAdvTestDiagnosticsResults OBJECT-TYPE
31 # SYNTAX INTEGER {
32 # ok(1),
33 # failed(2),
34 # invalidTest(3),
35 # testInProgress(4)
36 # }
37 # ACCESS read-only
38 # STATUS mandatory
39 # DESCRIPTION
40 # "The results of the last UPS diagnostics test performed."
41 # ::= { upsAdvTest 3 }
43 # PowerNet-MIB::upsAdvTestLastDiagnosticsDate .1.3.6.1.4.1.318.1.1.1.7.2.4
44 # upsAdvTestLastDiagnosticsDate OBJECT-TYPE
45 # SYNTAX DisplayString
46 # ACCESS read-only
47 # STATUS mandatory
48 # DESCRIPTION
49 # "The date the last UPS diagnostics test was performed in
50 # mm/dd/yy format."
51 # ::= { upsAdvTest 4 }
54 ups_test_default = (0, 0)
57 def check_apc_test(item, params, info):
58 days_warn, days_crit = params
59 if not info:
60 return 3, "Data Missing"
61 last_result = int(info[0][0])
62 last_date = info[0][1]
64 if last_date == 'Unknown' or len(last_date) not in [8, 10]:
65 return 3, "Date of last self test is unknown"
67 year_format = '%y' if len(last_date) == 8 else '%Y'
68 last_ts = time.mktime(time.strptime(last_date, '%m/%d/' + year_format))
69 days_diff = (time.time() - last_ts) / 86400
71 diagnostic_status_text = {1: "OK", 2: "failed", 3: "invalid", 4: "in progress"}
73 state = 0
74 diag_label = ""
75 if last_result == 2:
76 state = 2
77 diag_label = "(!!)"
78 elif last_result == 3:
79 state = 1
80 diag_label = "(!)"
82 time_label = ""
83 if days_crit and days_diff >= days_crit:
84 state = 2
85 time_label = "(!!)"
86 elif days_warn and days_diff >= days_warn:
87 state = max(state, 1)
88 time_label = "(!)"
90 return state, "Result of self test: %s%s, Date of last test: %s%s" % \
91 (diagnostic_status_text.get(last_result, '-'), diag_label, last_date, time_label)
94 def inventory_apc_test(info):
95 if info:
96 return [(None, "ups_test_default")]
99 check_info['apc_symmetra_test'] = {
100 "inventory_function": inventory_apc_test,
101 "check_function": check_apc_test,
102 "service_description": "Self Test",
103 "group": "ups_test",
104 "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.318.1.3"),
105 "snmp_info": (".1.3.6.1.4.1.318.1.1.1.7.2", [3, 4])