Refactoring: Changed remaining check parameters starting with an 's' to the new rules...
[check_mk.git] / checks / solaris_mem
blob425bf7acddb5dc7a0c4048757a3c65eefba0f2b6
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 # <<<solaris_mem>>>
28 # Memory: 256G real, 54G free, 257G swap in use, 86G swap free
30 # <<<solaris_mem>>>
31 # Memory: 512M phys mem, 353M free mem, 2000M total swap, 2000M free swap
33 # <<<solaris_mem>>>
34 # Memory: 10G phys mem, 1905M free mem, 8002M total swap, 8002M free swap
36 # <<<solaris_mem>>>
37 # Memory: 640M real, 10M free, 293M swap in use, 349M swap free
39 # <<<solaris_mem>>>
40 # Memory: 2048M real, 913M free, 723M swap in use, 2863M swap free
43 def parse_solaris_mem(info):
44 # The 1.2.4 agent seems to create an empty section under some circumstances
45 if not info:
46 return {}
48 values = []
49 mem_tokens = " ".join(info[0][1:]).split(",")
50 is_total_swap = False
51 for token in mem_tokens:
52 if "total swap" in token:
53 is_total_swap = True
54 values.append(solaris_mem_to_kbytes(token.split()[0]))
56 # convert swap-in-use to swap-total, as expected by check_memory()
57 if not is_total_swap:
58 values[2] = values[2] + values[3]
60 keys = ['MemTotal', 'MemFree', 'SwapTotal', 'SwapFree']
61 return dict(zip(keys, values))
64 def solaris_mem_to_kbytes(s):
65 if s[-1] == 'G':
66 return int(s[:-1]) * 1024 * 1024
67 elif s[-1] == 'M':
68 return int(s[:-1]) * 1024
69 elif s[-1] == 'K':
70 return int(s[:-1])
71 else:
72 raise Exception("Could not parse value %s" % s)
75 def inventory_solaris_mem_used(parsed):
76 if parsed:
77 return [(None, {})]
80 def check_solaris_mem_used(_no_item, params, parsed):
81 return check_memory(params, parsed)
84 check_info['solaris_mem'] = {
85 "parse_function": parse_solaris_mem,
86 "check_function": check_solaris_mem_used,
87 "inventory_function": inventory_solaris_mem_used,
88 "service_description": "Memory used",
89 "has_perfdata": True,
90 "group": "memory",
91 "default_levels_variable": "memory_default_levels",
92 "includes": ["mem.include"],