-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathmonitor_service.py
More file actions
170 lines (127 loc) · 6.46 KB
/
monitor_service.py
File metadata and controls
170 lines (127 loc) · 6.46 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
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import (
MonitorDashboard,
MonitorMetricsDefinition,
MonitorService,
MonitorServiceToken,
)
class MonitorGroup(Group):
"""
Encapsulates Monitor-related methods of the :any:`LinodeClient`.
This group contains all features beneath the `/monitor` group in the API v4.
"""
def list_monitor_dashboards(self, *filters) -> list[MonitorDashboard]:
"""
Returns a list of dashboards.
dashboards = client.monitor_service.list_monitor_dashboards()
dashboard = client.load(MonitorDashboard, 1)
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards-all
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A list of Dashboards.
:rtype: PaginatedList of Dashboard
"""
return self.client._get_and_filter(MonitorDashboard, *filters)
def list_dashboards_by_service(
self, service_type: str, *filters
) -> list[MonitorDashboard]:
"""
Returns a list of dashboards for a particular service.
dashboard_by_service = client.monitor_service.list_dashboards_by_service(service_type="dbaas")
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards
:param service_type: The service type to get dashboards for.
:type service_type: str
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: Dashboards filtered by Service Type.
:rtype: PaginatedList of the Dashboards
"""
return self.client._get_and_filter(
MonitorDashboard,
*filters,
endpoint=f"/monitor/services/{service_type}/dashboards",
)
def list_supported_services(self, *filters) -> list[MonitorService]:
"""
Returns a list of services supported by ACLP.
supported_services = client.monitor_service.list_supported_services()
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A list of Supported Services
:rtype: PaginatedList of Services
"""
return self.client._get_and_filter(MonitorService, *filters)
def list_service_by_type(
self, service_type: str, *filters
) -> list[MonitorService]:
"""
Lists monitor services by a given service_type
service_details = client.monitor_service.list_service_by_type(service_type="dbaas")
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services-for-service-type
:param service_type: The service type to get details for.
:type service_type: str
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: Lists monitor services by a given service_type
:rtype: PaginatedList of the Services
"""
return self.client._get_and_filter(
MonitorService,
*filters,
endpoint=f"/monitor/services/{service_type}",
)
def list_metric_definitions(
self, service_type: str, *filters
) -> list[MonitorMetricsDefinition]:
"""
Returns metrics for a specific service type.
metrics = client.monitor_service.list_metric_definitions(service_type="dbaas")
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information
:param service_type: The service type to get metrics for.
:type service_type: str
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: Returns a List of metrics for a service
:rtype: PaginatedList of metrics
"""
return self.client._get_and_filter(
MonitorMetricsDefinition,
*filters,
endpoint=f"/monitor/services/{service_type}/metric-definitions",
)
def create_token(
self, service_type: str, entity_ids: list
) -> MonitorServiceToken:
"""
Returns a JWE Token for a specific service type.
token = client.monitor_service.create_token(service_type="dbaas", entity_ids=[1234])
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token
:param service_type: The service type to create token for.
:type service_type: str
:param entity_ids: The list of entity IDs for which the token is valid.
:type entity_ids: list of int
:returns: Returns a token for a service
:rtype: str
"""
params = {"entity_ids": entity_ids}
result = self.client.post(
f"/monitor/services/{service_type}/token", data=params
)
if "token" not in result:
raise UnexpectedResponseError(
"Unexpected response when creating token!", json=result
)
return MonitorServiceToken(token=result["token"])