Chilkat Online Tools

C / Datadog API Collection / Get a rule's details

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *condition;
    const char *status;
    int j;
    int count_j;
    const char *strVal;
    const char *action;
    const char *query;
    const char *aggregation;
    const char *metric;
    const char *DefaultActivationStatus;
    const char *UserActivationStatus;
    const char *createdAt;
    const char *creationAuthorId;
    const char *deprecationDate;
    const char *hasExtendedTitle;
    const char *id;
    const char *isDefault;
    const char *isDeleted;
    const char *isEnabled;
    const char *message;
    const char *name;
    const char *ComplexRule;
    const char *Policy;
    const char *ResourceType;
    const char *DecreaseCriticalityBasedOnEnv;
    const char *DetectionMethod;
    int EvaluationWindow;
    const char *HardcodedEvaluatorType;
    const char *BaselineUserLocations;
    int KeepAlive;
    int MaxSignalDuration;
    int ForgetAfter;
    int LearningDuration;
    const char *LearningMethod;
    int LearningThreshold;
    const char *v_type;
    const char *updateAuthorId;
    const char *version;
    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();

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

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://api.app.ddog-gov.com/api/v2/security_monitoring/rules/:rule_id",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

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

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

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

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

    // {
    //   "cases": [
    //     {
    //       "condition": "<string>",
    //       "name": "<string>",
    //       "notifications": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "status": "medium"
    //     },
    //     {
    //       "condition": "<string>",
    //       "name": "<string>",
    //       "notifications": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "status": "critical"
    //     }
    //   ],
    //   "complianceSignalOptions": {
    //     "defaultActivationStatus": "<boolean>",
    //     "defaultGroupByFields": [
    //       "<string>",
    //       "<string>"
    //     ],
    //     "userActivationStatus": "<boolean>",
    //     "userGroupByFields": [
    //       "<string>",
    //       "<string>"
    //     ]
    //   },
    //   "createdAt": "<long>",
    //   "creationAuthorId": "<long>",
    //   "deprecationDate": "<long>",
    //   "filters": [
    //     {
    //       "action": "suppress",
    //       "query": "<string>"
    //     },
    //     {
    //       "action": "require",
    //       "query": "<string>"
    //     }
    //   ],
    //   "hasExtendedTitle": "<boolean>",
    //   "id": "<string>",
    //   "isDefault": "<boolean>",
    //   "isDeleted": "<boolean>",
    //   "isEnabled": "<boolean>",
    //   "message": "<string>",
    //   "name": "<string>",
    //   "options": {
    //     "complianceRuleOptions": {
    //       "complexRule": "<boolean>",
    //       "regoRule": {
    //         "policy": "<string>",
    //         "resourceTypes": [
    //           "<string>",
    //           "<string>"
    //         ]
    //       },
    //       "resourceType": "<string>"
    //     },
    //     "decreaseCriticalityBasedOnEnv": "<boolean>",
    //     "detectionMethod": "third_party",
    //     "evaluationWindow": 300,
    //     "hardcodedEvaluatorType": "log4shell",
    //     "impossibleTravelOptions": {
    //       "baselineUserLocations": "<boolean>"
    //     },
    //     "keepAlive": 300,
    //     "maxSignalDuration": 900,
    //     "newValueOptions": {
    //       "forgetAfter": 28,
    //       "learningDuration": 0,
    //       "learningMethod": "duration",
    //       "learningThreshold": 0
    //     }
    //   },
    //   "queries": [
    //     {
    //       "aggregation": "max",
    //       "distinctFields": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "groupByFields": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "metric": "<string>",
    //       "metrics": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "name": "<string>",
    //       "query": "<string>"
    //     },
    //     {
    //       "aggregation": "max",
    //       "distinctFields": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "groupByFields": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "metric": "<string>",
    //       "metrics": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "name": "<string>",
    //       "query": "<string>"
    //     }
    //   ],
    //   "tags": [
    //     "<string>",
    //     "<string>"
    //   ],
    //   "type": "application_security",
    //   "updateAuthorId": "<long>",
    //   "version": "<long>"
    // }

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

    DefaultActivationStatus = CkJsonObject_stringOf(jResp,"complianceSignalOptions.defaultActivationStatus");
    UserActivationStatus = CkJsonObject_stringOf(jResp,"complianceSignalOptions.userActivationStatus");
    createdAt = CkJsonObject_stringOf(jResp,"createdAt");
    creationAuthorId = CkJsonObject_stringOf(jResp,"creationAuthorId");
    deprecationDate = CkJsonObject_stringOf(jResp,"deprecationDate");
    hasExtendedTitle = CkJsonObject_stringOf(jResp,"hasExtendedTitle");
    id = CkJsonObject_stringOf(jResp,"id");
    isDefault = CkJsonObject_stringOf(jResp,"isDefault");
    isDeleted = CkJsonObject_stringOf(jResp,"isDeleted");
    isEnabled = CkJsonObject_stringOf(jResp,"isEnabled");
    message = CkJsonObject_stringOf(jResp,"message");
    name = CkJsonObject_stringOf(jResp,"name");
    ComplexRule = CkJsonObject_stringOf(jResp,"options.complianceRuleOptions.complexRule");
    Policy = CkJsonObject_stringOf(jResp,"options.complianceRuleOptions.regoRule.policy");
    ResourceType = CkJsonObject_stringOf(jResp,"options.complianceRuleOptions.resourceType");
    DecreaseCriticalityBasedOnEnv = CkJsonObject_stringOf(jResp,"options.decreaseCriticalityBasedOnEnv");
    DetectionMethod = CkJsonObject_stringOf(jResp,"options.detectionMethod");
    EvaluationWindow = CkJsonObject_IntOf(jResp,"options.evaluationWindow");
    HardcodedEvaluatorType = CkJsonObject_stringOf(jResp,"options.hardcodedEvaluatorType");
    BaselineUserLocations = CkJsonObject_stringOf(jResp,"options.impossibleTravelOptions.baselineUserLocations");
    KeepAlive = CkJsonObject_IntOf(jResp,"options.keepAlive");
    MaxSignalDuration = CkJsonObject_IntOf(jResp,"options.maxSignalDuration");
    ForgetAfter = CkJsonObject_IntOf(jResp,"options.newValueOptions.forgetAfter");
    LearningDuration = CkJsonObject_IntOf(jResp,"options.newValueOptions.learningDuration");
    LearningMethod = CkJsonObject_stringOf(jResp,"options.newValueOptions.learningMethod");
    LearningThreshold = CkJsonObject_IntOf(jResp,"options.newValueOptions.learningThreshold");
    v_type = CkJsonObject_stringOf(jResp,"type");
    updateAuthorId = CkJsonObject_stringOf(jResp,"updateAuthorId");
    version = CkJsonObject_stringOf(jResp,"version");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"cases");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        condition = CkJsonObject_stringOf(jResp,"cases[i].condition");
        name = CkJsonObject_stringOf(jResp,"cases[i].name");
        status = CkJsonObject_stringOf(jResp,"cases[i].status");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"cases[i].notifications");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"cases[i].notifications[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"complianceSignalOptions.defaultGroupByFields");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        strVal = CkJsonObject_stringOf(jResp,"complianceSignalOptions.defaultGroupByFields[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"complianceSignalOptions.userGroupByFields");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        strVal = CkJsonObject_stringOf(jResp,"complianceSignalOptions.userGroupByFields[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"filters");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        action = CkJsonObject_stringOf(jResp,"filters[i].action");
        query = CkJsonObject_stringOf(jResp,"filters[i].query");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"options.complianceRuleOptions.regoRule.resourceTypes");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        strVal = CkJsonObject_stringOf(jResp,"options.complianceRuleOptions.regoRule.resourceTypes[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"queries");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        aggregation = CkJsonObject_stringOf(jResp,"queries[i].aggregation");
        metric = CkJsonObject_stringOf(jResp,"queries[i].metric");
        name = CkJsonObject_stringOf(jResp,"queries[i].name");
        query = CkJsonObject_stringOf(jResp,"queries[i].query");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"queries[i].distinctFields");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            strVal = CkJsonObject_stringOf(jResp,"queries[i].distinctFields[j]");
            j = j + 1;
        }

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

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

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"tags");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        strVal = CkJsonObject_stringOf(jResp,"tags[i]");
        i = i + 1;
    }



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

    }

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/security_monitoring/rules/:rule_id

