2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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 # In cooperation with Thorsten Bruhns from OPITZ Consulting
29 # <<<oracle_recovery_state:sep(124)>>>
30 # TUX2|tux2|PRIMARY|MOUNTED|1|1405456155|ONLINE||NO|2719061
31 # TUX2|tux2|PRIMARY|MOUNTED|2|1405456155|ONLINE||NO|2719061
32 # new format with backupmode
33 # <<<oracle_recovery_status:sep(124)>>>
34 # TUX2|tux2|PRIMARY|READ WRITE|1|1419771465|317|ONLINE|NO|YES|8149107|NOT ACTIVE|489
35 # TUX2|tux2|PRIMARY|READ WRITE|2|1419771465|317|ONLINE|NO|YES|8149107|NOT ACTIVE|489
37 # Databases seem to also report lines with some data missing:
38 # PV|PV|PRIMARY|READ WRITE|397|1433251398|7297|ONLINE|NO|YES|10740614283
39 # PV|PV|PRIMARY|READ WRITE|398|1433251398|7297|ONLINE|NO|YES|10740614283
40 # PV|PV|PRIMARY|READ WRITE|399|||ONLINE|||0
41 # PV|PV|PRIMARY|READ WRITE|400|||ONLINE|||0
42 # PV|PV|PRIMARY|READ WRITE|401|||ONLINE|||0
45 def inventory_oracle_recovery_status(info
):
46 return [(line
[0], {}) for line
in info
]
49 def check_oracle_recovery_status(item
, params
, info
):
53 oldest_checkpoint_age
= None
55 oldest_backup_age
= -1
66 db_name
, db_unique_name
, database_role
, _open_mode
, _filenr
, \
67 _checkpoint_time
, checkpoint_age
, datafilestatus
, _recovery
, _fuzzy
, _checkpoint_change
= line
69 backup_state
= 'unknown'
72 db_name
, db_unique_name
, database_role
, _open_mode
, _filenr
, \
73 _checkpoint_time
, checkpoint_age
, datafilestatus
, _recovery
, \
74 _fuzzy
, _checkpoint_change
, backup_state
, backup_age
= line
76 if params
.get("levels"):
77 warn
, crit
= params
["levels"]
79 if backup_state
== 'ACTIVE':
81 oldest_backup_age
= max(int(backup_age
), oldest_backup_age
)
83 if datafilestatus
== 'ONLINE':
84 if backup_state
== 'FILE MISSING':
87 checkpoint_age
= int(checkpoint_age
)
89 if oldest_checkpoint_age
is None:
90 oldest_checkpoint_age
= checkpoint_age
92 oldest_checkpoint_age
= max(oldest_checkpoint_age
, checkpoint_age
)
98 infotext
= "%s database" % (database_role
.lower())
100 if oldest_checkpoint_age
is None:
101 infotext
+= ", no online datafiles found(!!)"
104 elif oldest_checkpoint_age
<= -1:
105 # we found a negative time for last checkpoint
106 infotext
+= ", oldest checkpoint is in the future %s(!), check the time on the server" \
107 % get_age_human_readable(int(oldest_checkpoint_age
)*-1)
108 state
= max(state
, 1)
111 infotext
+= ", oldest Checkpoint %s ago" \
112 % (get_age_human_readable(int(oldest_checkpoint_age
)))
114 if (((database_role
== 'PRIMARY' and db_name
== '_MGMTDB' and db_unique_name
== '_mgmtdb') \
115 or not params
.get("levels")
117 or db_name
[db_name
.rfind('.')+1:] == 'PDB$SEED'
120 # We ignore the state of the check when no parameters are known
121 # _mgmtdb is new internal instance from 12.1.0.2 on Grid-Infrastructure
122 # ignore PDB$SEED because this PDB is always in READ ONLY mode
123 perfdata
.append(('checkpoint_age', oldest_checkpoint_age
))
125 if database_role
== 'PRIMARY':
126 # checkpoint age should not higher on primary as well
127 # There is no CRIT for older checkoint age as this is mostly not a
129 # otherwise the standby will produca a warning or crit as well
130 if oldest_checkpoint_age
>= warn
:
132 state
= max(1, state
)
134 perfdata
.append(('checkpoint_age', oldest_checkpoint_age
, warn
))
136 perfdata
.append(('checkpoint_age', oldest_checkpoint_age
, warn
, crit
))
138 # check the checkpoint age on a non primary database!
139 if oldest_checkpoint_age
>= crit
:
142 elif oldest_checkpoint_age
>= warn
:
144 state
= max(1, state
)
146 infotext
+= ' (warn/crit at %s/%s )' % (get_age_human_readable(warn
),
147 get_age_human_readable(crit
))
150 infotext
+= " %i datafiles offline(!!)" \
154 if filemissingcount
> 0:
155 infotext
+= " %i missing datafiles(!!)" \
159 if oldest_backup_age
> 0:
160 infotext
+= " %i datafiles in backup mode oldest is %s" % ( \
161 backup_count
, get_age_human_readable(oldest_backup_age
))
163 if params
.get("backup_age"):
165 warn
, crit
= params
["backup_age"]
166 infotext
+= " (warn/crit at %s/%s)" % (get_age_human_readable(warn
),
167 get_age_human_readable(crit
))
168 perfdata
.append(('backup_age', oldest_backup_age
, warn
, crit
))
170 if oldest_backup_age
>= crit
:
173 elif oldest_backup_age
>= warn
:
175 state
= max(1, state
)
177 perfdata
.append(('backup_age', oldest_backup_age
))
180 # create a 'dummy' performance data with 0
181 # => The age from plugin is only valid when a datafile is in backup mode!
182 perfdata
.append(('backup_age', 0))
184 return state
, infotext
, perfdata
186 # In case of missing information we assume that the login into
187 # the database has failed and we simply skip this check. It won't
188 # switch to UNKNOWN, but will get stale.
189 raise MKCounterWrapped("Login into database failed")
192 check_info
['oracle_recovery_status'] = {
193 "check_function": check_oracle_recovery_status
,
194 "inventory_function": inventory_oracle_recovery_status
,
195 "service_description": "ORA %s Recovery Status",
196 "has_perfdata": True,
197 "group": "oracle_recovery_status",