15 Aug 2023 06:48 AM - last edited on 16 Aug 2023 08:43 AM by MaciejNeumann
Click the API on the page of Metric events, and the system gives the method of obtaining page data by default, but if I want to realize new Metric events through API, can it be realized? Because put/settings/objects/{objectid} in API V2.
Updates an existing settings object and POST /settings/objects Creates a new settings object didn't make it clear.
Solved! Go to Solution.
16 Aug 2023 01:54 PM
I'm not 100% of the true ask of this question but If you are looking to Post new Custom Events for alerting, It can be done via the Environment V2 > Settings - Objects, From there you will use builtin:anomaly-detection.metric-events as the Schema ID and then get the ID of the item you want. Thake that ID and get the settings of that object ID, edit and report it as needed or even create a net new set up via the Posting option.
21 Aug 2023 12:28 PM
Creating a new metric event through the API can be achieved like follow:
(This is just a curl example with some dummy payload, you would need to adjust fields to your needs)
curl --location --request POST 'https://{environmentid}.live.dynatrace.com/api/v2/settings/objects?validateOnly=false' \
--header 'accept: application/json; charset=utf-8' \
--header 'Authorization: Api-Token dt0c01.5VXCARPRP52BZNJVBUDSMQA5....' \
--header 'Content-Type: application/json; charset=utf-8' \
--data-raw '[
{
"scope": "environment",
"schemaId": "builtin:anomaly-detection.metric-events",
"value": {
"enabled": false,
"summary": "DEMO ALERT",
"queryDefinition": {
"type": "METRIC_KEY",
"metricKey": "builtin:host.cpu.usage",
"aggregation": "AVG",
"entityFilter": {
"conditions": []
},
"dimensionFilter": []
},
"modelProperties": {
"type": "STATIC_THRESHOLD",
"threshold": 1,
"alertOnNoData": false,
"alertCondition": "ABOVE",
"violatingSamples": 1,
"samples": 3,
"dealertingSamples": 3
},
"eventTemplate": {
"title": "DEMO TITLE",
"description": "The {metricname} value of {severity} was {alert_condition} your custom threshold of {threshold}.",
"eventType": "RESOURCE",
"davisMerge": true,
"metadata": []
},
"eventEntityDimensionKey": "dt.entity.host"
}
}
]'
The response on successful creation looks like this:
[
{
"code": 200,
"objectId": "vu9U3hXa3q0AAAABACdidWlsdGluOmFub21hbHktZGV0ZWN0aW9uLm1ldHJpYy1ldmVudHMABnRlbmFudAAGdGVuYW50ACRiN2JhOTU2Zi0xNTMwLTNiZTQtYWNiYS0zMjc5YThjODk3ZmG-71TeFdrerQ"
}
]