Chilkat Online Tools

DescribeFindings TCL Example

Amazon Inspector

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "AWS_SECRET_KEY"

# Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "inspector"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://inspector.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "inspector.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

# The following code creates the JSON request body.
# The JSON created by this code is shown below.

# Use this online tool to generate code from sample JSON:
# Generate Code to Create JSON

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "findingArns[0]" "string"
CkJsonObject_UpdateString $json "locale" "string"

# The JSON request body created by the above code:

# {
#   "findingArns": [
#     "string"
#   ],
#   "locale": "string"
# }

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "InspectorService.DescribeFindings"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody

# The following code parses the JSON response.
# A sample JSON response is shown below the sample code.

# Use this online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON

set FailureCode [CkJsonObject_stringOf $jResp "failedItems.string.failureCode"]
set Retryable [CkJsonObject_IntOf $jResp "failedItems.string.retryable"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "findings"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set arn [CkJsonObject_stringOf $jResp "findings[i].arn"]
    set AgentId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.agentId"]
    set AmiId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.amiId"]
    set AutoScalingGroup [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.autoScalingGroup"]
    set Hostname [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.hostname"]
    set SchemaVersion [CkJsonObject_IntOf $jResp "findings[i].assetAttributes.schemaVersion"]
    set assetType [CkJsonObject_stringOf $jResp "findings[i].assetType"]
    set confidence [CkJsonObject_IntOf $jResp "findings[i].confidence"]
    set createdAt [CkJsonObject_IntOf $jResp "findings[i].createdAt"]
    set description [CkJsonObject_stringOf $jResp "findings[i].description"]
    set id [CkJsonObject_stringOf $jResp "findings[i].id"]
    set indicatorOfCompromise [CkJsonObject_IntOf $jResp "findings[i].indicatorOfCompromise"]
    set numericSeverity [CkJsonObject_IntOf $jResp "findings[i].numericSeverity"]
    set recommendation [CkJsonObject_stringOf $jResp "findings[i].recommendation"]
    set schemaVersion [CkJsonObject_IntOf $jResp "findings[i].schemaVersion"]
    set service [CkJsonObject_stringOf $jResp "findings[i].service"]
    set AssessmentRunArn [CkJsonObject_stringOf $jResp "findings[i].serviceAttributes.assessmentRunArn"]
    set RulesPackageArn [CkJsonObject_stringOf $jResp "findings[i].serviceAttributes.rulesPackageArn"]
    set serviceAttributesSchemaVersion [CkJsonObject_IntOf $jResp "findings[i].serviceAttributes.schemaVersion"]
    set severity [CkJsonObject_stringOf $jResp "findings[i].severity"]
    set title [CkJsonObject_stringOf $jResp "findings[i].title"]
    set updatedAt [CkJsonObject_IntOf $jResp "findings[i].updatedAt"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.ipv4Addresses"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.ipv4Addresses[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.networkInterfaces"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set networkInterfaceId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].networkInterfaceId"]
        set privateDnsName [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].privateDnsName"]
        set privateIpAddress [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].privateIpAddress"]
        set publicDnsName [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].publicDnsName"]
        set publicIp [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].publicIp"]
        set subnetId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].subnetId"]
        set vpcId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].vpcId"]
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set strVal [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses[k]"]
            set k [expr $k + 1]
        }
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set privateDnsName [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateDnsName"]
            set privateIpAddress [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateIpAddress"]
            set k [expr $k + 1]
        }
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.networkInterfaces[j].securityGroups"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set groupId [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupId"]
            set groupName [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupName"]
            set k [expr $k + 1]
        }
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "findings[i].assetAttributes.tags"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set key [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.tags[j].key"]
        set value [CkJsonObject_stringOf $jResp "findings[i].assetAttributes.tags[j].value"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "findings[i].attributes"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set key [CkJsonObject_stringOf $jResp "findings[i].attributes[j].key"]
        set value [CkJsonObject_stringOf $jResp "findings[i].attributes[j].value"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "findings[i].userAttributes"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set key [CkJsonObject_stringOf $jResp "findings[i].userAttributes[j].key"]
        set value [CkJsonObject_stringOf $jResp "findings[i].userAttributes[j].value"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

# A sample JSON response body parsed by the above code:

# {
#   "failedItems": {
#     "string": {
#       "failureCode": "string",
#       "retryable": boolean
#     }
#   },
#   "findings": [
#     {
#       "arn": "string",
#       "assetAttributes": {
#         "agentId": "string",
#         "amiId": "string",
#         "autoScalingGroup": "string",
#         "hostname": "string",
#         "ipv4Addresses": [
#           "string"
#         ],
#         "networkInterfaces": [
#           {
#             "ipv6Addresses": [
#               "string"
#             ],
#             "networkInterfaceId": "string",
#             "privateDnsName": "string",
#             "privateIpAddress": "string",
#             "privateIpAddresses": [
#               {
#                 "privateDnsName": "string",
#                 "privateIpAddress": "string"
#               }
#             ],
#             "publicDnsName": "string",
#             "publicIp": "string",
#             "securityGroups": [
#               {
#                 "groupId": "string",
#                 "groupName": "string"
#               }
#             ],
#             "subnetId": "string",
#             "vpcId": "string"
#           }
#         ],
#         "schemaVersion": number,
#         "tags": [
#           {
#             "key": "string",
#             "value": "string"
#           }
#         ]
#       },
#       "assetType": "string",
#       "attributes": [
#         {
#           "key": "string",
#           "value": "string"
#         }
#       ],
#       "confidence": number,
#       "createdAt": number,
#       "description": "string",
#       "id": "string",
#       "indicatorOfCompromise": boolean,
#       "numericSeverity": number,
#       "recommendation": "string",
#       "schemaVersion": number,
#       "service": "string",
#       "serviceAttributes": {
#         "assessmentRunArn": "string",
#         "rulesPackageArn": "string",
#         "schemaVersion": number
#       },
#       "severity": "string",
#       "title": "string",
#       "updatedAt": number,
#       "userAttributes": [
#         {
#           "key": "string",
#           "value": "string"
#         }
#       ]
#     }
#   ]
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp