-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from Dynatrace-James-Kitson/tweak-settings
settings changes to align with API and rest of project
- Loading branch information
Showing
10 changed files
with
299 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,59 @@ | ||
from datetime import datetime | ||
|
||
import dynatrace.environment_v2.settings as st | ||
from dynatrace.environment_v2.settings import SettingsObject, SettingsObjectCreate | ||
from dynatrace import Dynatrace | ||
from dynatrace.pagination import PaginatedList | ||
payload = {"additionalInformation": [], | ||
"contactDetails":[{"email": 'unittest@contoso.com', "integrationType": "EMAIL"}], | ||
"description": 'unittest', | ||
"identifier":'unittest', | ||
"links": [], | ||
"name": 'unittest', | ||
"responsibilities": {"development": False, | ||
"infrastructure": False, | ||
"lineOfBusiness": True, | ||
"operations": False, | ||
"security": False}, | ||
"supplementaryIdentifiers": [] } | ||
|
||
settings_dict = { | ||
"enabled": True, | ||
"summary": "DT API TEST 22", | ||
"queryDefinition": { | ||
"type": "METRIC_KEY", | ||
"metricKey": "netapp.ontap.node.fru.state", | ||
"aggregation": "AVG", | ||
"entityFilter": { | ||
"dimensionKey": "dt.entity.netapp_ontap:fru", | ||
"conditions": [], | ||
}, | ||
"dimensionFilter": [], | ||
}, | ||
"modelProperties": { | ||
"type": "STATIC_THRESHOLD", | ||
"threshold": 100.0, | ||
"alertOnNoData": False, | ||
"alertCondition": "BELOW", | ||
"violatingSamples": 3, | ||
"samples": 5, | ||
"dealertingSamples": 5, | ||
}, | ||
"eventTemplate": { | ||
"title": "OnTap {dims:type} {dims:fru_id} is in Error State", | ||
"description": "OnTap field replaceable unit (FRU) {dims:type} with id {dims:fru_id} on node {dims:node} in cluster {dims:cluster} is in an error state.\n", | ||
"eventType": "RESOURCE", | ||
"davisMerge": True, | ||
"metadata": [], | ||
}, | ||
"eventEntityDimensionKey": "dt.entity.netapp_ontap:fru", | ||
} | ||
settings_object = SettingsObjectCreate("builtin:anomaly-detection.metric-events", settings_dict, "environment") | ||
test_object_id = "vu9U3hXa3q0AAAABACdidWlsdGluOmFub21hbHktZGV0ZWN0aW9uLm1ldHJpYy1ldmVudHMABnRlbmFudAAGdGVuYW50ACRiYmYzZWNhNy0zMmZmLTM2ZTEtOTFiOS05Y2QxZjE3OTc0YjC-71TeFdrerQ" | ||
|
||
def test_list_objects(dt: Dynatrace): | ||
settings = dt.settings.list_objects(schema_id="builtin:ownership.teams") | ||
settings = dt.settings.list_objects(schema_id="builtin:anomaly-detection.metric-events") | ||
assert isinstance(settings, PaginatedList) | ||
assert len(list(settings)) == 1 | ||
assert all(isinstance(s, st.Settings) for s in settings) | ||
assert len(list(settings)) == 2 | ||
assert all(isinstance(s, SettingsObject) for s in settings) | ||
|
||
def test_get_object(dt: Dynatrace): | ||
setting = dt.settings.get_object(object_id="vu9U3hXa3q0AAAABABdidWlsdGluOm93bmVyc2hpcC50ZWFtcwAGdGVuYW50AAZ0ZW5hbnQAJGVjN2UyNTdhLWM5MTktM2YzMC05NWFiLTliMzNkMmQwZGRkY77vVN4V2t6t") | ||
assert isinstance(setting, st.Settings) | ||
setting = dt.settings.get_object(object_id=test_object_id) | ||
assert isinstance(setting, SettingsObject) | ||
assert setting.schema_version == "1.0.16" | ||
|
||
def test_post_object(dt: Dynatrace): | ||
|
||
response = dt.settings.create_object(external_id='unittest',object_id='unittest',schema_id="builtin:ownership.teams",schema_version="1.0.6",scope="environment", value=payload,validate_only=False) | ||
response = dt.settings.create_object(body=settings_object) | ||
assert response[0].get("code") == 200 | ||
assert response[0].get("code") is not None | ||
|
||
def test_put_object(dt: Dynatrace): | ||
payload["identifier"] = "unittestupdate" | ||
response = dt.settings.update_object("unittest",payload) | ||
print(response) | ||
response = dt.settings.update_object(test_object_id, settings_object) | ||
print(response) | ||
|
69 changes: 69 additions & 0 deletions
69
test/mock_data/GET_api_v2_settings_objects_1eafd8dc0bf2543.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"items": [ | ||
{ | ||
"objectId": "vu9U3hXa3q0AAAABACdidWlsdGluOmFub21hbHktZGV0ZWN0aW9uLm1ldHJpYy1ldmVudHMABnRlbmFudAAGdGVuYW50ACQ4OWNhMmY2Ny0wY2Q3LTM0MzAtYmU5Ny1kOTg4YTRmMWRiYWa-71TeFdrerQ", | ||
"value": { | ||
"enabled": true, | ||
"summary": "OnTap Node Field Replaceable Unit in Error State", | ||
"queryDefinition": { | ||
"type": "METRIC_KEY", | ||
"metricKey": "netapp.ontap.node.fru.state", | ||
"aggregation": "AVG", | ||
"entityFilter": { | ||
"dimensionKey": "dt.entity.netapp_ontap:fru", | ||
"conditions": [] | ||
}, | ||
"dimensionFilter": [] | ||
}, | ||
"modelProperties": { | ||
"type": "STATIC_THRESHOLD", | ||
"threshold": 100.0, | ||
"alertOnNoData": false, | ||
"alertCondition": "BELOW", | ||
"violatingSamples": 3, | ||
"samples": 5, | ||
"dealertingSamples": 5 | ||
}, | ||
"eventTemplate": { | ||
"title": "OnTap {dims:type} {dims:fru_id} is in Error State", | ||
"description": "OnTap field replaceable unit (FRU) {dims:type} with id {dims:fru_id} on node {dims:node} in cluster {dims:cluster} is in an error state.\n", | ||
"eventType": "RESOURCE", | ||
"davisMerge": true, | ||
"metadata": [] | ||
}, | ||
"eventEntityDimensionKey": "dt.entity.netapp_ontap:fru" | ||
} | ||
}, | ||
{ | ||
"objectId": "vu9U3hXa3q0AAAABACdidWlsdGluOmFub21hbHktZGV0ZWN0aW9uLm1ldHJpYy1ldmVudHMABnRlbmFudAAGdGVuYW50ACQ5MjRiNjdiYS00OGQ1LTM0NDctODg4Zi05NzUzMzg5NzcxMze-71TeFdrerQ", | ||
"value": { | ||
"enabled": false, | ||
"summary": "High outbound bandwidth utilization", | ||
"queryDefinition": { | ||
"type": "METRIC_SELECTOR", | ||
"metricSelector": "func:com.dynatrace.extension.snmp-generic-cisco-device.if.out.bandwidth" | ||
}, | ||
"modelProperties": { | ||
"type": "STATIC_THRESHOLD", | ||
"threshold": 90.0, | ||
"alertOnNoData": false, | ||
"alertCondition": "ABOVE", | ||
"violatingSamples": 3, | ||
"samples": 5, | ||
"dealertingSamples": 5 | ||
}, | ||
"eventTemplate": { | ||
"title": "High outbound bandwidth utilization", | ||
"description": "The {metricname} value of {severity} was {alert_condition} your custom threshold of {threshold}.", | ||
"eventType": "CUSTOM_ALERT", | ||
"davisMerge": false, | ||
"metadata": [] | ||
}, | ||
"eventEntityDimensionKey": "dt.entity.snmp:com_dynatrace_extension_snmp_generic_cisco_network_interface", | ||
"legacyId": "E|649d5713-380b-6751-a64f-6904a2c4cd2f" | ||
} | ||
} | ||
], | ||
"totalCount": 25, | ||
"pageSize": 100 | ||
} |
Oops, something went wrong.