Cleanup config.nodes_of
[check_mk.git] / checks / oracle_locks
blob6f41f7f1cb26bfd821599009b9283054348501d8
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_locks>>>
28 # TUX12C|273|2985|ora12c.local|sqlplus@ora12c.local (TNS V1-V3)|46148|oracle|633|NULL|NULL
29 # newdb|25|15231|ol6131|sqlplus@ol6131 (TNS V1-V3)|13275|oracle|SYS|3782|VALID|1|407|1463|ol6131|sqlplus@ol6131 (TNS V1-V3)|13018|oracle|SYS
31 factory_settings["oracle_locks_defaults"] = {
32 "levels": (1800, 3600),
36 def inventory_oracle_locks(info):
37 return [(line[0], {}) for line in info if len(line) >= 10]
40 def check_oracle_locks(item, params, info):
41 lockcount = 0
42 state = -1
43 infotext = ''
45 for line in info:
46 warn, crit = params["levels"]
47 if line[0] == item and line[1] != '':
48 err = oracle_handle_ora_errors(line)
49 if err is False:
50 continue
51 elif isinstance(err, tuple):
52 return err
54 if len(line) == 10:
56 # old format from locks_old in current plugin
57 _sid, sidnr, serial, machine, _program, process, osuser, ctime, \
58 object_owner, object_name = line
60 elif len(line) == 18:
62 _sid, sidnr, serial, machine, _program, process, osuser, _dbusername, ctime, \
63 _block_status, _blk_inst_id, _blk_sid, _blk_serial, _blk_machine, _blk_program, \
64 _blk_process, _blk_osuser, _blk_dbusername = line
66 object_owner = ''
67 object_name = ''
69 else:
71 raise MKCounterWrapped("Unknow number of items in agent output")
73 ctime = int(ctime)
75 if ctime >= crit:
76 state = 2
77 lockcount += 1
78 infotext += 'locktime %s (!!) Session (sid,serial, proc) %s,%s,%s machine %s osuser %s object: %s.%s ; ' \
79 % (get_age_human_readable(ctime), sidnr, serial, process, machine, osuser, object_owner, object_name)
81 elif ctime >= warn:
82 state = max(1, state)
83 lockcount += 1
84 infotext += 'locktime %s (!) Session (sid,serial, proc) %s,%s,%s machine %s osuser %s object: %s.%s ; ' \
85 % (get_age_human_readable(ctime), sidnr, serial, process, machine, osuser, object_owner, object_name)
87 if line[0] == item and line[1] == '':
88 state = max(0, state)
90 if infotext == '':
91 infotext = 'No locks existing'
92 elif lockcount > 10:
93 infotext = 'more then 10 locks existing!'
95 if state <> -1:
96 return (state, infotext)
98 # In case of missing information we assume that the login into
99 # the database has failed and we simply skip this check. It won't
100 # switch to UNKNOWN, but will get stale.
101 raise MKCounterWrapped("Login into database failed")
104 check_info["oracle_locks"] = {
105 'check_function': check_oracle_locks,
106 'inventory_function': inventory_oracle_locks,
107 'service_description': 'ORA %s Locks',
108 "default_levels_variable": "oracle_locks_defaults",
109 'group': 'oracle_locks',
110 'includes': ['oracle.include'],