Refactored snapin server_time to new snapin API
[check_mk.git] / checks / solaris_mem
blob706c0b401332b6294a0d27da89983b1c56922d6a
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
42 def parse_solaris_mem(info):
43 # The 1.2.4 agent seems to create an empty section under some circumstances
44 if not info:
45 return {}
47 values = []
48 mem_tokens = " ".join(info[0][1:]).split(",")
49 is_total_swap = False
50 for token in mem_tokens:
51 if "total swap" in token:
52 is_total_swap = True
53 values.append(solaris_mem_to_kbytes(token.split()[0]))
55 # convert swap-in-use to swap-total, as expected by check_memory()
56 if not is_total_swap:
57 values[2] = values[2] + values[3]
59 keys = ['MemTotal', 'MemFree', 'SwapTotal', 'SwapFree']
60 return dict(zip(keys, values))
63 def solaris_mem_to_kbytes(s):
64 if s[-1] == 'G':
65 return int(s[:-1]) * 1024 * 1024
66 elif s[-1] == 'M':
67 return int(s[:-1]) * 1024
68 elif s[-1] == 'K':
69 return int(s[:-1])
70 else:
71 raise Exception("Could not parse value %s" % s)
74 def inventory_solaris_mem_used(parsed):
75 if parsed:
76 return [(None, {})]
79 def check_solaris_mem_used(_no_item, params, parsed):
80 return check_memory(params, parsed)
83 check_info['solaris_mem'] = {
84 "parse_function" : parse_solaris_mem,
85 "check_function" : check_solaris_mem_used,
86 "inventory_function" : inventory_solaris_mem_used,
87 "service_description" : "Memory used",
88 "has_perfdata" : True,
89 "group" : "memory",
90 "default_levels_variable" : "memory_default_levels",
91 "includes" : [ "mem.include" ],