Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / hpux_multipath
blob4df2ded6cd370fcf4748ddaf2eb3997a6971a0a1
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 # Example output from agent:
28 # <<<hpux_multipath>>>
29 # LUN PATH INFORMATION FOR LUN : /dev/rtape/tape1_BEST
30 # World Wide Identifier(WWID) = 0x600508b4000139e500049000075e0000
31 # State = UNOPEN
32 # LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk10
33 # World Wide Identifier(WWID) = 0x600508b4000139e500009000075e00b0
34 # State = ACTIVE
35 # LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk13
36 # World Wide Identifier(WWID) = 0x600508b4000139e500009000075e00c0
37 # State = UNOPEN
38 # LUN PATH INFORMATION FOR LUN : /dev/pt/pt2
39 # World Wide Identifier(WWID) = 0x600508b4000139e500009000075e00d0
40 # State = UNOPEN
41 # State = UNOPEN
42 # State = UNOPEN
43 # State = UNOPEN
44 # State = UNOPEN
45 # State = UNOPEN
46 # State = UNOPEN
47 # State = UNOPEN
48 # LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk781
49 # World Wide Identifier(WWID) = 0x600508b4000139e500009000075e00e0
50 # State = ACTIVE
51 # State = STANDBY
52 # State = FAILED
53 # State = FAILED
54 # State = ACTIVE
55 # State = STANDBY
56 # LUN PATH INFORMATION FOR LUN : /dev/rdisk/disk912
57 # World Wide Identifier(WWID) = 0x600508b4000139e500009000075e00f0
58 # State = ACTIVE
59 # State = STANDBY
60 # State = ACTIVE
61 # State = STANDBY
63 hpux_multipath_pathstates = {
64 "ACTIVE": 0,
65 "STANDBY": 1,
66 "FAILED": 2,
67 "UNOPEN": 3,
68 "OPENING": 0,
69 "CLOSING": 1
73 def parse_hpux_multipath(info):
74 disks = {}
75 for line in info:
76 if ':' in line:
77 disk = line[-1]
78 elif line[0] == "World":
79 wwid = line[-1]
80 paths = [0, 0, 0, 0] # ACTIVE, STANBY, FAILED, UNOPEN
81 disks[wwid] = (disk, paths)
82 elif '=' in line:
83 state = line[-1]
84 paths[hpux_multipath_pathstates[state]] += 1
85 return disks
88 def inventory_hpux_multipath(info):
89 inventory = []
90 disks = parse_hpux_multipath(info)
91 for wwid, (_disk, (active, standby, failed, unopen)) in disks.items():
92 if active + standby + failed >= 2:
93 inventory.append((wwid, (active, standby, failed, unopen)))
94 return inventory
97 def hpux_multipath_format_pathstatus(pathcounts):
98 infos = []
99 for name, i in hpux_multipath_pathstates.items():
100 c = pathcounts[i]
101 if c > 0:
102 infos.append("%d %s" % (c, name))
103 return ", ".join(infos)
106 def check_hpux_multipath(item, params, info):
107 disks = parse_hpux_multipath(info)
108 if item not in disks:
109 return (3, "no LUN with this WWID found")
110 disk, pathcounts = disks[item]
112 if pathcounts[2] > 0:
113 return (2, "%s: %d failed paths! (%s)" % (disk, pathcounts[2],
114 hpux_multipath_format_pathstatus(pathcounts)))
116 elif list(pathcounts) != list(params):
117 return (1, "%s: Invalid path status %s (should be %s)" %
118 (disk, hpux_multipath_format_pathstatus(pathcounts),
119 hpux_multipath_format_pathstatus(params)))
120 return (0, "%s: %s" % (disk, hpux_multipath_format_pathstatus(pathcounts)))
123 check_info["hpux_multipath"] = {
124 'check_function': check_hpux_multipath,
125 'inventory_function': inventory_hpux_multipath,
126 'service_description': 'Multipath %s',
127 'group': 'hpux_multipath',