Cleanup config.nodes_of
[check_mk.git] / checks / cisco_mem.include
blob55adbea4f4ae1e52d42bbb4972661571d42edfef
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 factory_settings["cisco_mem_default_levels"] = {
28 "levels": (80.0, 90.0),
32 def scan_cisco_mem_asa64(oid):
33 version = int((oid(".1.3.6.1.2.1.1.1.0").split("Version")[-1]).split(".")[0])
34 return version >= 9
37 def inventory_cisco_mem(info):
38 return [(line[0], {}) for line in info if line[0] != "Driver text"]
41 def check_cisco_mem(item, params, info):
42 for line in info:
44 if line[0] != item:
45 continue
47 if isinstance(params, tuple):
48 params = {"levels": params}
50 mem_free = int(line[2])
51 mem_used = int(line[1])
52 mem_total = mem_free + mem_used
53 return check_cisco_mem_sub(item, params, mem_used, mem_total)
56 def check_cisco_mem_sub(item, params, mem_used, mem_total):
57 if not mem_total:
58 return 3, "Cannot calculate memory usage: Device reports total memory 0"
60 perc_used = 100.0 * (float(mem_used) / float(mem_total))
61 warn, crit = params["levels"]
62 perfdata = [("mem_used", perc_used, warn, crit, 0, 100)]
64 status = 0
65 if isinstance(warn, float):
66 infotext = "%2.1f%% (%s) of %s used" % (perc_used, get_bytes_human_readable(mem_used),
67 get_bytes_human_readable(mem_total))
68 if perc_used >= crit:
69 status = 2
70 infotext += " (critical at %d%%)" % crit
71 elif perc_used >= warn:
72 status = 1
73 infotext += " (warning at %d%%)" % warn
74 else:
75 infotext = "%s (%2.1f%%) of %s used" % (get_bytes_human_readable(mem_used), perc_used,
76 get_bytes_human_readable(mem_total))
77 if mem_used >= crit:
78 status = 2
79 infotext += " (critical at %s MB)" % crit
80 elif mem_used >= warn:
81 status = 1
82 infotext += " (warning at %s MB)" % warn
84 if params.get("trend_range"):
85 mem_used_mb, mem_total_mb = mem_used / 1048576.0, mem_total / 1048576.0
86 trend_status, trend_infotext, trend_perfdata = size_trend('cisco_mem', item, "memory",
87 params, mem_used_mb, mem_total_mb)
88 status = max(status, trend_status)
89 infotext += trend_infotext
90 perfdata.extend(trend_perfdata)
92 return status, infotext, perfdata