Skip to content

Commit 64ec8ee

Browse files
committed
15370 FIX oracle_instance: fix reporting of restricted logins
Previously logins were not correctly reported: 1. they were only shown if the openmode was `OPEN` but not if they were `READ ONLY` or `READ WRITE` 2. the logic whether a database is restricted was inverted SUP-24195 Change-Id: Ia392defafa93e4fd35d65e78eb37b80c5a22193e
1 parent fbb8302 commit 64ec8ee

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

.werks/15370.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[//]: # (werk v2)
2+
# oracle_instance: fix reporting of restricted logins
3+
4+
key | value
5+
---------- | ---
6+
date | 2025-07-24T08:18:36+00:00
7+
version | 2.3.0p36
8+
class | fix
9+
edition | cre
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
Previously logins were not correctly reported:
15+
16+
1. they were only shown if the openmode was `OPEN` but not if they were `READ
17+
ONLY` or `READ WRITE`
18+
2. the logic whether a database is restricted was inverted

cmk/base/plugins/agent_based/oracle_instance_check.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class _Params(TypedDict, total=True):
6060
}
6161

6262

63+
def _is_open(openmode: str) -> bool:
64+
return openmode in {"OPEN", "READ ONLY", "READ WRITE"}
65+
66+
6367
def discover_oracle_instance(section: Section) -> DiscoveryResult:
6468
yield from (Service(item=item) for item in section)
6569

@@ -86,11 +90,7 @@ def check_oracle_instance(item: str, params: _Params, section: Section) -> Check
8690

8791
status_state = State.OK
8892
# Check state for PRIMARY Database. Normaly there are always OPEN
89-
if instance.database_role == "PRIMARY" and instance.openmode not in (
90-
"OPEN",
91-
"READ ONLY",
92-
"READ WRITE",
93-
):
93+
if instance.database_role == "PRIMARY" and not _is_open(instance.openmode):
9494
status_state = State(params["primarynotopen"])
9595
yield Result(
9696
state=status_state,
@@ -130,7 +130,7 @@ def _asses_property(
130130

131131
def _check_archive_log(instance: Instance, params: _Params) -> Iterable[Result]:
132132
# logins are only possible when the database is open
133-
if instance.openmode == "OPEN":
133+
if _is_open(instance.openmode):
134134
yield _asses_property("Logins", instance.logins, params, _LOGINS_MAP)
135135

136136
# the new internal database _MGMTDB from 12.1.0.2 is always in NOARCHIVELOG mode

cmk/base/plugins/agent_based/oracle_instance_section.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _parse_agent_line(line: Sequence[str]) -> InvalidData | GeneralError | Insta
150150

151151
if instance.pdb:
152152
assert instance.popenmode is not None
153-
instance.logins = "RESTRICTED" if str(instance.prestricted).lower() == "no" else "ALLOWED"
153+
instance.logins = "RESTRICTED" if str(instance.prestricted).lower() == "yes" else "ALLOWED"
154154
instance.openmode = instance.popenmode
155155
instance.up_seconds = instance.pup_seconds
156156

tests/unit/cmk/base/plugins/agent_based/test_oracle_instance.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,15 @@ def test_login():
827827
assert isinstance(section["ORA7777.FANTASY"], Instance)
828828

829829
assert section["ORA7777"].logins == "ALLOWED"
830-
assert section["ORA7777.BBBBBBBBBBBBBBB"].logins == "ALLOWED"
831-
assert section["ORA7777.PDB$SEED"].logins == "RESTRICTED"
830+
assert section["ORA7777.BBBBBBBBBBBBBBB"].logins == "RESTRICTED"
831+
assert section["ORA7777.PDB$SEED"].logins == "ALLOWED"
832832

833833
assert list(
834834
oracle_instance_check.check_oracle_instance("ORA7777.PDB$SEED", params, section)
835835
) == [
836836
Result(state=State.OK, summary="PDB Name ORA7777.PDB$SEED"),
837837
Result(state=State.OK, summary="Status READ ONLY"),
838+
Result(state=State.OK, summary="Logins allowed"),
838839
Result(state=State.OK, summary="PDB size: 4.14 GiB"),
839840
Metric("oracle_pdb_total_size", 4444444444.0),
840841
]
@@ -844,6 +845,7 @@ def test_login():
844845
) == [
845846
Result(state=State.OK, summary="PDB Name ORA7777.BBBBBBBBBBBBBBB"),
846847
Result(state=State.OK, summary="Status READ WRITE"),
848+
Result(state=State.CRIT, summary="Logins restricted"),
847849
Result(state=State.OK, summary="PDB size: 10.3 GiB"),
848850
Metric("oracle_pdb_total_size", 11111111111.0),
849851
]
@@ -853,7 +855,7 @@ def test_login():
853855
) == [
854856
Result(state=State.OK, summary="PDB Name ORA7777.FANTASY"),
855857
Result(state=State.OK, summary="Status OPEN"),
856-
Result(state=State.OK, summary="Logins allowed"),
858+
Result(state=State.CRIT, summary="Logins restricted"),
857859
Result(state=State.OK, summary="PDB size: 10.3 GiB"),
858860
Metric("oracle_pdb_total_size", 11111111111.0),
859861
]

0 commit comments

Comments
 (0)