Chilkat Online Tools

PureBasic / Datadog API Collection / Create a monitor

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    ; The following JSON is sent in the request body.

    ; {
    ;   "message": "You may need to add web hosts if this is consistently high.",
    ;   "name": "Bytes received on host0",
    ;   "options": {
    ;     "no_data_timeframe": 20,
    ;     "notify_no_data": true
    ;   },
    ;   "query": "avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100",
    ;   "tags": [
    ;     "app:webserver",
    ;     "frontend"
    ;   ],
    ;   "type": "query alert"
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"message","You may need to add web hosts if this is consistently high.")
    CkJsonObject::ckUpdateString(json,"name","Bytes received on host0")
    CkJsonObject::ckUpdateInt(json,"options.no_data_timeframe",20)
    CkJsonObject::ckUpdateBool(json,"options.notify_no_data",1)
    CkJsonObject::ckUpdateString(json,"query","avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100")
    CkJsonObject::ckUpdateString(json,"tags[0]","app:webserver")
    CkJsonObject::ckUpdateString(json,"tags[1]","frontend")
    CkJsonObject::ckUpdateString(json,"type","query alert")

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckPostJson3(http,"https://api.app.ddog-gov.com/api/v1/monitor","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "type": "query alert",
    ;   "query": "avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100",
    ;   "created": "1989-12-01T14:28:43.831Z",
    ;   "creator": {
    ;     "email": "officia sunt",
    ;     "handle": "pariatur",
    ;     "name": "aute do"
    ;   },
    ;   "deleted": "2020-10-30T20:46:24.520Z",
    ;   "id": -50675854,
    ;   "matching_downtimes": [
    ;     {
    ;       "id": 1625,
    ;       "end": 1412792983,
    ;       "scope": [
    ;         "env:staging"
    ;       ],
    ;       "start": 1412792983
    ;     },
    ;     {
    ;       "id": 1625,
    ;       "end": 1412792983,
    ;       "scope": [
    ;         "env:staging"
    ;       ],
    ;       "start": 1412792983
    ;     }
    ;   ],
    ;   "message": "ullamco incididunt cupidatat",
    ;   "modified": "1981-03-27T05:04:03.098Z",
    ;   "multi": false,
    ;   "name": "My monitor",
    ;   "options": {
    ;     "aggregation": {
    ;       "group_by": "host",
    ;       "metric": "metrics.name",
    ;       "type": "count"
    ;     },
    ;     "device_ids": [
    ;       "mobile_small",
    ;       "chrome.tablet"
    ;     ],
    ;     "enable_logs_sample": false,
    ;     "enable_samples": false,
    ;     "escalation_message": "none",
    ;     "evaluation_delay": -52819274,
    ;     "group_retention_duration": "dolor Lorem qui",
    ;     "groupby_simple_monitor": false,
    ;     "include_tags": true,
    ;     "locked": false,
    ;     "min_failure_duration": 0,
    ;     "min_location_failed": 1,
    ;     "new_group_delay": -94315945,
    ;     "new_host_delay": 300,
    ;     "no_data_timeframe": -86360342,
    ;     "notification_preset_name": "show_all",
    ;     "notify_audit": false,
    ;     "notify_by": [
    ;       "labore dolore",
    ;       "deserunt commodo consectetur"
    ;     ],
    ;     "notify_no_data": false,
    ;     "on_missing_data": "resolve",
    ;     "renotify_interval": null,
    ;     "renotify_occurrences": 56355858,
    ;     "renotify_statuses": [
    ;       "warn",
    ;       "no data"
    ;     ],
    ;     "require_full_window": false,
    ;     "scheduling_options": {
    ;       "evaluation_window": {
    ;         "day_starts": "04:00",
    ;         "hour_starts": 0,
    ;         "month_starts": 1
    ;       }
    ;     },
    ;     "silenced": {
    ;       "non_6f_": 77287100
    ;     },
    ;     "synthetics_check_id": "culpa in laborum irure",
    ;     "threshold_windows": {
    ;       "recovery_window": "culpa cupidatat Lorem ut",
    ;       "trigger_window": "fugiat officia mollit esse quis"
    ;     },
    ;     "thresholds": {
    ;       "critical": -44507487.0891542,
    ;       "critical_recovery": 94365870.17342958,
    ;       "ok": 26645340.31156695,
    ;       "unknown": -32772943.396166816,
    ;       "warning": 75330874.10211122,
    ;       "warning_recovery": 30665996.226613894
    ;     },
    ;     "timeout_h": null,
    ;     "variables": [
    ;       {
    ;         "data_source": "rum",
    ;         "compute": {
    ;           "aggregation": "avg",
    ;           "interval": 60000,
    ;           "metric": "@duration"
    ;         },
    ;         "name": "query_errors",
    ;         "group_by": [
    ;           {
    ;             "facet": "status",
    ;             "limit": 10,
    ;             "sort": {
    ;               "aggregation": "avg",
    ;               "metric": "minim tempor i",
    ;               "order": "desc"
    ;             }
    ;           },
    ;           {
    ;             "facet": "status",
    ;             "limit": 10,
    ;             "sort": {
    ;               "aggregation": "avg",
    ;               "metric": "Ut fugiat officia",
    ;               "order": "desc"
    ;             }
    ;           }
    ;         ],
    ;         "indexes": [
    ;           "days-3",
    ;           "days-7"
    ;         ],
    ;         "search": {
    ;           "query": "service:query"
    ;         }
    ;       },
    ;       {
    ;         "data_source": "rum",
    ;         "compute": {
    ;           "aggregation": "avg",
    ;           "interval": 60000,
    ;           "metric": "@duration"
    ;         },
    ;         "name": "query_errors",
    ;         "group_by": [
    ;           {
    ;             "facet": "status",
    ;             "limit": 10,
    ;             "sort": {
    ;               "aggregation": "avg",
    ;               "metric": "do velit",
    ;               "order": "desc"
    ;             }
    ;           },
    ;           {
    ;             "facet": "status",
    ;             "limit": 10,
    ;             "sort": {
    ;               "aggregation": "avg",
    ;               "metric": "amet proident anim in",
    ;               "order": "desc"
    ;             }
    ;           }
    ;         ],
    ;         "indexes": [
    ;           "days-3",
    ;           "days-7"
    ;         ],
    ;         "search": {
    ;           "query": "service:query"
    ;         }
    ;       }
    ;     ]
    ;   },
    ;   "overall_state": "Warn",
    ;   "priority": 1,
    ;   "restricted_roles": [
    ;     "enim qui cillum est",
    ;     "quis ut"
    ;   ],
    ;   "state": {
    ;     "groups": {
    ;       "Lorem_1": {
    ;         "last_nodata_ts": -12653992,
    ;         "last_notified_ts": -66141067,
    ;         "last_resolved_ts": 5643925,
    ;         "last_triggered_ts": -6121593,
    ;         "name": "dolore nulla i",
    ;         "status": "OK"
    ;       },
    ;       "nisi_c43": {
    ;         "last_nodata_ts": -66061060,
    ;         "last_notified_ts": -86988012,
    ;         "last_resolved_ts": -39919633,
    ;         "last_triggered_ts": 13467862,
    ;         "name": "Ut fugiat eiusmod anim",
    ;         "status": "Ignored"
    ;       },
    ;       "minim_c": {
    ;         "last_nodata_ts": 6509669,
    ;         "last_notified_ts": 39348490,
    ;         "last_resolved_ts": 13221088,
    ;         "last_triggered_ts": 21889420,
    ;         "name": "in velit Duis",
    ;         "status": "Alert"
    ;       }
    ;     }
    ;   },
    ;   "tags": [
    ;     "ex tempor",
    ;     "enim veniam dolore"
    ;   ]
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    v_end.i
    start.i
    j.i
    count_j.i
    strVal.s
    data_source.s
    Aggregation.s
    Interval.i
    computeMetric.s
    Query.s
    facet.s
    limit.i
    sortAggregation.s
    sortMetric.s
    Order.s

    v_type.s = CkJsonObject::ckStringOf(jResp,"type")
    query.s = CkJsonObject::ckStringOf(jResp,"query")
    created.s = CkJsonObject::ckStringOf(jResp,"created")
    v_Email.s = CkJsonObject::ckStringOf(jResp,"creator.email")
    Handle.s = CkJsonObject::ckStringOf(jResp,"creator.handle")
    Name.s = CkJsonObject::ckStringOf(jResp,"creator.name")
    deleted.s = CkJsonObject::ckStringOf(jResp,"deleted")
    id.i = CkJsonObject::ckIntOf(jResp,"id")
    message.s = CkJsonObject::ckStringOf(jResp,"message")
    modified.s = CkJsonObject::ckStringOf(jResp,"modified")
    multi.i = CkJsonObject::ckBoolOf(jResp,"multi")
    name.s = CkJsonObject::ckStringOf(jResp,"name")
    Group_by.s = CkJsonObject::ckStringOf(jResp,"options.aggregation.group_by")
    Metric.s = CkJsonObject::ckStringOf(jResp,"options.aggregation.metric")
    v_Type.s = CkJsonObject::ckStringOf(jResp,"options.aggregation.type")
    Enable_logs_sample.i = CkJsonObject::ckBoolOf(jResp,"options.enable_logs_sample")
    Enable_samples.i = CkJsonObject::ckBoolOf(jResp,"options.enable_samples")
    Escalation_message.s = CkJsonObject::ckStringOf(jResp,"options.escalation_message")
    Evaluation_delay.i = CkJsonObject::ckIntOf(jResp,"options.evaluation_delay")
    Group_retention_duration.s = CkJsonObject::ckStringOf(jResp,"options.group_retention_duration")
    Groupby_simple_monitor.i = CkJsonObject::ckBoolOf(jResp,"options.groupby_simple_monitor")
    Include_tags.i = CkJsonObject::ckBoolOf(jResp,"options.include_tags")
    Locked.i = CkJsonObject::ckBoolOf(jResp,"options.locked")
    Min_failure_duration.i = CkJsonObject::ckIntOf(jResp,"options.min_failure_duration")
    Min_location_failed.i = CkJsonObject::ckIntOf(jResp,"options.min_location_failed")
    New_group_delay.i = CkJsonObject::ckIntOf(jResp,"options.new_group_delay")
    New_host_delay.i = CkJsonObject::ckIntOf(jResp,"options.new_host_delay")
    No_data_timeframe.i = CkJsonObject::ckIntOf(jResp,"options.no_data_timeframe")
    Notification_preset_name.s = CkJsonObject::ckStringOf(jResp,"options.notification_preset_name")
    Notify_audit.i = CkJsonObject::ckBoolOf(jResp,"options.notify_audit")
    Notify_no_data.i = CkJsonObject::ckBoolOf(jResp,"options.notify_no_data")
    On_missing_data.s = CkJsonObject::ckStringOf(jResp,"options.on_missing_data")
    Renotify_interval.s = CkJsonObject::ckStringOf(jResp,"options.renotify_interval")
    Renotify_occurrences.i = CkJsonObject::ckIntOf(jResp,"options.renotify_occurrences")
    Require_full_window.i = CkJsonObject::ckBoolOf(jResp,"options.require_full_window")
    Day_starts.s = CkJsonObject::ckStringOf(jResp,"options.scheduling_options.evaluation_window.day_starts")
    Hour_starts.i = CkJsonObject::ckIntOf(jResp,"options.scheduling_options.evaluation_window.hour_starts")
    Month_starts.i = CkJsonObject::ckIntOf(jResp,"options.scheduling_options.evaluation_window.month_starts")
    Non_6f_.i = CkJsonObject::ckIntOf(jResp,"options.silenced.non_6f_")
    Synthetics_check_id.s = CkJsonObject::ckStringOf(jResp,"options.synthetics_check_id")
    Recovery_window.s = CkJsonObject::ckStringOf(jResp,"options.threshold_windows.recovery_window")
    Trigger_window.s = CkJsonObject::ckStringOf(jResp,"options.threshold_windows.trigger_window")
    Critical.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.critical")
    Critical_recovery.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.critical_recovery")
    Ok.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.ok")
    Unknown.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.unknown")
    Warning.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.warning")
    Warning_recovery.s = CkJsonObject::ckStringOf(jResp,"options.thresholds.warning_recovery")
    Timeout_h.s = CkJsonObject::ckStringOf(jResp,"options.timeout_h")
    overall_state.s = CkJsonObject::ckStringOf(jResp,"overall_state")
    priority.i = CkJsonObject::ckIntOf(jResp,"priority")
    Last_nodata_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.Lorem_1.last_nodata_ts")
    Last_notified_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.Lorem_1.last_notified_ts")
    Last_resolved_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.Lorem_1.last_resolved_ts")
    Last_triggered_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.Lorem_1.last_triggered_ts")
    Lorem_1Name.s = CkJsonObject::ckStringOf(jResp,"state.groups.Lorem_1.name")
    Status.s = CkJsonObject::ckStringOf(jResp,"state.groups.Lorem_1.status")
    Nisi_c43Last_nodata_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.nisi_c43.last_nodata_ts")
    Nisi_c43Last_notified_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.nisi_c43.last_notified_ts")
    Nisi_c43Last_resolved_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.nisi_c43.last_resolved_ts")
    Nisi_c43Last_triggered_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.nisi_c43.last_triggered_ts")
    Nisi_c43Name.s = CkJsonObject::ckStringOf(jResp,"state.groups.nisi_c43.name")
    Nisi_c43Status.s = CkJsonObject::ckStringOf(jResp,"state.groups.nisi_c43.status")
    Minim_cLast_nodata_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.minim_c.last_nodata_ts")
    Minim_cLast_notified_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.minim_c.last_notified_ts")
    Minim_cLast_resolved_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.minim_c.last_resolved_ts")
    Minim_cLast_triggered_ts.i = CkJsonObject::ckIntOf(jResp,"state.groups.minim_c.last_triggered_ts")
    Minim_cName.s = CkJsonObject::ckStringOf(jResp,"state.groups.minim_c.name")
    Minim_cStatus.s = CkJsonObject::ckStringOf(jResp,"state.groups.minim_c.status")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"matching_downtimes")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckIntOf(jResp,"matching_downtimes[i].id")
        v_end = CkJsonObject::ckIntOf(jResp,"matching_downtimes[i].end")
        start = CkJsonObject::ckIntOf(jResp,"matching_downtimes[i].start")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"matching_downtimes[i].scope")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"matching_downtimes[i].scope[j]")
            j = j + 1
        Wend
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"options.device_ids")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"options.device_ids[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"options.notify_by")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"options.notify_by[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"options.renotify_statuses")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"options.renotify_statuses[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"options.variables")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        data_source = CkJsonObject::ckStringOf(jResp,"options.variables[i].data_source")
        Aggregation = CkJsonObject::ckStringOf(jResp,"options.variables[i].compute.aggregation")
        Interval = CkJsonObject::ckIntOf(jResp,"options.variables[i].compute.interval")
        computeMetric = CkJsonObject::ckStringOf(jResp,"options.variables[i].compute.metric")
        name = CkJsonObject::ckStringOf(jResp,"options.variables[i].name")
        Query = CkJsonObject::ckStringOf(jResp,"options.variables[i].search.query")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"options.variables[i].group_by")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            facet = CkJsonObject::ckStringOf(jResp,"options.variables[i].group_by[j].facet")
            limit = CkJsonObject::ckIntOf(jResp,"options.variables[i].group_by[j].limit")
            sortAggregation = CkJsonObject::ckStringOf(jResp,"options.variables[i].group_by[j].sort.aggregation")
            sortMetric = CkJsonObject::ckStringOf(jResp,"options.variables[i].group_by[j].sort.metric")
            Order = CkJsonObject::ckStringOf(jResp,"options.variables[i].group_by[j].sort.order")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"options.variables[i].indexes")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"options.variables[i].indexes[j]")
            j = j + 1
        Wend
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"restricted_roles")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"restricted_roles[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"tags")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"tags[i]")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "message": "You may need to add web hosts if this is consistently high.",
  "name": "Bytes received on host0",
  "options": {
    "no_data_timeframe": 20,
    "notify_no_data": true
  },
  "query": "avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100",
  "tags": [
    "app:webserver",
    "frontend"
  ],
  "type": "query alert"
}'
https://api.app.ddog-gov.com/api/v1/monitor

