Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / oracle_longactivesessions
blob298bc093684d7c8f1fc2f7acce960855c2c8cb92
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 # <<<oracle_recovery_area>>>
28 # TUX12C 0 4800 19 0
30 # Columns:
31 # ORACLE_SID serial# machine process osuser program last_call_el sql_id
33 factory_settings["oracle_longactivesessions_defaults"] = {
34 "levels": (500, 1000),
38 def inventory_oracle_longactivesessions(info):
39 return [(line[0], {}) for line in info]
42 def check_oracle_longactivesessions(item, params, info):
43 sessioncount = 0
44 state = 3
45 itemfound = False
47 for line in info:
49 if len(line) <= 1:
50 continue
52 warn, crit = params["levels"]
54 if line[0] == item:
55 itemfound = True
57 if line[0] == item and line[1] != '':
59 sessioncount += 1
60 _sid, sidnr, serial, machine, process, osuser, program, \
61 last_call_el, sql_id = line
63 longoutput = 'Session (sid,serial,proc) %s %s %s active for %s from %s osuser %s program %s sql_id %s ' \
64 % (sidnr, serial, process, get_age_human_readable(int(last_call_el)), machine, osuser, program, sql_id)
66 if itemfound:
67 if sessioncount >= crit:
68 state = 2
69 elif sessioncount >= warn:
70 state = 1
71 else:
72 state = 0
74 if sessioncount == 0:
75 return 0, "%d long active sessions (%d, warn/crit at %d/%d)" \
76 % (sessioncount, sessioncount, warn, crit), \
77 [("count", sessioncount, warn, crit)]
78 elif sessioncount <= 10:
79 return state, "%d long active sessions (%d, warn/crit at %d/%d) %s" \
80 % (sessioncount, sessioncount, warn, crit, longoutput), \
81 [("count", sessioncount, warn, crit)]
82 elif sessioncount > 10:
83 return state, "%d long active sessions (%d, warn/crit at %d/%d)" \
84 % (sessioncount, sessioncount, warn, crit), \
85 [("count", sessioncount, warn, crit)]
87 # In case of missing information we assume that the login into
88 # the database has failed and we simply skip this check. It won't
89 # switch to UNKNOWN, but will get stale.
90 raise MKCounterWrapped("no info from database. Check ORA %s Instance" % item)
93 check_info['oracle_longactivesessions'] = {
94 "check_function": check_oracle_longactivesessions,
95 "inventory_function": inventory_oracle_longactivesessions,
96 "service_description": "ORA %s Long Active Sessions",
97 "has_perfdata": True,
98 "default_levels_variable": "oracle_longactivesessions_defaults",
99 "group": "oracle_longactivesessions",