Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / oracle_jobs
bloba80789748b06a0c83782e33e1013d1edec4fcc5a
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_jobs>>>
28 # IODBSZ1 SYS SM$CLEAN_AUTO_SPLIT_MERGE SCHEDULED 0 763 TRUE 24.04.13 00:00:00,600000 EUROPE/VIENNA - SUCCEEDED
29 # IODBSZ1 SYS RSE$CLEAN_RECOVERABLE_SCRIPT SCHEDULED 0 763 TRUE 24.04.13 00:00:00,100000 EUROPE/VIENNA - SUCCEEDED
30 # IODBSZ1 SYS BSLN_MAINTAIN_STATS_JOB SCHEDULED 0 110 TRUE 29.04.13 00:00:00,300000 +01:00 BSLN_MAINTAIN_STATS_SCHED SUCCEEDED
31 # IODBSZ1 SYS DRA_REEVALUATE_OPEN_FAILURES SCHEDULED 0 97 TRUE 01.01.70 00:00:00,000000 +02:00 MAINTENANCE_WINDOW_GROUP SUCCEEDED
32 # IODBSZ1 SYS ORA$AUTOTASK_CLEAN SCHEDULED 0 763 TRUE 24.04.13 03:00:00,900000 EUROPE/VIENNA DAILY_PURGE_SCHEDULE SUCCEEDED
33 # IODBSZ1 SYS PURGE_LOG SCHEDULED 0 763 TRUE 24.04.13 03:00:00,800000 EUROPE/VIENNA DAILY_PURGE_SCHEDULE SUCCEEDED
34 # IODBSZ1 ORACLE_OCM MGMT_CONFIG_JOB SCHEDULED 0 97 TRUE 01.01.70 00:00:00,000000 +02:00 MAINTENANCE_WINDOW_GROUP SUCCEEDED
35 # IODBSZ1 ORACLE_OCM MGMT_STATS_CONFIG_JOB SCHEDULED 0 3 TRUE 01.05.13 01:01:01,000000 +01:00 - SUCCEEDED
36 # IODBSZ1 EXFSYS RLM$SCHDNEGACTION SCHEDULED 0 18954 TRUE 23.04.13 14:51:57,000000 +02:00 - SUCCEEDED
37 # IODBSZ1 EXFSYS RLM$EVTCLEANUP SCHEDULED 0 18202 TRUE 23.04.13 13:41:48,200000 +01:00 - SUCCEEDED
39 # new output
40 # <<<oracle_jobs:sep(124)>>>
41 # QS1|SYS|SM$CLEAN_AUTO_SPLIT_MERGE|SCHEDULED|1|877|TRUE|02-AUG-15 12.00.00.500000 AM EUROPE/VIENNA|-|SUCCEEDED
42 # QS1|SYS|RSE$CLEAN_RECOVERABLE_SCRIPT|SCHEDULED|0|877|TRUE|02-AUG-15 12.00.00.800000 AM EUROPE/VIENNA|-|SUCCEEDED
43 # QS1|SYS|FGR$AUTOPURGE_JOB|DISABLED||0|FALSE|01-JAN-70 12.00.00.000000 AM +02:00|-|
44 # QS1|SYS|BSLN_MAINTAIN_STATS_JOB|SCHEDULED|12|128|TRUE|02-AUG-15 12.00.00.600000 AM +01:00|BSLN_MAINTAIN_STATS_SCHED|SUCCEEDED
45 # QS1|SYS|DRA_REEVALUATE_OPEN_FAILURES|SCHEDULED|0|156|TRUE|01-JAN-70 12.00.00.000000 AM +02:00|MAINTENANCE_WINDOW_GROUP|SUCCEEDED
46 # QS1|SYS|HM_CREATE_OFFLINE_DICTIONARY|DISABLED||0|FALSE|01-JAN-70 12.00.00.000000 AM +02:00|MAINTENANCE_WINDOW_GROUP|
47 # QS1|SYS|ORA$AUTOTASK_CLEAN|SCHEDULED|0|877|TRUE|02-AUG-15 03.00.00.200000 AM EUROPE/VIENNA|DAILY_PURGE_SCHEDULE|SUCCEEDED
48 # QS1|SYS|FILE_WATCHER|DISABLED||0|FALSE|01-JAN-70 12.00.00.000000 AM +02:00|FILE_WATCHER_SCHEDULE|
49 # QS1|SYS|PURGE_LOG|SCHEDULED|0|877|TRUE|02-AUG-15 03.00.00.700000 AM EUROPE/VIENNA|DAILY_PURGE_SCHEDULE|SUCCEEDED
50 # QS1|ORACLE_OCM|MGMT_STATS_CONFIG_JOB|DISABLED|0|2|FALSE|01-MAY-15 01.01.01.100000 AM +01:00|-|
51 # QS1|ORACLE_OCM|MGMT_CONFIG_JOB|DISABLED|0|40|FALSE|08-APR-15 01.01.01.200000 AM +01:00|-|
52 # QS1|DBADMIN|DATENEXPORT-FUR|COMPLETED|0|3|FALSE|22-AUG-14 01.11.00.000000 AM EUROPE/BERLIN|-|
54 factory_settings["oracle_jobs_defaults"] = {
55 "disabled": True,
56 "missinglog": 1,
57 "missingjob": 3,
61 def inventory_oracle_jobs(info):
62 for line in info:
63 # old format < RDBMS 12.1
64 if len(line) >= 3 and len(line) <= 10:
65 yield "%s.%s.%s" % (line[0], line[1], line[2]), {}
66 else:
67 # new format: sid.pdb_name.job_owner.job_name
68 yield "%s.%s.%s.%s" % (line[0], line[1], line[2], line[3]), {}
71 def check_oracle_jobs(item, params, info):
73 # only extract the sid from item.
74 sid = item[0:item.index('.', 0)]
76 data_found = False
77 state = 0
79 for line in info:
80 service_found = False
82 if line[0] == sid:
83 data_found = True
85 # check for pdb_name in agent output
86 # => the agentoutput is responsible for the format of item from Check_MK!
87 # item could have the following formats. Keep in mind, that job_name could include a '.'!
88 if len(line) == 11:
89 # => sid.pdb_name.job_owner.job_name
90 itemsid, itempdb, itemowner, itemname = item.split('.', 4)
91 lineformat = 3
93 sid, job_pdb, job_owner, job_name, job_state, job_runtime, _job_run_count, \
94 job_enabled, job_nextrun, job_schedule, job_last_state = line
96 elif len(line) == 10:
97 # sid.job_owner.job_name
98 itemsid, itemowner, itemname = item.split('.', 3)
99 itempdb = ''
100 lineformat = 2
102 sid, job_owner, job_name, job_state, job_runtime, _job_run_count, \
103 job_enabled, job_nextrun, job_schedule, job_last_state = line
105 else:
106 # really old plugins without job_owner...
107 # this should be removed in a future release!
109 # sid.job_name
110 itemsid, itemname = item.split('.', 2)
111 itempdb = ''
112 itemowner = ''
113 lineformat = 1
115 job_name = line[2]
116 job_state = line[3]
117 job_runtime = line[4]
118 job_enabled = line[6]
119 job_nextrun = " ".join(line[7:-3])
120 job_schedule = line[-2]
121 job_last_state = line[-1]
123 if (lineformat == 3 and itemname == job_name and itemowner == job_owner and itempdb == job_pdb and itemsid == sid) \
124 or(lineformat == 2 and itemname == job_name and itemowner == job_owner and itemsid == sid) \
125 or(lineformat == 1 and itemname == job_name and itemsid == sid):
127 service_found = True
128 param_disabled = params["disabled"]
130 break
132 if not data_found:
133 # In case of missing information we assume that the login into
134 # the database has failed and we simply skip this check. It won't
135 # switch to UNKNOWN, but will get stale.
136 raise MKCounterWrapped("Login not possible for check %s" % item)
138 if not service_found:
139 missingjob = params.get('missingjob')
140 state = max(state, missingjob)
141 return (state, 'Job is missing')
143 state = 0
144 output = []
145 perfdata = []
147 txt = "Job-State: %s" % job_state
148 if job_state == "BROKEN":
149 txt += "(!!)"
150 state = max(state, 2)
151 output.append(txt)
153 txt = "Enabled: %s" % (job_enabled == "TRUE" and "Yes" or "No")
154 if job_enabled != "TRUE" and job_state != 'RUNNING':
155 if param_disabled:
156 txt += ' (ignored)'
157 else:
158 txt += "(!)"
159 state = max(state, 1)
160 output.append(txt)
162 if job_runtime == '' or job_runtime == 'SCHEDULED':
163 last_duration = 0
164 else:
165 last_duration = int(job_runtime.replace('.', ',').split(',', 1)[0])
166 # bugfix for an error in mk_oracle agent with missing round over last_duration
167 output.append("Last Duration: %s" % (get_age_human_readable(last_duration)))
169 if "run_duration" in params:
170 warn, crit = params["run_duration"]
172 output.append(" (warn/crit at %ds/%ds)" % (warn, crit))
174 if last_duration >= crit:
175 output.append("(!!)")
176 state = max(state, 2)
177 elif last_duration >= warn:
178 output.append("(!)")
179 state = max(state, 1)
181 perfdata.append(("duration", last_duration))
183 # 01.05.13 01:01:01,000000 +01:00
184 if job_nextrun.startswith("01.01.70 00:00:00"):
185 if job_schedule == "-" and job_state != "DISABLED":
186 job_nextrun = "not scheduled(!)"
187 state = max(state, 1)
188 else:
189 job_nextrun = job_schedule
190 output.append("Next Run: %s" % job_nextrun)
192 if "missinglog" in params:
193 missinglog = params["missinglog"]
194 else:
195 missinglog = 1
197 # A job who is running forever has no last run state and job_last_state is
198 # STOPPED
199 if job_state == "RUNNING" and job_runtime == '' and job_last_state == 'STOPPED':
200 txt = 'Job is running forever'
201 else:
203 if job_last_state == '':
204 # no information from job log (outer join in SQL is empty)
205 txt = ' no log information found'
207 if missinglog == 0:
208 txt += ' (ignored)'
209 elif missinglog == 1:
210 txt += '(!)'
211 elif missinglog == 2:
212 txt += '(!!)'
213 elif missinglog == 3:
214 txt += '(?)'
215 output.append(txt)
217 state = max(state, missinglog)
219 else:
220 txt = "Last Run Status: %s" % (job_last_state)
222 if job_enabled == "TRUE" and job_last_state != "SUCCEEDED":
223 state = max(state, 2)
224 else:
225 txt += ' (ignored disabled Job)'
226 output.append(txt)
228 if job_state == "DISABLED" and "status_disabled_jobs" in params:
229 state = params["status_disabled_jobs"]
231 return (state, ", ".join(output), perfdata)
234 check_info['oracle_jobs'] = {
235 "service_description": "ORA %s Job",
236 "group": "oracle_jobs",
237 "check_function": check_oracle_jobs,
238 "inventory_function": inventory_oracle_jobs,
239 "has_perfdata": True,
240 "default_levels_variable": "oracle_jobs_defaults",