Postman Collection Item JSON

{
  "name": "Create a monitor",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"message\": \"You may need to add web hosts if this is consistently high.\",\n  \"name\": \"Bytes received on host0\",\n  \"options\": {\n    \"no_data_timeframe\": 20,\n    \"notify_no_data\": true\n  },\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"tags\": [\n    \"app:webserver\",\n    \"frontend\"\n  ],\n  \"type\": \"query alert\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/monitor",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "monitor"
      ]
    },
    "description": "Create a monitor using the specified options.\n\n#### Monitor Types\n\nThe type of monitor chosen from:\n\n- anomaly: `query alert`\n- APM: `query alert` or `trace-analytics alert`\n- composite: `composite`\n- custom: `service check`\n- event: `event alert`\n- forecast: `query alert`\n- host: `service check`\n- integration: `query alert` or `service check`\n- live process: `process alert`\n- logs: `log alert`\n- metric: `query alert`\n- network: `service check`\n- outlier: `query alert`\n- process: `service check`\n- rum: `rum alert`\n- SLO: `slo alert`\n- watchdog: `event alert`\n- event-v2: `event-v2 alert`\n- audit: `audit alert`\n- error-tracking: `error-tracking alert`\n- database-monitoring: `database-monitoring alert`\n\n**Note**: Synthetic monitors are created through the Synthetics API. See the [Synthetics API] (https://docs.datadoghq.com/api/latest/synthetics/) documentation for more information.\n\n#### Query Types\n\n##### Metric Alert Query\n\nExample: `time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator #`\n\n- `time_aggr`: avg, sum, max, min, change, or pct_change\n- `time_window`: `last_#m` (with `#` between 1 and 10080 depending on the monitor type) or `last_#h`(with `#` between 1 and 168 depending on the monitor type) or `last_1d`, or `last_1w`\n- `space_aggr`: avg, sum, min, or max\n- `tags`: one or more tags (comma-separated), or *\n- `key`: a 'key' in key:value tag syntax; defines a separate alert for each tag in the group (multi-alert)\n- `operator`: <, <=, >, >=, ==, or !=\n- `#`: an integer or decimal number used to set the threshold\n\nIf you are using the `_change_` or `_pct_change_` time aggregator, instead use `change_aggr(time_aggr(time_window),\ntimeshift):space_aggr:metric{tags} [by {key}] operator #` with:\n\n- `change_aggr` change, pct_change\n- `time_aggr` avg, sum, max, min [Learn more](https://docs.datadoghq.com/monitors/create/types/#define-the-conditions)\n- `time_window` last\\_#m (between 1 and 2880 depending on the monitor type), last\\_#h (between 1 and 48 depending on the monitor type), or last_#d (1 or 2)\n- `timeshift` #m_ago (5, 10, 15, or 30), #h_ago (1, 2, or 4), or 1d_ago\n\nUse this to create an outlier monitor using the following query:\n`avg(last_30m):outliers(avg:system.cpu.user{role:es-events-data} by {host}, 'dbscan', 7) > 0`\n\n##### Service Check Query\n\nExample: `\"check\".over(tags).last(count).by(group).count_by_status()`\n\n- `check` name of the check, for example `datadog.agent.up`\n- `tags` one or more quoted tags (comma-separated), or \"*\". for example: `.over(\"env:prod\", \"role:db\")`; `over` cannot be blank.\n- `count` must be at greater than or equal to your max threshold (defined in the `options`). It is limited to 100.\nFor example, if you've specified to notify on 1 critical, 3 ok, and 2 warn statuses, `count` should be at least 3.\n- `group` must be specified for check monitors. Per-check grouping is already explicitly known for some service checks.\nFor example, Postgres integration monitors are tagged by `db`, `host`, and `port`, and Network monitors by `host`, `instance`, and `url`. See [Service Checks](https://docs.datadoghq.com/api/latest/service-checks/) documentation for more information.\n\n##### Event Alert Query\n\nExample: `events('sources:nagios status:error,warning priority:normal tags: \"string query\"').rollup(\"count\").last(\"1h\")\"`\n\n- `event`, the event query string:\n- `string_query` free text query to match against event title and text.\n- `sources` event sources (comma-separated).\n- `status` event statuses (comma-separated). Valid options: error, warn, and info.\n- `priority` event priorities (comma-separated). Valid options: low, normal, all.\n- `host` event reporting host (comma-separated).\n- `tags` event tags (comma-separated).\n- `excluded_tags` excluded event tags (comma-separated).\n- `rollup` the stats roll-up method. `count` is the only supported method now.\n- `last` the timeframe to roll up the counts. Examples: 45m, 4h. Supported timeframes: m, h and d. This value should not exceed 48 hours.\n\n**NOTE** The Event Alert Query is being deprecated and replaced by the Event V2 Alert Query. For more information, see the [Event Migration guide](https://docs.datadoghq.com/events/guides/migrating_to_new_events_features/).\n\n##### Event V2 Alert Query\n\nExample: `events(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n##### Process Alert Query\n\nExample: `processes(search).over(tags).rollup('count').last(timeframe) operator #`\n\n- `search` free text search string for querying processes.\nMatching processes match results on the [Live Processes](https://docs.datadoghq.com/infrastructure/process/?tab=linuxwindows) page.\n- `tags` one or more tags (comma-separated)\n- `timeframe` the timeframe to roll up the counts. Examples: 10m, 4h. Supported timeframes: s, m, h and d\n- `operator` <, <=, >, >=, ==, or !=\n- `#` an integer or decimal number used to set the threshold\n\n##### Logs Alert Query\n\nExample: `logs(query).index(index_name).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `index_name` For multi-index organizations, the log index in which the request is performed.\n- `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n##### Composite Query\n\nExample: `12345 && 67890`, where `12345` and `67890` are the IDs of non-composite monitors\n\n* `name` [*required*, *default* = **dynamic, based on query**]: The name of the alert.\n* `message` [*required*, *default* = **dynamic, based on query**]: A message to include with notifications for this monitor.\nEmail notifications can be sent to specific users by using the same '@username' notation as events.\n* `tags` [*optional*, *default* = **empty list**]: A list of tags to associate with your monitor.\nWhen getting all monitor details via the API, use the `monitor_tags` argument to filter results by these tags.\nIt is only available via the API and isn't visible or editable in the Datadog UI.\n\n##### SLO Alert Query\n\nExample: `error_budget(\"slo_id\").over(\"time_window\") operator #`\n\n- `slo_id`: The alphanumeric SLO ID of the SLO you are configuring the alert for.\n- `time_window`: The time window of the SLO target you wish to alert on. Valid options: `7d`, `30d`, `90d`.\n- `operator`: `>=` or `>`\n\n##### Audit Alert Query\n\nExample: `audits(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg` and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n**NOTE** Only available on US1-FED and in closed beta on US1, EU, AP1, US3, and US5.\n\n##### CI Pipelines Alert Query\n\nExample: `ci-pipelines(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n**NOTE** CI Pipeline monitors are in alpha on US1, EU, AP1, US3, and US5.\n\n##### CI Tests Alert Query\n\nExample: `ci-tests(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n**NOTE** CI Test monitors are available only in closed beta on US1, EU, AP1, US3, and US5.\n\n##### Error Tracking Alert Query\n\nExample(RUM): `error-tracking-rum(query).rollup(rollup_method[, measure]).last(time_window) operator #`\nExample(APM Traces): `error-tracking-traces(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n**Database Monitoring Alert Query**\n\nExample: `database-monitoring(query).rollup(rollup_method[, measure]).last(time_window) operator #`\n\n- `query` The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).\n- `rollup_method` The stats roll-up method - supports `count`, `avg`, and `cardinality`.\n- `measure` For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.\n- `time_window` #m (between 1 and 2880), #h (between 1 and 48).\n- `operator` `<`, `<=`, `>`, `>=`, `==`, or `!=`.\n- `#` an integer or decimal number used to set the threshold.\n\n**NOTE** Database Monitoring monitors are in alpha on US1."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"message\": \"You may need to add web hosts if this is consistently high.\",\n  \"name\": \"Bytes received on host0\",\n  \"options\": {\n    \"no_data_timeframe\": 20,\n    \"notify_no_data\": true\n  },\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"tags\": [\n    \"app:webserver\",\n    \"frontend\"\n  ],\n  \"type\": \"query alert\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"type\": \"query alert\",\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"created\": \"1989-12-01T14:28:43.831Z\",\n  \"creator\": {\n    \"email\": \"officia sunt\",\n    \"handle\": \"pariatur\",\n    \"name\": \"aute do\"\n  },\n  \"deleted\": \"2020-10-30T20:46:24.520Z\",\n  \"id\": -50675854,\n  \"matching_downtimes\": [\n    {\n      \"id\": 1625,\n      \"end\": 1412792983,\n      \"scope\": [\n        \"env:staging\"\n      ],\n      \"start\": 1412792983\n    },\n    {\n      \"id\": 1625,\n      \"end\": 1412792983,\n      \"scope\": [\n        \"env:staging\"\n      ],\n      \"start\": 1412792983\n    }\n  ],\n  \"message\": \"ullamco incididunt cupidatat\",\n  \"modified\": \"1981-03-27T05:04:03.098Z\",\n  \"multi\": false,\n  \"name\": \"My monitor\",\n  \"options\": {\n    \"aggregation\": {\n      \"group_by\": \"host\",\n      \"metric\": \"metrics.name\",\n      \"type\": \"count\"\n    },\n    \"device_ids\": [\n      \"mobile_small\",\n      \"chrome.tablet\"\n    ],\n    \"enable_logs_sample\": false,\n    \"enable_samples\": false,\n    \"escalation_message\": \"none\",\n    \"evaluation_delay\": -52819274,\n    \"group_retention_duration\": \"dolor Lorem qui\",\n    \"groupby_simple_monitor\": false,\n    \"include_tags\": true,\n    \"locked\": false,\n    \"min_failure_duration\": 0,\n    \"min_location_failed\": 1,\n    \"new_group_delay\": -94315945,\n    \"new_host_delay\": 300,\n    \"no_data_timeframe\": -86360342,\n    \"notification_preset_name\": \"show_all\",\n    \"notify_audit\": false,\n    \"notify_by\": [\n      \"labore dolore\",\n      \"deserunt commodo consectetur\"\n    ],\n    \"notify_no_data\": false,\n    \"on_missing_data\": \"resolve\",\n    \"renotify_interval\": null,\n    \"renotify_occurrences\": 56355858,\n    \"renotify_statuses\": [\n      \"warn\",\n      \"no data\"\n    ],\n    \"require_full_window\": false,\n    \"scheduling_options\": {\n      \"evaluation_window\": {\n        \"day_starts\": \"04:00\",\n        \"hour_starts\": 0,\n        \"month_starts\": 1\n      }\n    },\n    \"silenced\": {\n      \"non_6f_\": 77287100\n    },\n    \"synthetics_check_id\": \"culpa in laborum irure\",\n    \"threshold_windows\": {\n      \"recovery_window\": \"culpa cupidatat Lorem ut\",\n      \"trigger_window\": \"fugiat officia mollit esse quis\"\n    },\n    \"thresholds\": {\n      \"critical\": -44507487.0891542,\n      \"critical_recovery\": 94365870.17342958,\n      \"ok\": 26645340.31156695,\n      \"unknown\": -32772943.396166816,\n      \"warning\": 75330874.10211122,\n      \"warning_recovery\": 30665996.226613894\n    },\n    \"timeout_h\": null,\n    \"variables\": [\n      {\n        \"data_source\": \"rum\",\n        \"compute\": {\n          \"aggregation\": \"avg\",\n          \"interval\": 60000,\n          \"metric\": \"@duration\"\n        },\n        \"name\": \"query_errors\",\n        \"group_by\": [\n          {\n            \"facet\": \"status\",\n            \"limit\": 10,\n            \"sort\": {\n              \"aggregation\": \"avg\",\n              \"metric\": \"minim tempor i\",\n              \"order\": \"desc\"\n            }\n          },\n          {\n            \"facet\": \"status\",\n            \"limit\": 10,\n            \"sort\": {\n              \"aggregation\": \"avg\",\n              \"metric\": \"Ut fugiat officia\",\n              \"order\": \"desc\"\n            }\n          }\n        ],\n        \"indexes\": [\n          \"days-3\",\n          \"days-7\"\n        ],\n        \"search\": {\n          \"query\": \"service:query\"\n        }\n      },\n      {\n        \"data_source\": \"rum\",\n        \"compute\": {\n          \"aggregation\": \"avg\",\n          \"interval\": 60000,\n          \"metric\": \"@duration\"\n        },\n        \"name\": \"query_errors\",\n        \"group_by\": [\n          {\n            \"facet\": \"status\",\n            \"limit\": 10,\n            \"sort\": {\n              \"aggregation\": \"avg\",\n              \"metric\": \"do velit\",\n              \"order\": \"desc\"\n            }\n          },\n          {\n            \"facet\": \"status\",\n            \"limit\": 10,\n            \"sort\": {\n              \"aggregation\": \"avg\",\n              \"metric\": \"amet proident anim in\",\n              \"order\": \"desc\"\n            }\n          }\n        ],\n        \"indexes\": [\n          \"days-3\",\n          \"days-7\"\n        ],\n        \"search\": {\n          \"query\": \"service:query\"\n        }\n      }\n    ]\n  },\n  \"overall_state\": \"Warn\",\n  \"priority\": 1,\n  \"restricted_roles\": [\n    \"enim qui cillum est\",\n    \"quis ut\"\n  ],\n  \"state\": {\n    \"groups\": {\n      \"Lorem_1\": {\n        \"last_nodata_ts\": -12653992,\n        \"last_notified_ts\": -66141067,\n        \"last_resolved_ts\": 5643925,\n        \"last_triggered_ts\": -6121593,\n        \"name\": \"dolore nulla i\",\n        \"status\": \"OK\"\n      },\n      \"nisi_c43\": {\n        \"last_nodata_ts\": -66061060,\n        \"last_notified_ts\": -86988012,\n        \"last_resolved_ts\": -39919633,\n        \"last_triggered_ts\": 13467862,\n        \"name\": \"Ut fugiat eiusmod anim\",\n        \"status\": \"Ignored\"\n      },\n      \"minim_c\": {\n        \"last_nodata_ts\": 6509669,\n        \"last_notified_ts\": 39348490,\n        \"last_resolved_ts\": 13221088,\n        \"last_triggered_ts\": 21889420,\n        \"name\": \"in velit Duis\",\n        \"status\": \"Alert\"\n      }\n    }\n  },\n  \"tags\": [\n    \"ex tempor\",\n    \"enim veniam dolore\"\n  ]\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"message\": \"You may need to add web hosts if this is consistently high.\",\n  \"name\": \"Bytes received on host0\",\n  \"options\": {\n    \"no_data_timeframe\": 20,\n    \"notify_no_data\": true\n  },\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"tags\": [\n    \"app:webserver\",\n    \"frontend\"\n  ],\n  \"type\": \"query alert\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"message\": \"You may need to add web hosts if this is consistently high.\",\n  \"name\": \"Bytes received on host0\",\n  \"options\": {\n    \"no_data_timeframe\": 20,\n    \"notify_no_data\": true\n  },\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"tags\": [\n    \"app:webserver\",\n    \"frontend\"\n  ],\n  \"type\": \"query alert\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"message\": \"You may need to add web hosts if this is consistently high.\",\n  \"name\": \"Bytes received on host0\",\n  \"options\": {\n    \"no_data_timeframe\": 20,\n    \"notify_no_data\": true\n  },\n  \"query\": \"avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100\",\n  \"tags\": [\n    \"app:webserver\",\n    \"frontend\"\n  ],\n  \"type\": \"query alert\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    }
  ]
}