Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / netapp_api_snapshots
blobd227572d6ebdff1ca35dd5e4fb631b458a7657f1
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 # Agent output:
28 # <<<netapp_api_snapshots:sep(9)>>>
29 # volume_snapshot volch150 percent-reserved 22 blocks-reserved 3322 size-total 12122 ...
30 # volume_snapshot volch150 percentage-of-total-blocks 0 cumulative-total 122924 ...
32 factory_settings["netapp_api_snapshots_default_levels"] = {"levels": (85.0, 90.0)}
35 def inventory_netapp_api_snapshots(parsed):
36 for key in parsed.keys():
37 yield key, {}
40 def check_netapp_api_snapshots(item, params, parsed):
41 data = parsed.get(item)
43 if not data:
44 return
46 if data[0].get("state") != "online":
47 yield 3, "No snapshot information available. Volume is %s" % data[0].get("state")
48 return
50 snapshot_total = int(data[0]["reserve-used-actual"]) * 1024.0
51 size_total = int(data[0]["size-total"])
52 reserved_bytes = int(data[0]["snapshot-blocks-reserved"]) * 1024.0
54 if not reserved_bytes:
55 yield 0, "Used snapshot space: %s" % get_bytes_human_readable(snapshot_total), [
56 ("bytes", snapshot_total)
58 yield params.get("state_noreserve", 1), "No snapshot reserve configured"
59 return
61 used_percent = snapshot_total / reserved_bytes * 100.0
62 volume_total = size_total + reserved_bytes
64 state = 0
66 warn, crit = params.get("levels")
67 if used_percent >= crit:
68 state = 2
69 elif used_percent >= warn:
70 state = 1
72 extra_info = ("(Levels at %d%%/%d%%)" % (warn, crit)) if state else ""
74 yield state, "Reserve used: %.1f%% (%s)%s" % (
75 used_percent, get_bytes_human_readable(snapshot_total), extra_info)
77 yield 0, "Total Reserve: %s%% (%s) of %s" % (data[0]["snapshot-percent-reserved"],
78 get_bytes_human_readable(reserved_bytes),
79 get_bytes_human_readable(volume_total)),\
80 [("bytes", snapshot_total, 0, 0, 0, reserved_bytes)]
82 check_info["netapp_api_snapshots"] = {
83 'parse_function' : lambda info: netapp_api_parse_lines(info,
84 custom_keys = ["volume_snapshot"], as_dict_list = True),
85 'check_function' : check_netapp_api_snapshots,
86 'inventory_function' : inventory_netapp_api_snapshots,
87 "default_levels_variable" : "netapp_api_snapshots_default_levels",
88 'service_description' : 'Snapshots Volume %s',
89 'group' : "netapp_snapshots",
90 'has_perfdata' : True,
91 'includes' : ["netapp_api.include"]