cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can I use API to realize Put Metric events setting?

kanna
Visitor

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.

2 REPLIES 2

ChadTurner
DynaMight Legend
DynaMight Legend

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. 

ChadTurner_0-1692190481169.png

 

-Chad

mark_bley
Dynatrace Champion
Dynatrace Champion

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"
    }
]

Featured Posts