forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_oracle_instance_uptime.py
97 lines (86 loc) · 3.29 KB
/
test_oracle_instance_uptime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import datetime
from zoneinfo import ZoneInfo
import pytest
import time_machine
from cmk.checkengine.checking import CheckPluginName
from cmk.base.api.agent_based.register import AgentBasedPlugins
from cmk.agent_based.v2 import (
IgnoreResultsError,
Metric,
Result,
Service,
State,
)
from cmk.plugins.lib.oracle_instance import GeneralError, Instance, InvalidData
from cmk.plugins.oracle.agent_based.oracle_instance_section import parse_oracle_instance
def test_discover_oracle_instance_uptime(agent_based_plugins: AgentBasedPlugins) -> None:
assert list(
agent_based_plugins.check_plugins[
CheckPluginName("oracle_instance_uptime")
].discovery_function(
{
"a": Instance(sid="a", version="", openmode="", logins="", up_seconds=1234),
"b": Instance(sid="a", version="", openmode="", logins=""),
"c": GeneralError("b", "whatever"),
"d": InvalidData("c", "This is an error"),
},
)
) == [
Service(item="a"),
]
def test_check_oracle_instance_uptime_normal(agent_based_plugins: AgentBasedPlugins) -> None:
with time_machine.travel(datetime.datetime.fromtimestamp(1643360266, tz=ZoneInfo("UTC"))):
assert list(
agent_based_plugins.check_plugins[
CheckPluginName("oracle_instance_uptime")
].check_function(
item="IC731",
params={},
section=parse_oracle_instance(
[
[
"IC731",
"12.1.0.2.0",
"OPEN",
"ALLOWED",
"STARTED",
"2144847",
"3190399742",
"ARCHIVELOG",
"PRIMARY",
"YES",
"IC73",
"130920150251",
]
]
),
)
) == [
Result(state=State.OK, summary="Up since 2022-01-03 13:10:19"),
Result(state=State.OK, summary="Uptime: 24 days 19 hours"),
Metric("uptime", 2144847.0),
]
def test_check_oracle_instance_uptime_error(agent_based_plugins: AgentBasedPlugins) -> None:
with pytest.raises(IgnoreResultsError):
list(
agent_based_plugins.check_plugins[
CheckPluginName("oracle_instance_uptime")
].check_function(
item="IC731",
params={},
section=parse_oracle_instance(
[
[
"IC731",
"FAILURE",
"ORA-99999 tnsping failed for IC731 ERROR: ORA-28002: the password "
"will expire within 1 days",
]
]
),
)
)