Chilkat Online Tools

GetServerDetails Foxpro Example

Migration Hub Strategy Recommendations

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcId
LOCAL lcName
LOCAL lnCount
LOCAL lcStrategy
LOCAL lcSeverity
LOCAL lcInterfaceName
LOCAL lcIpAddress
LOCAL lcMacAddress
LOCAL lcNetMask
LOCAL lcNextToken
LOCAL lcS3Bucket
LOCAL lcS3key
LOCAL lcAntipatternReportStatus
LOCAL lcAntipatternReportStatusMessage
LOCAL lcDataCollectionStatus
LOCAL lcId
LOCAL lnLastAnalyzedTimestamp
LOCAL lcName
LOCAL lcStrategy
LOCAL lcTargetDestination
LOCAL lcDescription
LOCAL lcTransformationToolName
LOCAL lcTranformationToolInstallationLink
LOCAL lcServerType
LOCAL lcStatusMessage
LOCAL lcCpuArchitecture
LOCAL lcFileSystemType
LOCAL lcV_Type
LOCAL lcVersion
LOCAL i
LOCAL lnCount_i

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

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "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.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "migrationhub-strategy"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("migrationhub-strategy.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","GetServerDetails")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/get-server-details/{serverId}",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* 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

lcNextToken = loJResp.StringOf("nextToken")
lcS3Bucket = loJResp.StringOf("serverDetail.antipatternReportS3Object.s3Bucket")
lcS3key = loJResp.StringOf("serverDetail.antipatternReportS3Object.s3key")
lcAntipatternReportStatus = loJResp.StringOf("serverDetail.antipatternReportStatus")
lcAntipatternReportStatusMessage = loJResp.StringOf("serverDetail.antipatternReportStatusMessage")
lcDataCollectionStatus = loJResp.StringOf("serverDetail.dataCollectionStatus")
lcId = loJResp.StringOf("serverDetail.id")
lnLastAnalyzedTimestamp = loJResp.IntOf("serverDetail.lastAnalyzedTimestamp")
lcName = loJResp.StringOf("serverDetail.name")
lcStrategy = loJResp.StringOf("serverDetail.recommendationSet.strategy")
lcTargetDestination = loJResp.StringOf("serverDetail.recommendationSet.targetDestination")
lcDescription = loJResp.StringOf("serverDetail.recommendationSet.transformationTool.description")
lcTransformationToolName = loJResp.StringOf("serverDetail.recommendationSet.transformationTool.name")
lcTranformationToolInstallationLink = loJResp.StringOf("serverDetail.recommendationSet.transformationTool.tranformationToolInstallationLink")
lcServerType = loJResp.StringOf("serverDetail.serverType")
lcStatusMessage = loJResp.StringOf("serverDetail.statusMessage")
lcCpuArchitecture = loJResp.StringOf("serverDetail.systemInfo.cpuArchitecture")
lcFileSystemType = loJResp.StringOf("serverDetail.systemInfo.fileSystemType")
lcV_Type = loJResp.StringOf("serverDetail.systemInfo.osInfo.type")
lcVersion = loJResp.StringOf("serverDetail.systemInfo.osInfo.version")
i = 0
lnCount_i = loJResp.SizeOfArray("associatedApplications")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcId = loJResp.StringOf("associatedApplications[i].id")
    lcName = loJResp.StringOf("associatedApplications[i].name")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("serverDetail.applicationComponentStrategySummary")
DO WHILE i < lnCount_i
    loJResp.I = i
    lnCount = loJResp.IntOf("serverDetail.applicationComponentStrategySummary[i].count")
    lcStrategy = loJResp.StringOf("serverDetail.applicationComponentStrategySummary[i].strategy")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("serverDetail.listAntipatternSeveritySummary")
DO WHILE i < lnCount_i
    loJResp.I = i
    lnCount = loJResp.IntOf("serverDetail.listAntipatternSeveritySummary[i].count")
    lcSeverity = loJResp.StringOf("serverDetail.listAntipatternSeveritySummary[i].severity")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("serverDetail.systemInfo.networkInfoList")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcInterfaceName = loJResp.StringOf("serverDetail.systemInfo.networkInfoList[i].interfaceName")
    lcIpAddress = loJResp.StringOf("serverDetail.systemInfo.networkInfoList[i].ipAddress")
    lcMacAddress = loJResp.StringOf("serverDetail.systemInfo.networkInfoList[i].macAddress")
    lcNetMask = loJResp.StringOf("serverDetail.systemInfo.networkInfoList[i].netMask")
    i = i + 1
ENDDO

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

* {
*   "associatedApplications": [
*     {
*       "id": "string",
*       "name": "string"
*     }
*   ],
*   "nextToken": "string",
*   "serverDetail": {
*     "antipatternReportS3Object": {
*       "s3Bucket": "string",
*       "s3key": "string"
*     },
*     "antipatternReportStatus": "string",
*     "antipatternReportStatusMessage": "string",
*     "applicationComponentStrategySummary": [
*       {
*         "count": number,
*         "strategy": "string"
*       }
*     ],
*     "dataCollectionStatus": "string",
*     "id": "string",
*     "lastAnalyzedTimestamp": number,
*     "listAntipatternSeveritySummary": [
*       {
*         "count": number,
*         "severity": "string"
*       }
*     ],
*     "name": "string",
*     "recommendationSet": {
*       "strategy": "string",
*       "targetDestination": "string",
*       "transformationTool": {
*         "description": "string",
*         "name": "string",
*         "tranformationToolInstallationLink": "string"
*       }
*     },
*     "serverType": "string",
*     "statusMessage": "string",
*     "systemInfo": {
*       "cpuArchitecture": "string",
*       "fileSystemType": "string",
*       "networkInfoList": [
*         {
*           "interfaceName": "string",
*           "ipAddress": "string",
*           "macAddress": "string",
*           "netMask": "string"
*         }
*       ],
*       "osInfo": {
*         "type": "string",
*         "version": "string"
*       }
*     }
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loSbResponseBody
RELEASE loJResp