Skip to content

Commit 10550c6

Browse files
Merge pull request #83 from Dynatrace-James-Kitson/management-zone-rule-type
correct rule type enums for management zones
2 parents 699b3ed + 29b094a commit 10550c6

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-16
lines changed

dynatrace/configuration_v1/management_zones.py

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
from typing import List, Dict, Any
18+
from enum import Enum
1819

1920
from dynatrace.environment_v2.schemas import ConfigurationMetadata
2021
from dynatrace.dynatrace_object import DynatraceObject
@@ -26,25 +27,68 @@
2627
ConditionKeyAttribute,
2728
ConditionKeyType,
2829
PropagationType,
29-
RuleType,
3030
)
3131

3232

33+
class RuleType(Enum):
34+
APPMON_SERVER = "APPMON_SERVER"
35+
APPMON_SYSTEM_PROFILE = "APPMON_SYSTEM_PROFILE"
36+
AWS_ACCOUNT = "AWS_ACCOUNT"
37+
AWS_APPLICATION_LOAD_BALANCER = "AWS_APPLICATION_LOAD_BALANCER"
38+
AWS_AUTO_SCALING_GROUP = "AWS_AUTO_SCALING_GROUP"
39+
AWS_CLASSIC_LOAD_BALANCER = "AWS_CLASSIC_LOAD_BALANCER"
40+
AWS_NETWORK_LOAD_BALANCER = "AWS_NETWORK_LOAD_BALANCER"
41+
AWS_RELATIONAL_DATABASE_SERVICE = "AWS_RELATIONAL_DATABASE_SERVICE"
42+
AZURE = "AZURE"
43+
BROWSER_MONITOR = "BROWSER_MONITOR"
44+
CLOUD_APPLICATION = "CLOUD_APPLICATION"
45+
CLOUD_APPLICATION_NAMESPACE = "CLOUD_APPLICATION_NAMESPACE"
46+
CLOUD_FOUNDRY_FOUNDATION = "CLOUD_FOUNDRY_FOUNDATION"
47+
CUSTOM_APPLICATION = "CUSTOM_APPLICATION"
48+
CUSTOM_DEVICE = "CUSTOM_DEVICE"
49+
CUSTOM_DEVICE_GROUP = "CUSTOM_DEVICE_GROUP"
50+
DATA_CENTER_SERVICE = "DATA_CENTER_SERVICE"
51+
ENTERPRISE_APPLICATION = "ENTERPRISE_APPLICATION"
52+
ESXI_HOST = "ESXI_HOST"
53+
EXTERNAL_MONITOR = "EXTERNAL_MONITOR"
54+
HOST = "HOST"
55+
HOST_GROUP = "HOST_GROUP"
56+
HTTP_MONITOR = "HTTP_MONITOR"
57+
KUBERNETES_CLUSTER = "KUBERNETES_CLUSTER"
58+
KUBERNETES_SERVICE = "KUBERNETES_SERVICE"
59+
MOBILE_APPLICATION = "MOBILE_APPLICATION"
60+
MULTIPROTOCOL_MONITOR = "MULTIPROTOCOL_MONITOR"
61+
OPENSTACK_ACCOUNT = "OPENSTACK_ACCOUNT"
62+
PROCESS_GROUP = "PROCESS_GROUP"
63+
QUEUE = "QUEUE"
64+
SERVICE = "SERVICE"
65+
WEB_APPLICATION = "WEB_APPLICATION"
66+
NONE = None
67+
68+
3369
class ManagementZoneService:
3470
ENDPOINT = "/api/config/v1/managementZones"
3571

3672
def __init__(self, http_client: HttpClient):
3773
self.__http_client = http_client
3874

39-
def list(self, page_size: int = 200) -> PaginatedList["ManagementZoneShortRepresentation"]:
75+
def list(
76+
self, page_size: int = 200
77+
) -> PaginatedList["ManagementZoneShortRepresentation"]:
4078
"""
4179
List all management zones.
4280
4381
:param page_size: The number of results per result page. Must be between 1 and 500
4482
Default value : 200
4583
"""
4684
params = {"pageSize": page_size}
47-
return PaginatedList(ManagementZoneShortRepresentation, self.__http_client, f"{self.ENDPOINT}", params, list_item="values")
85+
return PaginatedList(
86+
ManagementZoneShortRepresentation,
87+
self.__http_client,
88+
f"{self.ENDPOINT}",
89+
params,
90+
list_item="values",
91+
)
4892

4993
def get(self, management_zone_id: str) -> "ManagementZone":
5094
"""Gets the description of a management zone referenced by ID.
@@ -53,16 +97,22 @@ def get(self, management_zone_id: str) -> "ManagementZone":
5397
5498
:returns Event: the requested management zone
5599
"""
56-
response = self.__http_client.make_request(path=f"{self.ENDPOINT}/{management_zone_id}")
57-
return ManagementZone(raw_element=response.json(), http_client=self.__http_client)
100+
response = self.__http_client.make_request(
101+
path=f"{self.ENDPOINT}/{management_zone_id}"
102+
)
103+
return ManagementZone(
104+
raw_element=response.json(), http_client=self.__http_client
105+
)
58106