Postman Collection Item JSON

{
  "name": "Get a rule's details",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/security_monitoring/rules/:rule_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "security_monitoring",
        "rules",
        ":rule_id"
      ],
      "variable": [
        {
          "key": "rule_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Get a rule's 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/v2/security_monitoring/rules/:rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "rules",
            ":rule_id"
          ],
          "variable": [
            {
              "key": "rule_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"cases\": [\n    {\n      \"condition\": \"<string>\",\n      \"name\": \"<string>\",\n      \"notifications\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"status\": \"medium\"\n    },\n    {\n      \"condition\": \"<string>\",\n      \"name\": \"<string>\",\n      \"notifications\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"status\": \"critical\"\n    }\n  ],\n  \"complianceSignalOptions\": {\n    \"defaultActivationStatus\": \"<boolean>\",\n    \"defaultGroupByFields\": [\n      \"<string>\",\n      \"<string>\"\n    ],\n    \"userActivationStatus\": \"<boolean>\",\n    \"userGroupByFields\": [\n      \"<string>\",\n      \"<string>\"\n    ]\n  },\n  \"createdAt\": \"<long>\",\n  \"creationAuthorId\": \"<long>\",\n  \"deprecationDate\": \"<long>\",\n  \"filters\": [\n    {\n      \"action\": \"suppress\",\n      \"query\": \"<string>\"\n    },\n    {\n      \"action\": \"require\",\n      \"query\": \"<string>\"\n    }\n  ],\n  \"hasExtendedTitle\": \"<boolean>\",\n  \"id\": \"<string>\",\n  \"isDefault\": \"<boolean>\",\n  \"isDeleted\": \"<boolean>\",\n  \"isEnabled\": \"<boolean>\",\n  \"message\": \"<string>\",\n  \"name\": \"<string>\",\n  \"options\": {\n    \"complianceRuleOptions\": {\n      \"complexRule\": \"<boolean>\",\n      \"regoRule\": {\n        \"policy\": \"<string>\",\n        \"resourceTypes\": [\n          \"<string>\",\n          \"<string>\"\n        ]\n      },\n      \"resourceType\": \"<string>\"\n    },\n    \"decreaseCriticalityBasedOnEnv\": \"<boolean>\",\n    \"detectionMethod\": \"third_party\",\n    \"evaluationWindow\": 300,\n    \"hardcodedEvaluatorType\": \"log4shell\",\n    \"impossibleTravelOptions\": {\n      \"baselineUserLocations\": \"<boolean>\"\n    },\n    \"keepAlive\": 300,\n    \"maxSignalDuration\": 900,\n    \"newValueOptions\": {\n      \"forgetAfter\": 28,\n      \"learningDuration\": 0,\n      \"learningMethod\": \"duration\",\n      \"learningThreshold\": 0\n    }\n  },\n  \"queries\": [\n    {\n      \"aggregation\": \"max\",\n      \"distinctFields\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"groupByFields\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"metric\": \"<string>\",\n      \"metrics\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"name\": \"<string>\",\n      \"query\": \"<string>\"\n    },\n    {\n      \"aggregation\": \"max\",\n      \"distinctFields\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"groupByFields\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"metric\": \"<string>\",\n      \"metrics\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"name\": \"<string>\",\n      \"query\": \"<string>\"\n    }\n  ],\n  \"tags\": [\n    \"<string>\",\n    \"<string>\"\n  ],\n  \"type\": \"application_security\",\n  \"updateAuthorId\": \"<long>\",\n  \"version\": \"<long>\"\n}"
    },
    {
      "name": "Not Found",
      "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/security_monitoring/rules/:rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "rules",
            ":rule_id"
          ],
          "variable": [
            {
              "key": "rule_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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/security_monitoring/rules/:rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "rules",
            ":rule_id"
          ],
          "variable": [
            {
              "key": "rule_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}