Chilkat Online Tools

GetServerDetails Swift3 Example

Migration Hub Strategy Recommendations

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.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.)
    authAws.region = "us-west-2"
    authAws.serviceName = "migrationhub-strategy"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("migrationhub-strategy.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "GetServerDetails")

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/get-server-details/{serverId}", sb: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(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

    var id: String?
    var name: String?
    var count: Int
    var strategy: String?
    var severity: String?
    var interfaceName: String?
    var ipAddress: String?
    var macAddress: String?
    var netMask: String?

    var nextToken: String? = jResp.string(of: "nextToken")
    var S3Bucket: String? = jResp.string(of: "serverDetail.antipatternReportS3Object.s3Bucket")
    var S3key: String? = jResp.string(of: "serverDetail.antipatternReportS3Object.s3key")
    var AntipatternReportStatus: String? = jResp.string(of: "serverDetail.antipatternReportStatus")
    var AntipatternReportStatusMessage: String? = jResp.string(of: "serverDetail.antipatternReportStatusMessage")
    var DataCollectionStatus: String? = jResp.string(of: "serverDetail.dataCollectionStatus")
    var Id: String? = jResp.string(of: "serverDetail.id")
    var LastAnalyzedTimestamp: Int = jResp.int(of: "serverDetail.lastAnalyzedTimestamp").intValue
    var Name: String? = jResp.string(of: "serverDetail.name")
    var Strategy: String? = jResp.string(of: "serverDetail.recommendationSet.strategy")
    var TargetDestination: String? = jResp.string(of: "serverDetail.recommendationSet.targetDestination")
    var Description: String? = jResp.string(of: "serverDetail.recommendationSet.transformationTool.description")
    var TransformationToolName: String? = jResp.string(of: "serverDetail.recommendationSet.transformationTool.name")
    var TranformationToolInstallationLink: String? = jResp.string(of: "serverDetail.recommendationSet.transformationTool.tranformationToolInstallationLink")
    var ServerType: String? = jResp.string(of: "serverDetail.serverType")
    var StatusMessage: String? = jResp.string(of: "serverDetail.statusMessage")
    var CpuArchitecture: String? = jResp.string(of: "serverDetail.systemInfo.cpuArchitecture")
    var FileSystemType: String? = jResp.string(of: "serverDetail.systemInfo.fileSystemType")
    var v_Type: String? = jResp.string(of: "serverDetail.systemInfo.osInfo.type")
    var Version: String? = jResp.string(of: "serverDetail.systemInfo.osInfo.version")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "associatedApplications").intValue
    while i < count_i {
        jResp.i = i
        id = jResp.string(of: "associatedApplications[i].id")
        name = jResp.string(of: "associatedApplications[i].name")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "serverDetail.applicationComponentStrategySummary").intValue
    while i < count_i {
        jResp.i = i
        count = jResp.int(of: "serverDetail.applicationComponentStrategySummary[i].count").intValue
        strategy = jResp.string(of: "serverDetail.applicationComponentStrategySummary[i].strategy")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "serverDetail.listAntipatternSeveritySummary").intValue
    while i < count_i {
        jResp.i = i
        count = jResp.int(of: "serverDetail.listAntipatternSeveritySummary[i].count").intValue
        severity = jResp.string(of: "serverDetail.listAntipatternSeveritySummary[i].severity")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "serverDetail.systemInfo.networkInfoList").intValue
    while i < count_i {
        jResp.i = i
        interfaceName = jResp.string(of: "serverDetail.systemInfo.networkInfoList[i].interfaceName")
        ipAddress = jResp.string(of: "serverDetail.systemInfo.networkInfoList[i].ipAddress")
        macAddress = jResp.string(of: "serverDetail.systemInfo.networkInfoList[i].macAddress")
        netMask = jResp.string(of: "serverDetail.systemInfo.networkInfoList[i].netMask")
        i = i + 1
    }

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

}