Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / aix_sap_processlist
blob30a36c916b7ceccec72280bbf4510c71c5972c54
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # Example output from agent:
28 # <<<aix_sap_processlist:sep(44)>>>
29 # [01]
30 # 23.03.2015 13:49:27
31 # GetProcessList
32 # OK
33 # name, description, dispstatus, textstatus, starttime, elapsedtime, pid
34 # msg_server, MessageServer, GREEN, Running, 2015 03 23 05:03:45, 8:45:42, 17563666
35 # disp+work, Dispatcher, GREEN, Running, Message Server connection ok, Dialog Queue time: 0.00 sec, 2015 03 23 05:03:45, 8:45:42, 15335532
36 # igswd_mt, IGS Watchdog, GREEN, Running, 2015 03 23 05:03:45, 8:45:42, 31326312
38 # <<<aix_sap_processlist:sep(44)>>>
39 # [02]
40 # 23.03.2015 13:59:27
41 # GetProcessList
42 # FAIL: NIECONN_REFUSED (Connection refused), NiRawConnect failed in plugin_fopen()
44 # <<<aix_sap_processlist:sep(44)>>>
45 # [04]
46 # 10.01.2017 09:10:41
47 # GetProcessList
48 # OK
49 # name, description, dispstatus, textstatus, starttime, elapsedtime, pid
50 # msg_server, MessageServer, GREEN, Running, 2017 01 08 14:38:18, 42:32:23, 12714224
51 # disp+work, Dispatcher, GREEN, Running, 2017 01 08 14:38:18, 42:32:23, 15794214
52 # aaaaaaaa, Central Syslog Collector, GRAY, Stopped, , , 9961478
53 # bbbbbbbb, Central Syslog Sender, GRAY, Stopped, , , 9109548
56 def parse_aix_sap_processlist(info):
57 instance, description = None, None
58 parsed = {}
59 for line in info:
60 if line[0].startswith('['):
61 instance = line[0][1:-1]
63 elif instance and line[0].startswith("FAIL:"):
64 instance = None
66 elif instance and len(line) == 7 and line[-1] != " pid":
67 description, status, textstatus, start = [re.sub("^ ", "", x) for x in line[1:5]]
69 elif instance and len(line) == 9:
70 description, status, textstatus = [re.sub("^ ", "", x) for x in line[1:4]]
71 start = re.sub("^ ", "", line[6])
73 else:
74 continue
76 if instance is not None and description is not None:
77 itemname = "%s on Instance %s" % (description, instance)
78 parsed.setdefault(itemname, {"status": status, "textstatus": textstatus})
79 try:
80 parsed[itemname]["start_time"] = time.strptime(start, "%Y %m %d %H:%M:%S")
81 except ValueError:
82 continue
84 return parsed
87 def inventory_aix_sap_processlist(parsed):
88 for entry in parsed:
89 yield entry, None
92 def check_aix_sap_processlist(item, _no_params, parsed):
93 if item in parsed:
94 data = parsed[item]
95 status = data["status"]
96 textstatus = data["textstatus"]
97 infotexts = ["Status: %s" % textstatus]
98 perfdata = []
100 if "start_time" in data:
101 start_time = data["start_time"]
102 start = time.strftime("%c", start_time)
103 elapsed = time.time() - time.mktime(start_time)
104 perfdata = [("runtime", elapsed)]
105 infotexts.append(
106 "Start Time: %s, Elapsed Time: %s" % (start, get_age_human_readable(elapsed)))
108 if status == "GREEN":
109 state = 0
110 elif status == "YELLOW":
111 state = 1
112 else:
113 state = 2
114 return state, ", ".join(infotexts), perfdata
117 check_info["aix_sap_processlist"] = {
118 'parse_function': parse_aix_sap_processlist,
119 'inventory_function': inventory_aix_sap_processlist,
120 'check_function': check_aix_sap_processlist,
121 'service_description': 'SAP Process %s',
122 'has_perfdata': True,