-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathmonitor.py
More file actions
153 lines (124 loc) · 5.55 KB
/
monitor.py
File metadata and controls
153 lines (124 loc) · 5.55 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
__all__ = [
"MonitorGroup",
]
from typing import Any, Optional
from linode_api4 import (
PaginatedList,
)
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 dashboards(
self, *filters, service_type: Optional[str] = None
) -> PaginatedList:
"""
Returns a list of dashboards. If `service_type` is provided, it fetches dashboards
for the specific service type. If None, it fetches all dashboards.
dashboards = client.monitor.dashboards()
dashboard = client.load(MonitorDashboard, 1)
dashboards_by_service = client.monitor.dashboards(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:
- All Dashboards: https://techdocs.akamai.com/linode-api/reference/get-dashboards-all
- Dashboards by Service: https://techdocs.akamai.com/linode-api/reference/get-dashboards
:param service_type: The service type to get dashboards for.
:type service_type: Optional[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: A list of Dashboards.
:rtype: PaginatedList of Dashboard
"""
endpoint = (
f"/monitor/services/{service_type}/dashboards"
if service_type
else "/monitor/dashboards"
)
return self.client._get_and_filter(
MonitorDashboard,
*filters,
endpoint=endpoint,
)
def services(
self, *filters, service_type: Optional[str] = None
) -> list[MonitorService]:
"""
Lists services supported by ACLP.
supported_services = client.monitor.services()
service_details = client.monitor.services(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
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: Optional[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
"""
endpoint = (
f"/monitor/services/{service_type}"
if service_type
else "/monitor/services"
)
return self.client._get_and_filter(
MonitorService,
*filters,
endpoint=endpoint,
)
def metric_definitions(
self, service_type: str, *filters
) -> list[MonitorMetricsDefinition]:
"""
Returns metrics for a specific service type.
metrics = client.monitor.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[Any]
) -> MonitorServiceToken:
"""
Returns a JWE Token for a specific service type.
token = client.monitor.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: any
: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"])