Skip to content

Commit 06d0331

Browse files
committed
mk-oracle: Restructure oracle_id and improve ruleset help texts
Move oracle_id from connection options to the instances section. Add SID and TNS alias fields to oracle_id. Update ruleset titles and help texts to clarify the relationship between default settings (applied to all databases) and per-database overrides in the instance list. Change-Id: I4557d3883b5e6fe0e023ba289ad2e9c9dc36c093
1 parent db88d0b commit 06d0331

File tree

3 files changed

+88
-78
lines changed

3 files changed

+88
-78
lines changed

cmk/plugins/oracle/bakery/mk_oracle_unified.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ class Config:
9292

9393

9494
class GuiOracleIdentificationConf(BaseModel):
95-
service_name: str
95+
service_name: str | None = None
9696
instance_name: str | None = None
97+
sid: str | None = None
98+
alias: str | None = None
9799

98100

99101
class GuiConnectionConf(BaseModel):
@@ -102,7 +104,6 @@ class GuiConnectionConf(BaseModel):
102104
timeout: int | None = None
103105
tns_admin: str | None = None
104106
oracle_local_registry: str | None = None
105-
oracle_id: GuiOracleIdentificationConf | None = None
106107

107108

108109
class GuiDiscoveryConf(BaseModel):
@@ -144,8 +145,7 @@ class GuiInstanceAdditionalOptionsConf(BaseModel):
144145

145146

146147
class GuiInstanceConf(BaseModel):
147-
service_name: str | None
148-
instance_name: str | None
148+
oracle_id: GuiOracleIdentificationConf
149149
auth: GuiAuthConf | None = None
150150
connection: GuiConnectionConf | None = None
151151

@@ -189,8 +189,6 @@ class OracleConnection(BaseModel):
189189
timeout: int | None = None
190190
tns_admin: str | None = None
191191
oracle_local_registry: str | None = None
192-
service_name: str | None = None
193-
instance: str | None = None
194192

195193

196194
class OracleInstanceAdditionalOptions(BaseModel):
@@ -201,6 +199,8 @@ class OracleInstanceAdditionalOptions(BaseModel):
201199
class OracleInstance(BaseModel):
202200
service_name: str | None = None
203201
instance_name: str | None = None
202+
sid: str | None = None
203+
alias: str | None = None
204204
authentication: OracleAuth | None = None
205205
connection: OracleConnection | None = None
206206

@@ -288,20 +288,12 @@ def _get_oracle_connection(conn: GuiConnectionConf | None) -> OracleConnection |
288288
if conn is None:
289289
return None
290290

291-
service_name = None
292-
instance = None
293-
if oracle_id := conn.oracle_id:
294-
service_name = oracle_id.service_name
295-
instance = oracle_id.instance_name
296-
297291
return OracleConnection(
298292
hostname=conn.host,
299293
port=conn.port,
300294
timeout=conn.timeout,
301295
tns_admin=conn.tns_admin,
302296
oracle_local_registry=conn.oracle_local_registry,
303-
service_name=service_name,
304-
instance=instance,
305297
)
306298

307299

