Chilkat Online Tools

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

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    http.SetRequestHeader("Accept","application/json");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = http.QuickGetSb("https://api.app.ddog-gov.com/api/v2/security_monitoring/rules/:rule_id",sbResponseBody);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = http.get_LastStatus();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, http.lastHeader());
        Log.i(TAG, "Failed.");
        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

    String condition;
    String status;
    int j;
    int count_j;
    String strVal;
    String action;
    String query;
    String aggregation;
    String metric;

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

        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("complianceSignalOptions.defaultGroupByFields");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("complianceSignalOptions.defaultGroupByFields[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("complianceSignalOptions.userGroupByFields");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("complianceSignalOptions.userGroupByFields[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("filters");
    while (i < count_i) {
        jResp.put_I(i);
        action = jResp.stringOf("filters[i].action");
        query = jResp.stringOf("filters[i].query");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("options.complianceRuleOptions.regoRule.resourceTypes");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("options.complianceRuleOptions.regoRule.resourceTypes[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("queries");
    while (i < count_i) {
        jResp.put_I(i);
        aggregation = jResp.stringOf("queries[i].aggregation");
        metric = jResp.stringOf("queries[i].metric");
        name = jResp.stringOf("queries[i].name");
        query = jResp.stringOf("queries[i].query");
        j = 0;
        count_j = jResp.SizeOfArray("queries[i].distinctFields");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("queries[i].distinctFields[j]");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("queries[i].groupByFields");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("queries[i].groupByFields[j]");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("queries[i].metrics");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("queries[i].metrics[j]");
            j = j + 1;
            }

        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("tags");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("tags[i]");
        i = i + 1;
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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