Chilkat Online Tools

autoit / Datadog API Collection / Get all Cloud Workload Security Agent rules

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/security_monitoring/cloud_workload_security/agent_rules",$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": {
;         "agentConstraint": "<string>",
;         "category": "<string>",
;         "creationAuthorUuId": "<string>",
;         "creationDate": "<long>",
;         "creator": {
;           "handle": "<string>",
;           "name": "<string>"
;         },
;         "defaultRule": "<boolean>",
;         "description": "<string>",
;         "enabled": "<boolean>",
;         "expression": "<string>",
;         "name": "<string>",
;         "updateAuthorUuId": "<string>",
;         "updateDate": "<long>",
;         "updatedAt": "<long>",
;         "updater": {
;           "handle": "<string>",
;           "name": "<string>"
;         },
;         "version": "<long>"
;       },
;       "id": "<string>",
;       "type": "agent_rule"
;     },
;     {
;       "attributes": {
;         "agentConstraint": "<string>",
;         "category": "<string>",
;         "creationAuthorUuId": "<string>",
;         "creationDate": "<long>",
;         "creator": {
;           "handle": "<string>",
;           "name": "<string>"
;         },
;         "defaultRule": "<boolean>",
;         "description": "<string>",
;         "enabled": "<boolean>",
;         "expression": "<string>",
;         "name": "<string>",
;         "updateAuthorUuId": "<string>",
;         "updateDate": "<long>",
;         "updatedAt": "<long>",
;         "updater": {
;           "handle": "<string>",
;           "name": "<string>"
;         },
;         "version": "<long>"
;       },
;       "id": "<string>",
;       "type": "agent_rule"
;     }
;   ]
; }

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

Local $sAgentConstraint
Local $sCategory
Local $sCreationAuthorUuId
Local $sCreationDate
Local $sHandle
Local $sName
Local $sDefaultRule
Local $sDescription
Local $sEnabled
Local $sExpression
Local $sAttributesName
Local $sUpdateAuthorUuId
Local $sUpdateDate
Local $sUpdatedAt
Local $sUpdaterHandle
Local $sUpdaterName
Local $sVersion
Local $sId
Local $sV_type

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data")
While $i < $iCount_i
    $oJResp.I = $i
    $sAgentConstraint = $oJResp.StringOf("data[i].attributes.agentConstraint")
    $sCategory = $oJResp.StringOf("data[i].attributes.category")
    $sCreationAuthorUuId = $oJResp.StringOf("data[i].attributes.creationAuthorUuId")
    $sCreationDate = $oJResp.StringOf("data[i].attributes.creationDate")
    $sHandle = $oJResp.StringOf("data[i].attributes.creator.handle")
    $sName = $oJResp.StringOf("data[i].attributes.creator.name")
    $sDefaultRule = $oJResp.StringOf("data[i].attributes.defaultRule")
    $sDescription = $oJResp.StringOf("data[i].attributes.description")
    $sEnabled = $oJResp.StringOf("data[i].attributes.enabled")
    $sExpression = $oJResp.StringOf("data[i].attributes.expression")
    $sAttributesName = $oJResp.StringOf("data[i].attributes.name")
    $sUpdateAuthorUuId = $oJResp.StringOf("data[i].attributes.updateAuthorUuId")
    $sUpdateDate = $oJResp.StringOf("data[i].attributes.updateDate")
    $sUpdatedAt = $oJResp.StringOf("data[i].attributes.updatedAt")
    $sUpdaterHandle = $oJResp.StringOf("data[i].attributes.updater.handle")
    $sUpdaterName = $oJResp.StringOf("data[i].attributes.updater.name")
    $sVersion = $oJResp.StringOf("data[i].attributes.version")
    $sId = $oJResp.StringOf("data[i].id")
    $sV_type = $oJResp.StringOf("data[i].type")
    $i = $i + 1
Wend

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get all Cloud Workload Security Agent rules",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "security_monitoring",
        "cloud_workload_security",
        "agent_rules"
      ]
    },
    "description": "Get the list of Agent rules."
  },
  "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/cloud_workload_security/agent_rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"agentConstraint\": \"<string>\",\n        \"category\": \"<string>\",\n        \"creationAuthorUuId\": \"<string>\",\n        \"creationDate\": \"<long>\",\n        \"creator\": {\n          \"handle\": \"<string>\",\n          \"name\": \"<string>\"\n        },\n        \"defaultRule\": \"<boolean>\",\n        \"description\": \"<string>\",\n        \"enabled\": \"<boolean>\",\n        \"expression\": \"<string>\",\n        \"name\": \"<string>\",\n        \"updateAuthorUuId\": \"<string>\",\n        \"updateDate\": \"<long>\",\n        \"updatedAt\": \"<long>\",\n        \"updater\": {\n          \"handle\": \"<string>\",\n          \"name\": \"<string>\"\n        },\n        \"version\": \"<long>\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"agent_rule\"\n    },\n    {\n      \"attributes\": {\n        \"agentConstraint\": \"<string>\",\n        \"category\": \"<string>\",\n        \"creationAuthorUuId\": \"<string>\",\n        \"creationDate\": \"<long>\",\n        \"creator\": {\n          \"handle\": \"<string>\",\n          \"name\": \"<string>\"\n        },\n        \"defaultRule\": \"<boolean>\",\n        \"description\": \"<string>\",\n        \"enabled\": \"<boolean>\",\n        \"expression\": \"<string>\",\n        \"name\": \"<string>\",\n        \"updateAuthorUuId\": \"<string>\",\n        \"updateDate\": \"<long>\",\n        \"updatedAt\": \"<long>\",\n        \"updater\": {\n          \"handle\": \"<string>\",\n          \"name\": \"<string>\"\n        },\n        \"version\": \"<long>\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"agent_rule\"\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/security_monitoring/cloud_workload_security/agent_rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules"
          ]
        }
      },
      "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/security_monitoring/cloud_workload_security/agent_rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules"
          ]
        }
      },
      "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}"
    }
  ]
}