Chilkat Online Tools

DataFlex / Datadog API Collection / Monitors search

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iCount
    Boolean iName
    String sName_str
    String sClassification
    String sHandle
    String sName
    Integer iId
    String sLast_triggered_ts
    Integer iOrg_id
    String sStatus
    String sV_type
    Integer j
    Integer iCount_j
    String sStrVal
    String sHandle
    Integer iPage
    Integer iPage_count
    Integer iPer_page
    Integer iTotal_count
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "query" "tempor Ut sed velit" To iSuccess
    Get ComUpdateInt Of hoQueryParams "page" 0 To iSuccess
    Get ComUpdateInt Of hoQueryParams "per_page" 30 To iSuccess
    Get ComUpdateString Of hoQueryParams "sort" "tempor Ut sed velit" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/monitor/search" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    // {
    //   "counts": {
    //     "muted": [
    //       {
    //         "count": 3,
    //         "name": false
    //       },
    //       {
    //         "count": 3,
    //         "name": true
    //       }
    //     ],
    //     "status": [
    //       {
    //         "count": 4,
    //         "name": "No Data"
    //       },
    //       {
    //         "count": 2,
    //         "name": "OK"
    //       }
    //     ],
    //     "tag": [
    //       {
    //         "count": 6,
    //         "name": "service:cassandra"
    //       }
    //     ],
    //     "type": [
    //       {
    //         "count": 6,
    //         "name": "metric"
    //       }
    //     ]
    //   },
    //   "metadata": {
    //     "page": 0,
    //     "page_count": 6,
    //     "per_page": 30,
    //     "total_count": 6
    //   },
    //   "monitors": [
    //     {
    //       "classification": "metric",
    //       "creator": {
    //         "handle": "john@datadoghq.com",
    //         "name": "John Doe"
    //       },
    //       "id": 2699850,
    //       "last_triggered_ts": null,
    //       "metrics": [
    //         "system.cpu.user"
    //       ],
    //       "name": "Cassandra CPU is high on {{host.name}} in {{availability-zone.name}}",
    //       "notifications": [
    //         {
    //           "handle": "jane@datadoghq.com",
    //           "name": "Jane Doe"
    //         }
    //       ],
    //       "org_id": 1234,
    //       "scopes": [
    //         "!availability-zone:us-east-1c",
    //         "name:cassandra"
    //       ],
    //       "status": "No Data",
    //       "tags": [
    //         "service:cassandra"
    //       ],
    //       "type": "query alert"
    //     }
    //   ]
    // }

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

    Get ComIntOf Of hoJResp "metadata.page" To iPage
    Get ComIntOf Of hoJResp "metadata.page_count" To iPage_count
    Get ComIntOf Of hoJResp "metadata.per_page" To iPer_page
    Get ComIntOf Of hoJResp "metadata.total_count" To iTotal_count
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "counts.muted" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "counts.muted[i].count" To iCount
        Get ComBoolOf Of hoJResp "counts.muted[i].name" To iName
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "counts.status" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "counts.status[i].count" To iCount
        Get ComStringOf Of hoJResp "counts.status[i].name" To sName_str
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "counts.tag" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "counts.tag[i].count" To iCount
        Get ComStringOf Of hoJResp "counts.tag[i].name" To sName_str
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "counts.type" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "counts.type[i].count" To iCount
        Get ComStringOf Of hoJResp "counts.type[i].name" To sName_str
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "monitors" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "monitors[i].classification" To sClassification
        Get ComStringOf Of hoJResp "monitors[i].creator.handle" To sHandle
        Get ComStringOf Of hoJResp "monitors[i].creator.name" To sName
        Get ComIntOf Of hoJResp "monitors[i].id" To iId
        Get ComStringOf Of hoJResp "monitors[i].last_triggered_ts" To sLast_triggered_ts
        Get ComStringOf Of hoJResp "monitors[i].name" To sName_str
        Get ComIntOf Of hoJResp "monitors[i].org_id" To iOrg_id
        Get ComStringOf Of hoJResp "monitors[i].status" To sStatus
        Get ComStringOf Of hoJResp "monitors[i].type" To sV_type
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "monitors[i].metrics" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "monitors[i].metrics[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "monitors[i].notifications" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "monitors[i].notifications[j].handle" To sHandle
            Get ComStringOf Of hoJResp "monitors[i].notifications[j].name" To sName_str
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "monitors[i].scopes" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "monitors[i].scopes[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "monitors[i].tags" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "monitors[i].tags[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -G -d "query=tempor%20Ut%20sed%20velit"
	-d "page=0"
	-d "per_page=30"
	-d "sort=tempor%20Ut%20sed%20velit"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/monitor/search

Postman Collection Item JSON

{
  "name": "Monitors search",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/monitor/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "monitor",
        "search"
      ],
      "query": [
        {
          "key": "query",
          "value": "tempor Ut sed velit",
          "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
        },
        {
          "key": "page",
          "value": "0",
          "description": "Page to start paginating from."
        },
        {
          "key": "per_page",
          "value": "30",
          "description": "Number of monitors to return per page."
        },
        {
          "key": "sort",
          "value": "tempor Ut sed velit",
          "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
        }
      ]
    },
    "description": "Search and filter your monitors details."
  },
  "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/v1/monitor/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"counts\": {\n    \"muted\": [\n      {\n        \"count\": 3,\n        \"name\": false\n      },\n      {\n        \"count\": 3,\n        \"name\": true\n      }\n    ],\n    \"status\": [\n      {\n        \"count\": 4,\n        \"name\": \"No Data\"\n      },\n      {\n        \"count\": 2,\n        \"name\": \"OK\"\n      }\n    ],\n    \"tag\": [\n      {\n        \"count\": 6,\n        \"name\": \"service:cassandra\"\n      }\n    ],\n    \"type\": [\n      {\n        \"count\": 6,\n        \"name\": \"metric\"\n      }\n    ]\n  },\n  \"metadata\": {\n    \"page\": 0,\n    \"page_count\": 6,\n    \"per_page\": 30,\n    \"total_count\": 6\n  },\n  \"monitors\": [\n    {\n      \"classification\": \"metric\",\n      \"creator\": {\n        \"handle\": \"john@datadoghq.com\",\n        \"name\": \"John Doe\"\n      },\n      \"id\": 2699850,\n      \"last_triggered_ts\": null,\n      \"metrics\": [\n        \"system.cpu.user\"\n      ],\n      \"name\": \"Cassandra CPU is high on {{host.name}} in {{availability-zone.name}}\",\n      \"notifications\": [\n        {\n          \"handle\": \"jane@datadoghq.com\",\n          \"name\": \"Jane Doe\"\n        }\n      ],\n      \"org_id\": 1234,\n      \"scopes\": [\n        \"!availability-zone:us-east-1c\",\n        \"name:cassandra\"\n      ],\n      \"status\": \"No Data\",\n      \"tags\": [\n        \"service:cassandra\"\n      ],\n      \"type\": \"query alert\"\n    }\n  ]\n}"
    },
    {
      "name": "Bad Request",
      "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/v1/monitor/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "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": "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/v1/monitor/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "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": "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/v1/monitor/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "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}"
    }
  ]
}