Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / hitachi_hnas.include
blob0e8eeec07a763987f5fc857fcbf88f6492bc6f7f
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.
28 def parse_physical_volumes(volume_data):
29 status_map = {
30 '1': 'unformatted',
31 '2': 'mounted',
32 '3': 'formatted',
33 '4': 'needsChecking',
36 map_label = {}
37 parsed_volumes = {}
39 for volume_id, label, status_id, size, avail, evs in volume_data:
40 if volume_id == '':
41 continue
43 map_label[volume_id] = label
45 volume = '%s %s' % (volume_id, label)
46 status = status_map.get(status_id, 'unidentified')
47 size_mb = int(size) / 1048576.0 if size else None
48 avail_mb = int(avail) / 1048576.0 if avail else None
49 parsed_volumes[volume] = (status, size_mb, avail_mb, evs)
51 return map_label, parsed_volumes
54 def parse_virtual_volumes(map_label, virtual_volumes, quotas):
55 # Note: A virtual volume may have no quota or a quota without a limit
56 # and usage.
57 # Besides quotas for virtual volumes the quota table also contains
58 # user and group quotas.
60 # A QuotasEntry is indexed by a concatenation of the physical
61 # volume_id the virtual volume belongs to and the oid_end without
62 # the first element of the virtual volume.
63 def quota_oid_end(phys_volume_id, virtual_volume_oid_end):
64 return '.'.join([phys_volume_id] + virtual_volume_oid_end.split('.')[1:] + ['0'])
66 parsed = {}
67 map_quota_oid = {}
68 for oid_end, phys_volume_id, virtual_volume_label in virtual_volumes:
69 phys_volume_label = map_label[phys_volume_id]
70 volume = '%s on %s' % (virtual_volume_label, phys_volume_label)
71 parsed[volume] = None
73 ref_oid_end = quota_oid_end(phys_volume_id, oid_end)
74 map_quota_oid[ref_oid_end] = volume
76 volume_quota = '3'
77 for oid_end, quota_type, usage, limit in quotas:
78 if quota_type != volume_quota:
79 continue
81 if usage and limit:
82 volume = map_quota_oid[oid_end]
83 size_mb = int(limit) / 1048576.0
84 avail_mb = size_mb - int(usage) / 1048576.0
85 parsed[volume] = (size_mb, avail_mb)
86 else:
87 parsed[volume] = (None, None)
89 return parsed
92 def hitachin_hnas_scan_function(oid):
93 system_oid = oid(".1.3.6.1.2.1.1.2.0")
95 if system_oid.startswith(".1.3.6.1.4.1.11096.6"):
96 return True
98 # e.g. HM800 report "linux" as type. Check the vendor tree too
99 return system_oid.startswith(".1.3.6.1.4.1.8072.3.2.10") \
100 and oid(".1.3.6.1.4.1.11096.6.1.*")