Chilkat Online Tools

C / Datadog API Collection / Monitors search

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject queryParams;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    int count;
    BOOL name;
    const char *name_str;
    const char *classification;
    const char *Handle;
    const char *Name;
    int id;
    const char *last_triggered_ts;
    int org_id;
    const char *status;
    const char *v_type;
    int j;
    int count_j;
    const char *strVal;
    const char *handle;
    int Page;
    int Page_count;
    int Per_page;
    int Total_count;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    queryParams = CkJsonObject_Create();
    CkJsonObject_UpdateString(queryParams,"query","tempor Ut sed velit");
    CkJsonObject_UpdateInt(queryParams,"page",0);
    CkJsonObject_UpdateInt(queryParams,"per_page",30);
    CkJsonObject_UpdateString(queryParams,"sort","tempor Ut sed velit");

    CkHttp_SetRequestHeader(http,"Accept","application/json");

    resp = CkHttp_QuickRequestParams(http,"GET","https://api.app.ddog-gov.com/api/v1/monitor/search",queryParams);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(resp);

    // 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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Page = CkJsonObject_IntOf(jResp,"metadata.page");
    Page_count = CkJsonObject_IntOf(jResp,"metadata.page_count");
    Per_page = CkJsonObject_IntOf(jResp,"metadata.per_page");
    Total_count = CkJsonObject_IntOf(jResp,"metadata.total_count");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"counts.muted");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        count = CkJsonObject_IntOf(jResp,"counts.muted[i].count");
        name = CkJsonObject_BoolOf(jResp,"counts.muted[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"counts.status");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        count = CkJsonObject_IntOf(jResp,"counts.status[i].count");
        name_str = CkJsonObject_stringOf(jResp,"counts.status[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"counts.tag");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        count = CkJsonObject_IntOf(jResp,"counts.tag[i].count");
        name_str = CkJsonObject_stringOf(jResp,"counts.tag[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"counts.type");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        count = CkJsonObject_IntOf(jResp,"counts.type[i].count");
        name_str = CkJsonObject_stringOf(jResp,"counts.type[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"monitors");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        classification = CkJsonObject_stringOf(jResp,"monitors[i].classification");
        Handle = CkJsonObject_stringOf(jResp,"monitors[i].creator.handle");
        Name = CkJsonObject_stringOf(jResp,"monitors[i].creator.name");
        id = CkJsonObject_IntOf(jResp,"monitors[i].id");
        last_triggered_ts = CkJsonObject_stringOf(jResp,"monitors[i].last_triggered_ts");
        name_str = CkJsonObject_stringOf(jResp,"monitors[i].name");
        org_id = CkJsonObject_IntOf(jResp,"monitors[i].org_id");
        status = CkJsonObject_stringOf(jResp,"monitors[i].status");
        v_type = CkJsonObject_stringOf(jResp,"monitors[i].type");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"monitors[i].metrics");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"monitors[i].metrics[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"monitors[i].notifications");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            handle = CkJsonObject_stringOf(jResp,"monitors[i].notifications[j].handle");
            name_str = CkJsonObject_stringOf(jResp,"monitors[i].notifications[j].name");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"monitors[i].scopes");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"monitors[i].scopes[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"monitors[i].tags");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"monitors[i].tags[j]");
            j = j + 1;
        }

        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkJsonObject_Dispose(queryParams);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

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