@@ -374,16 +366,21 @@ def _get_oracle_instances(instances: list[GuiInstanceConf] | None) -> list[Oracl
374366

375367
result: list[OracleInstance] = []
376368
for instance in instances:
369+
oracle_id = instance.oracle_id
377370
if (
378-
not instance.service_name
379-
and not instance.instance_name
371+
oracle_id.service_name is None
372+
and oracle_id.instance_name is None
373+
and oracle_id.sid is None
374+
and oracle_id.alias is None
380375
and instance.auth is None
381376
and instance.connection is None
382377
):
383378
continue
384379
oracle_instance = OracleInstance(
385-
service_name=instance.service_name,
386-
instance_name=instance.instance_name,
380+
service_name=oracle_id.service_name,
381+
instance_name=oracle_id.instance_name,
382+
sid=oracle_id.sid,
383+
alias=oracle_id.alias,
387384
authentication=_get_oracle_authentication(instance.auth),
388385
connection=_get_oracle_connection(instance.connection),
389386
)

cmk/plugins/oracle/rulesets/mk_oracle_unified.py

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,48 @@ def _oracle_id() -> Dictionary:
238238
"service_name": DictElement(
239239
parameter_form=String(
240240
title=Title("Service Name"),
241-
help_text=Help("Oracle Service Name of the database instance."),
241+
help_text=Help(
242+
"The Oracle service name used to connect to the database. "
243+
"A service name typically represents a database and can map to "
244+
"one or more instances in a RAC environment."
245+
),
242246
),
243-
required=True,
247+
required=False,
244248
),
245249
"instance_name": DictElement(
246250
parameter_form=String(
247-
title=Title("Instance Name(SID)"),
251+
title=Title("Instance Name"),
248252
help_text=Help(
249-
"Oracle Instance Name of the database instance. May be the same as SID."
253+
"The Oracle instance name (ORACLE_SID running instance) to connect to. "
254+
"Use this to target a specific instance when multiple instances serve "
255+
"the same service name, e.g. in Oracle RAC configurations. "
256+
"If not set, the connection is made to the service name without "
257+
"specifying a particular instance."
258+
),
259+
),
260+
required=False,
261+
),
262+
"sid": DictElement(
263+
parameter_form=String(
264+
title=Title("SID"),
265+
help_text=Help(
266+
"The Oracle System Identifier (SID) that identifies "
267+
"a specific database instance on the host. "
268+
"Use SID-based connections for older Oracle configurations or "
269+
"when connecting to a database that does not use service names. "
270+
"If both a service name and SID are specified, "
271+
"the service name takes precedence."
272+
),
273+
),
274+
required=False,
275+
),
276+
"alias": DictElement(
277+
parameter_form=String(
278+
title=Title("TNS Alias"),
279+
help_text=Help(
280+
"A TNS alias as defined in the <tt>tnsnames.ora</tt> file. "
281+
"Requires a properly configured <tt>tnsnames.ora</tt> file accessible "
282+
"via the TNS_ADMIN directory path."
250283
),
251284
),
252285
required=False,
@@ -255,7 +288,7 @@ def _oracle_id() -> Dictionary:
255288
)
256289

257290

258-
def _connection_options(*, with_service_name: bool) -> Dictionary:
291+
def _connection_options() -> Dictionary:
259292
base: dict[str, DictElement[str] | DictElement[int]] = {
260293
"host": DictElement(
261294
parameter_form=String(
@@ -304,16 +337,9 @@ def _connection_options(*, with_service_name: bool) -> Dictionary:
304337
required=False,
305338
),
306339
}
307-
308-
extension: dict[str, DictElement[_NamedOption]] = {
309-
"oracle_id": DictElement(
310-
parameter_form=_oracle_id(),
311-
required=False,
312-
),
313-
}
314340
return Dictionary(
315341
title=Title("Connection options"),
316-
elements=base | extension if with_service_name else base,
342+
elements=base,
317343
)
318344

319345

@@ -510,15 +536,20 @@ def _endpoint(
510536
required=is_main_entry,
511537
),
512538
"connection": DictElement(
513-
parameter_form=_connection_options(with_service_name=is_main_entry),
539+
parameter_form=_connection_options(),
514540
required=is_main_entry,
515541
),
516542
}
517543

518544

519545
def _main() -> Dictionary:
520546
return Dictionary(
521-
title=Title("Default configuration"),
547+
title=Title("Default settings"),
548+
help_text=Help(
549+
"These settings apply to all monitored Oracle databases by default. "
550+
"They define the authentication, connection, and data collection options "
551+
"used unless overridden for a specific database in the instance list below."
552+
),
522553
elements={
523554
**_endpoint(is_main_entry=True),
524555
"cache_age": DictElement(
@@ -543,27 +574,20 @@ def _main() -> Dictionary:
543574

544575
def _instances() -> List[_NamedOption]:
545576
return List(
546-
title=Title("Database instances"),
577+
title=Title("Databases to monitor"),
547578
help_text=Help(
548-
"Define Oracle database instances to monitor to overwrite default settings."
579+
"Define the Oracle databases you want to monitor. Each entry must include "
580+
"an Oracle database identifier (service name, instance name, SID, or TNS alias). "
581+
"Authentication and connection options from the default settings are used "
582+
"automatically, but can be overridden per database if needed."
549583
),
550-
add_element_label=Label("Add new database instance"),
584+
add_element_label=Label("Add new database"),
551585
element_template=Dictionary(
552-
title=Title("Database instance"),
586+
title=Title("Database"),
553587
elements={
554-
"service_name": DictElement(
555-
parameter_form=String(
556-
title=Title("Service name"),
557-
help_text=Help("Oracle Service Name"),
558-
),
559-
required=False,
560-
),
561-
"instance_name": DictElement(
562-
parameter_form=String(
563-
title=Title("Oracle instance name"),
564-
help_text=Help("Oracle Instance Name, may be the same as SID."),
565-
),
566-
required=False,
588+
"oracle_id": DictElement(
589+
parameter_form=_oracle_id(),
590+
required=True,
567591
),
568592
**_endpoint(is_main_entry=False),
569593
},

tests/unit/cmk/plugins/oracle/bakery/test_oracle_unified.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
115115
port=None,
116116
timeout=None,
117117
tns_admin=None,
118-
oracle_id=None,
119118
),
120119
options=None,
121120
cache_age=None,
@@ -157,7 +156,6 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
157156
port=1521,
158157
timeout=10,
159158
tns_admin="/etc/oracle/tns",
160-
oracle_id=None,
161159
),
162160
options=GuiAdditionalOptionsConf(
163161
max_connections=10,
@@ -195,14 +193,15 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
195193
),
196194
instances=[
197195
GuiInstanceConf(
198-
service_name="Service_Name_1",
199-
instance_name=None,
200-
auth=None,
201-
connection=None,
196+
oracle_id=GuiOracleIdentificationConf(
197+
service_name="Service_Name_1",
198+
),
202199
),
203200
GuiInstanceConf(
204-
service_name="Service_Name_2",
205-
instance_name="Instance_Name_2",
201+
oracle_id=GuiOracleIdentificationConf(
202+
service_name="Service_Name_2",
203+
instance_name="Instance_Name_2",
204+
),
206205
auth=GuiAuthConf(
207206
auth_type=(
208207
OracleAuthType.STANDARD,
@@ -218,14 +217,10 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
218217
port=1522,
219218
timeout=20,
220219
tns_admin="/etc/oracle/tns2",
221-
oracle_id=None,
222220
),
223221
),
224222
GuiInstanceConf(
225-
service_name=None,
226-
instance_name=None,
227-
auth=None,
228-
connection=None,
223+
oracle_id=GuiOracleIdentificationConf(),
229224
),
230225
],
231226
)
@@ -296,9 +291,6 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
296291
timeout=None,
297292
tns_admin="some_tns_admin",
298293
oracle_local_registry="some_registry",
299-
oracle_id=GuiOracleIdentificationConf(
300-
service_name="some_name", instance_name="some_instance"
301-
),
302294
),
303295
options=None,
304296
cache_age=None,
@@ -339,10 +331,8 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
339331
" cache_age: 600",
340332
" connection:",
341333
" hostname: localhost",
342-
" instance: some_instance",
343334
" oracle_local_registry: some_registry",
344335
" port: 1521",
345-
" service_name: some_name",
346336
" tns_admin: some_tns_admin",
347337
" sections:",
348338
" - instance:",
@@ -376,10 +366,9 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
376366
),
377367
instances=[
378368
GuiInstanceConf(
379-
service_name="SIDONLY",
380-
instance_name=None,
381-
auth=None,
382-
connection=None,
369+
oracle_id=GuiOracleIdentificationConf(
370+
service_name="SIDONLY",
371+
),
383372
),
384373
],
385374
)
@@ -430,14 +419,14 @@ def _combine(files: Sequence[Plugin], yaml_lines: Sequence[str]) -> Sequence[Plu
430419
),
431420
instances=[
432421
GuiInstanceConf(
433-
service_name=None,
434-
instance_name="SID_A",
435-
auth=None,
436-
connection=None,
422+
oracle_id=GuiOracleIdentificationConf(
423+
instance_name="SID_A",
424+
),
437425
),
438426
GuiInstanceConf(
439-
service_name=None,
440-
instance_name="SID_B",
427+
oracle_id=GuiOracleIdentificationConf(
428+
instance_name="SID_B",
429+
),
441430
auth=GuiAuthConf(
442431
auth_type=(
443432
OracleAuthType.STANDARD,

0 commit comments

Comments
 (0)