-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathmonitor_test.py
More file actions
172 lines (155 loc) · 7.65 KB
/
monitor_test.py
File metadata and controls
172 lines (155 loc) · 7.65 KB
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
import datetime
from test.unit.base import ClientBaseCase
from linode_api4.objects import AlertChannel, MonitorDashboard, MonitorService
class MonitorTest(ClientBaseCase):
"""
Tests the methods of MonitorServiceSupported class
"""
def test_supported_services(self):
"""
Test the services supported by monitor
"""
service = self.client.monitor.services()
self.assertEqual(len(service), 1)
self.assertEqual(service[0].label, "Databases")
self.assertEqual(service[0].service_type, "dbaas")
def test_dashboard_by_ID(self):
"""
Test the dashboard by ID API
"""
dashboard = self.client.load(MonitorDashboard, 1)
self.assertEqual(dashboard.type, "standard")
self.assertEqual(
dashboard.created, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboard.id, 1)
self.assertEqual(dashboard.label, "Resource Usage")
self.assertEqual(dashboard.service_type, "dbaas")
self.assertEqual(
dashboard.updated, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboard.widgets[0].aggregate_function, "sum")
self.assertEqual(dashboard.widgets[0].chart_type, "area")
self.assertEqual(dashboard.widgets[0].color, "default")
self.assertEqual(dashboard.widgets[0].label, "CPU Usage")
self.assertEqual(dashboard.widgets[0].metric, "cpu_usage")
self.assertEqual(dashboard.widgets[0].size, 12)
self.assertEqual(dashboard.widgets[0].unit, "%")
self.assertEqual(dashboard.widgets[0].y_label, "cpu_usage")
self.assertEqual(dashboard.widgets[0].group_by, ["entity_id"])
self.assertIsNone(dashboard.widgets[0].filters)
def test_dashboard_by_service_type(self):
dashboards = self.client.monitor.dashboards(service_type="dbaas")
self.assertEqual(dashboards[0].type, "standard")
self.assertEqual(
dashboards[0].created, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboards[0].id, 1)
self.assertEqual(dashboards[0].label, "Resource Usage")
self.assertEqual(dashboards[0].service_type, "dbaas")
self.assertEqual(
dashboards[0].updated, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboards[0].widgets[0].aggregate_function, "sum")
self.assertEqual(dashboards[0].widgets[0].chart_type, "area")
self.assertEqual(dashboards[0].widgets[0].color, "default")
self.assertEqual(dashboards[0].widgets[0].label, "CPU Usage")
self.assertEqual(dashboards[0].widgets[0].metric, "cpu_usage")
self.assertEqual(dashboards[0].widgets[0].size, 12)
self.assertEqual(dashboards[0].widgets[0].unit, "%")
self.assertEqual(dashboards[0].widgets[0].y_label, "cpu_usage")
self.assertEqual(dashboards[0].widgets[0].group_by, ["entity_id"])
self.assertIsNone(dashboards[0].widgets[0].filters)
# Test the second widget which has filters
self.assertEqual(dashboards[0].widgets[1].label, "Memory Usage")
self.assertEqual(dashboards[0].widgets[1].group_by, ["entity_id"])
self.assertIsNotNone(dashboards[0].widgets[1].filters)
self.assertEqual(len(dashboards[0].widgets[1].filters), 1)
self.assertEqual(
dashboards[0].widgets[1].filters[0].dimension_label, "pattern"
)
self.assertEqual(dashboards[0].widgets[1].filters[0].operator, "in")
self.assertEqual(
dashboards[0].widgets[1].filters[0].value, "publicout,privateout"
)
def test_get_all_dashboards(self):
dashboards = self.client.monitor.dashboards()
self.assertEqual(dashboards[0].type, "standard")
self.assertEqual(
dashboards[0].created, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboards[0].id, 1)
self.assertEqual(dashboards[0].label, "Resource Usage")
self.assertEqual(dashboards[0].service_type, "dbaas")
self.assertEqual(
dashboards[0].updated, datetime.datetime(2024, 10, 10, 5, 1, 58)
)
self.assertEqual(dashboards[0].widgets[0].aggregate_function, "sum")
self.assertEqual(dashboards[0].widgets[0].chart_type, "area")
self.assertEqual(dashboards[0].widgets[0].color, "default")
self.assertEqual(dashboards[0].widgets[0].label, "CPU Usage")
self.assertEqual(dashboards[0].widgets[0].metric, "cpu_usage")
self.assertEqual(dashboards[0].widgets[0].size, 12)
self.assertEqual(dashboards[0].widgets[0].unit, "%")
self.assertEqual(dashboards[0].widgets[0].y_label, "cpu_usage")
self.assertEqual(dashboards[0].widgets[0].group_by, ["entity_id"])
self.assertIsNone(dashboards[0].widgets[0].filters)
def test_specific_service_details(self):
data = self.client.load(MonitorService, "dbaas")
self.assertEqual(data.label, "Databases")
self.assertEqual(data.service_type, "dbaas")
# Test alert configuration
self.assertIsNotNone(data.alert)
self.assertEqual(data.alert.polling_interval_seconds, [300])
self.assertEqual(data.alert.evaluation_period_seconds, [300])
self.assertEqual(data.alert.scope, ["entity"])
def test_metric_definitions(self):
metrics = self.client.monitor.metric_definitions(service_type="dbaas")
self.assertEqual(
metrics[0].available_aggregate_functions,
["max", "avg", "min", "sum"],
)
self.assertTrue(metrics[0].is_alertable)
self.assertEqual(metrics[0].label, "CPU Usage")
self.assertEqual(metrics[0].metric, "cpu_usage")
self.assertEqual(metrics[0].metric_type, "gauge")
self.assertEqual(metrics[0].scrape_interval, "60s")
self.assertEqual(metrics[0].unit, "percent")
self.assertEqual(metrics[0].dimensions[0].dimension_label, "node_type")
self.assertEqual(metrics[0].dimensions[0].label, "Node Type")
self.assertEqual(
metrics[0].dimensions[0].values, ["primary", "secondary"]
)
def test_create_token(self):
with self.mock_post("/monitor/services/dbaas/token") as m:
self.client.monitor.create_token(
service_type="dbaas", entity_ids=[189690, 188020]
)
self.assertEqual(m.return_dct["token"], "abcdefhjigkfghh")
with self.mock_post("/monitor/services/linode/token") as m:
self.client.monitor.create_token(
service_type="linode", entity_ids=["compute-instance-1"]
)
self.assertEqual(m.return_dct["token"], "abcdefhjigkfghh")
def test_alert_channels(self):
channels = self.client.monitor.alert_channels()
self.assertEqual(len(channels), 1)
self.assertIsInstance(channels[0], AlertChannel)
self.assertEqual(channels[0].id, 123)
self.assertEqual(channels[0].label, "alert notification channel")
self.assertEqual(channels[0].type, "user")
self.assertEqual(channels[0].channel_type, "email")
self.assertIsNotNone(channels[0].details)
self.assertIsNotNone(channels[0].details.email)
self.assertEqual(
channels[0].details.email.usernames,
["admin-user1", "admin-user2"],
)
self.assertEqual(channels[0].details.email.recipient_type, "user")
self.assertIsNotNone(channels[0].alerts)
self.assertEqual(
channels[0].alerts.url,
"/monitor/alert-channels/123/alerts",
)
self.assertEqual(channels[0].alerts.alert_count, 0)
self.assertFalse(hasattr(channels[0], "content"))