Chilkat Online Tools

autoit / Datadog API Collection / Get all log-based metrics

Back to Collection Items

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

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

$oHttp.SetRequestHeader "Accept","application/json"

$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.app.ddog-gov.com/api/v2/logs/config/metrics",$oSbResponseBody)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oHttp.LastHeader & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

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

; {
;   "data": [
;     {
;       "attributes": {
;         "compute": {
;           "aggregation_type": "count",
;           "include_percentiles": "<boolean>",
;           "path": "<string>"
;         },
;         "filter": {
;           "query": "<string>"
;         },
;         "group_by": [
;           {
;             "path": "<string>",
;             "tag_name": "<string>"
;           },
;           {
;             "path": "<string>",
;             "tag_name": "<string>"
;           }
;         ]
;       },
;       "id": "<string>",
;       "type": "logs_metrics"
;     },
;     {
;       "attributes": {
;         "compute": {
;           "aggregation_type": "distribution",
;           "include_percentiles": "<boolean>",
;           "path": "<string>"
;         },
;         "filter": {
;           "query": "<string>"
;         },
;         "group_by": [
;           {
;             "path": "<string>",
;             "tag_name": "<string>"
;           },
;           {
;             "path": "<string>",
;             "tag_name": "<string>"
;           }
;         ]
;       },
;       "id": "<string>",
;       "type": "logs_metrics"
;     }
;   ]
; }

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

Local $sAggregation_type
Local $sInclude_percentiles
Local $sPath
Local $sQuery
Local $sId
Local $sV_type
Local $iJ
Local $iCount_j
Local $sPath
Local $sTag_name

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data")
While $i < $iCount_i
    $oJResp.I = $i
    $sAggregation_type = $oJResp.StringOf("data[i].attributes.compute.aggregation_type")
    $sInclude_percentiles = $oJResp.StringOf("data[i].attributes.compute.include_percentiles")
    $sPath = $oJResp.StringOf("data[i].attributes.compute.path")
    $sQuery = $oJResp.StringOf("data[i].attributes.filter.query")
    $sId = $oJResp.StringOf("data[i].id")
    $sV_type = $oJResp.StringOf("data[i].type")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("data[i].attributes.group_by")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sPath = $oJResp.StringOf("data[i].attributes.group_by[j].path")
        $sTag_name = $oJResp.StringOf("data[i].attributes.group_by[j].tag_name")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/logs/config/metrics

Postman Collection Item JSON

{
  "name": "Get all log-based metrics",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/logs/config/metrics",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "logs",
        "config",
        "metrics"
      ]
    },
    "description": "Get the list of configured log-based metrics with their definitions."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"compute\": {\n          \"aggregation_type\": \"count\",\n          \"include_percentiles\": \"<boolean>\",\n          \"path\": \"<string>\"\n        },\n        \"filter\": {\n          \"query\": \"<string>\"\n        },\n        \"group_by\": [\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          },\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          }\n        ]\n      },\n      \"id\": \"<string>\",\n      \"type\": \"logs_metrics\"\n    },\n    {\n      \"attributes\": {\n        \"compute\": {\n          \"aggregation_type\": \"distribution\",\n          \"include_percentiles\": \"<boolean>\",\n          \"path\": \"<string>\"\n        },\n        \"filter\": {\n          \"query\": \"<string>\"\n        },\n        \"group_by\": [\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          },\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          }\n        ]\n      },\n      \"id\": \"<string>\",\n      \"type\": \"logs_metrics\"\n    }\n  ]\n}"
    },
    {
      "name": "Not Authorized",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}