59107
def delete(self, management_zone_id: str):
60108
"""Deletes the specified management zone
61109
62110
:param networkzone_id: the ID of the management zone
63111
:return: HTTP response
64112
"""
65-
return self.__http_client.make_request(path=f"{self.ENDPOINT}/{management_zone_id}", method="DELETE")
113+
return self.__http_client.make_request(
114+
path=f"{self.ENDPOINT}/{management_zone_id}", method="DELETE"
115+
)
66116

67117

68118
class ComparisonBasic(DynatraceObject):
@@ -76,14 +126,18 @@ def _create_from_raw_data(self, raw_element: Dict[str, Any]):
76126

77127
class ConditionKey(DynatraceObject):
78128
def _create_from_raw_data(self, raw_element: Dict[str, Any]):
79-
self.attribute: ConditionKeyAttribute = ConditionKeyAttribute(raw_element.get("attribute"))
129+
self.attribute: ConditionKeyAttribute = ConditionKeyAttribute(
130+
raw_element.get("attribute")
131+
)
80132
self.type: ConditionKeyType = ConditionKeyType(raw_element.get("type"))
81133

82134

83135
class EntityRuleEngineCondition(DynatraceObject):
84136
def _create_from_raw_data(self, raw_element: Dict[str, Any]):
85137
self.key: ConditionKey = ConditionKey(raw_element=raw_element.get("key"))
86-
self.comparison_info: ComparisonBasic = ComparisonBasic(raw_element=raw_element.get("comparisonInfo"))
138+
self.comparison_info: ComparisonBasic = ComparisonBasic(
139+
raw_element=raw_element.get("comparisonInfo")
140+
)
87141

88142

89143
class EntitySelectorBasedManagementZoneRule(DynatraceObject):
@@ -98,21 +152,32 @@ def _create_from_raw_data(self, raw_element: Dict[str, Any]):
98152
self.type: RuleType = RuleType(raw_element.get("type"))
99153
self.enabled: bool = raw_element.get("enabled")
100154
self.value_format: str = raw_element.get("valueFormat")
101-
self.propagation_types: List[PropagationType] = [PropagationType(prop_type) for prop_type in (raw_element.get("propagationTypes") or [])]
155+
self.propagation_types: List[PropagationType] = [
156+
PropagationType(prop_type)
157+
for prop_type in (raw_element.get("propagationTypes") or [])
158+
]
102159
self.conditions: List[EntityRuleEngineCondition] = [
103-
EntityRuleEngineCondition(raw_element=condition) for condition in (raw_element.get("conditions") or [])
160+
EntityRuleEngineCondition(raw_element=condition)
161+
for condition in (raw_element.get("conditions") or [])
104162
]
105163

106164

107165
class ManagementZone(DynatraceObject):
108166
def _create_from_raw_data(self, raw_element: Dict[str, Any]):
109-
self.metadata: ConfigurationMetadata = ConfigurationMetadata(self._http_client, None, raw_element.get("metadata"))
167+
self.metadata: ConfigurationMetadata = ConfigurationMetadata(
168+
self._http_client, None, raw_element.get("metadata")
169+
)
110170
self.id: str = raw_element.get("id")
111171
self.name: str = raw_element.get("name")
112172
self.description: str = raw_element.get("description")
113-
self.rules: List[ManagementZoneRule] = [ManagementZoneRule(raw_element=rule) for rule in raw_element.get("rules")]
114-
self.entity_selector_based_rules: List[EntitySelectorBasedManagementZoneRule] = [
115-
EntitySelectorBasedManagementZoneRule(raw_element=rule) for rule in (raw_element.get("entitySelectorBasedRules") or [])
173+
self.rules: List[ManagementZoneRule] = [
174+
ManagementZoneRule(raw_element=rule) for rule in raw_element.get("rules")
175+
]
176+
self.entity_selector_based_rules: List[
177+
EntitySelectorBasedManagementZoneRule
178+
] = [
179+
EntitySelectorBasedManagementZoneRule(raw_element=rule)
180+
for rule in (raw_element.get("entitySelectorBasedRules") or [])
116181
]
117182

118183

@@ -121,5 +186,7 @@ def get_full_configuration(self):
121186
"""
122187
Get the full configuration for this management zone short representation.
123188
"""
124-
response = self._http_client.make_request(f"{ManagementZoneService.ENDPOINT}/{self.id}").json()
189+
response = self._http_client.make_request(
190+
f"{ManagementZoneService.ENDPOINT}/{self.id}"
191+
).json()
125192
return ManagementZone(http_client=self._http_client, raw_element=response)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="dt",
5-
version="1.1.62",
5+
version="1.1.63",
66
packages=find_packages(),
77
install_requires=["requests>=2.22"],
88
tests_require=["pytest", "mock", "tox"],

0 commit comments

Comments
 (0)