forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_elasticsearch_cluster_health.py
178 lines (169 loc) · 6.42 KB
/
test_elasticsearch_cluster_health.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/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 pytest
from cmk.base.legacy_checks.elasticsearch_cluster_health import (
check_elasticsearch_cluster_health,
check_elasticsearch_cluster_health_shards,
check_elasticsearch_cluster_health_tasks,
parse_elasticsearch_cluster_health,
)
pytestmark = pytest.mark.checks
@pytest.mark.parametrize(
"parameters, item, info, expected_result",
[
(
{},
None,
[
["cluster_name", "elasticsearch"],
["status", "yellow"],
["timed_out", "False"],
["number_of_nodes", "5"],
["number_of_data_nodes", "5"],
["active_primary_shards", "747"],
["active_shards", "1613"],
["relocating_shards", "0"],
["initializing_shards", "0"],
["unassigned_shards", "0"],
["delayed_unassigned_shards", "0"],
["number_of_pending_tasks", "0"],
["number_of_in_flight_fetch", "0"],
["task_max_waiting_in_queue_millis", "0"],
["active_shards_percent_as_number", "100.0"],
],
[
(0, "Name: elasticsearch"),
(0, "Data nodes: 5", [("number_of_data_nodes", 5, None, None)]),
(0, "Nodes: 5", [("number_of_nodes", 5, None, None)]),
(1, "Status: yellow"),
],
),
(
{"green": 0, "red": 2, "yellow": 3},
None,
[["status", "yellow"]],
[
(3, "Status: yellow (State changed by rule)"),
],
),
],
)
def test_check_function(parameters, item, info, expected_result):
parsed = parse_elasticsearch_cluster_health(info)
assert list(check_elasticsearch_cluster_health(item, parameters, parsed)) == expected_result
@pytest.mark.parametrize(
"parameters, item, info, expected_result",
[
(
{},
None,
[
["cluster_name", "elasticsearch"],
["status", "yellow"],
["timed_out", "False"],
["number_of_nodes", "5"],
["number_of_data_nodes", "5"],
["active_primary_shards", "747"],
["active_shards", "1613"],
["relocating_shards", "0"],
["initializing_shards", "0"],
["unassigned_shards", "0"],
["delayed_unassigned_shards", "0"],
["number_of_pending_tasks", "0"],
["number_of_in_flight_fetch", "0"],
["task_max_waiting_in_queue_millis", "0"],
["active_shards_percent_as_number", "100.0"],
],
[
(0, "Active primary: 747", [("active_primary_shards", 747, None, None)]),
(0, "Active: 1613", [("active_shards", 1613, None, None)]),
(
0,
"Active in percent: 100.00%",
[("active_shards_percent_as_number", 100.0, None, None)],
),
(0, "Delayed unassigned: 0", [("delayed_unassigned_shards", 0, None, None)]),
(0, "Initializing: 0", [("initializing_shards", 0, None, None)]),
(
0,
"Ongoing shard info requests: 0",
[("number_of_in_flight_fetch", 0, None, None)],
),
(0, "Relocating: 0", [("relocating_shards", 0, None, None)]),
(0, "Unassigned: 0", [("unassigned_shards", 0, None, None)]),
],
),
(
{},
None,
[
["cluster_name", "elasticsearch"],
["status", "yellow"],
["timed_out", "False"],
["number_of_nodes", "5"],
["number_of_data_nodes", "5"],
["number_of_pending_tasks", "0"],
["task_max_waiting_in_queue_millis", "0"],
],
[], # If there is no shards information, there is no result (the state of the check turns to UNKNOWN)
),
],
)
def test_shards_check_function(parameters, item, info, expected_result):
parsed = parse_elasticsearch_cluster_health(info)
assert (
list(check_elasticsearch_cluster_health_shards(item, parameters, parsed)) == expected_result
)
@pytest.mark.parametrize(
"parameters, item, info, expected_result",
[
(
{},
None,
[
["cluster_name", "elasticsearch"],
["status", "yellow"],
["timed_out", "False"],
["number_of_nodes", "5"],
["number_of_data_nodes", "5"],
["active_primary_shards", "747"],
["active_shards", "1613"],
["relocating_shards", "0"],
["initializing_shards", "0"],
["unassigned_shards", "0"],
["delayed_unassigned_shards", "0"],
["number_of_pending_tasks", "0"],
["number_of_in_flight_fetch", "0"],
["task_max_waiting_in_queue_millis", "0"],
["active_shards_percent_as_number", "100.0"],
],
[
(0, "Pending tasks: 0.00", [("number_of_pending_tasks", 0, None, None)]),
(
0,
"Task max waiting: 0.00",
[("task_max_waiting_in_queue_millis", 0, None, None)],
),
(0, "Timed out: False"),
],
),
(
{},
None,
[
["cluster_name", "elasticsearch"],
["status", "yellow"],
["number_of_nodes", "5"],
["number_of_data_nodes", "5"],
],
[], # If there is no tasks information, there is no result (the state of the check turns to UNKNOWN)
),
],
)
def test_tasks_check_function(parameters, item, info, expected_result):
parsed = parse_elasticsearch_cluster_health(info)
assert (
list(check_elasticsearch_cluster_health_tasks(item, parameters, parsed)) == expected_result
)