Sample code for 30+ languages & platforms
PureBasic

Azure Monitor - List Activity Logs

See more Azure Monitor Examples

Provides the list of records from the activity logs.

Note: The $filter criteria cannot specify a time range that begins more than 90 days in the past.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken.i = CkJsonObject::ckCreate()
    If jsonToken.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/azureToken.json")
    ; Assuming success..
    CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token"))
    Debug "AuthToken: " + CkHttp::ckAuthToken(http)

    CkHttp::setCkAccept(http, "application/json")

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpNoBody(http,"GET","https://management.azure.com/subscriptions/{subscriptionId}/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp%20ge%20%272019-05-16T04%3A36%3A37.6407898Z%27%20and%20eventTimestamp%20le%20%272019-06-12T04%3A36%3A37.6407898Z%27",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp))

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResponse,CkHttpResponse::ckBodyStr(resp))
    CkJsonObject::setCkEmitCompact(jsonResponse, 0)
    Debug CkJsonObject::ckEmit(jsonResponse)

    If CkHttpResponse::ckStatusCode(resp) <> 200
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(jsonResponse)
        ProcedureReturn
    EndIf

    ; Sample output...
    ; (See the parsing code below..)
    ; 
    ; Use the this online tool to generate parsing code from sample JSON: 
    ; Generate Parsing Code from JSON

    ; {
    ;   "value": [
    ;     {
    ;       "authorization": {
    ;         "action": "microsoft.support/supporttickets/write",
    ;         "role": "Subscription Admin",
    ;         "scope": "/subscriptions/089bd33f-d4ec-47fe-8ba5-0753aa5c5b33/resourceGroups/MSSupportGroup/providers/microsoft.support/supporttickets/115012112305841"
    ;       },
    ;       "caller": "admin@contoso.com",
    ;       "claims": {
    ;         "aud": "https://management.core.windows.net/",
    ;         "iss": "https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/",
    ;         "iat": "1421876371",
    ;         "nbf": "1421876371",
    ;         "exp": "1421880271",
    ;         "ver": "1.0",
    ;         "http://schemas.microsoft.com/identity/claims/tenantid": "1e8d8218-c5e7-4578-9acc-9abbd5d23315 ",
    ;         "http://schemas.microsoft.com/claims/authnmethodsreferences": "pwd",
    ;         "http://schemas.microsoft.com/identity/claims/objectidentifier": "2468adf0-8211-44e3-95xq-85137af64708",
    ;         "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": "admin@contoso.com",
    ;         "puid": "20030000801A118C",
    ;         "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "9vckmEGF7zDKk1YzIY8k0t1_EAPaXoeHyPRn6f413zM",
    ;         "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": "John",
    ;         "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": "Smith",
    ;         "name": "John Smith",
    ;         "groups": "cacfe77c-e058-4712-83qw-f9b08849fd60,7f71d11d-4c41-4b23-99d2-d32ce7aa621c,31522864-0578-4ea0-9gdc-e66cc564d18c",
    ;         "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": " admin@contoso.com",
    ;         "appid": "c44b4083-3bq0-49c1-b47d-974e53cbdf3c",
    ;         "appidacr": "2",
    ;         "http://schemas.microsoft.com/identity/claims/scope": "user_impersonation",
    ;         "http://schemas.microsoft.com/claims/authnclassreference": "1"
    ;       },
    ;       "correlationId": "1e121103-0ba6-4300-ac9d-952bb5d0c80f",
    ;       "description": "",
    ;       "eventDataId": "44ade6b4-3813-45e6-ae27-7420a95fa2f8",
    ;       "eventName": {
    ;         "value": "EndRequest",
    ;         "localizedValue": "End request"
    ;       },
    ;       "httpRequest": {
    ;         "clientRequestId": "27003b25-91d3-418f-8eb1-29e537dcb249",
    ;         "clientIpAddress": "192.168.35.115",
    ;         "method": "PUT"
    ;       },
    ;       "id": "/subscriptions/089bd33f-d4ec-47fe-8ba5-0753aa5c5b33/resourceGroups/MSSupportGroup/providers/microsoft.support/supporttickets/115012112305841/events/44ade6b4-3813-45e6-ae27-7420a95fa2f8/ticks/635574752669792776",
    ;       "level": "Informational",
    ;       "resourceGroupName": "MSSupportGroup",
    ;       "resourceProviderName": {
    ;         "value": "microsoft.support",
    ;         "localizedValue": "microsoft.support"
    ;       },
    ;       "operationId": "1e121103-0ba6-4300-ac9d-952bb5d0c80f",
    ;       "operationName": {
    ;         "value": "microsoft.support/supporttickets/write",
    ;         "localizedValue": "microsoft.support/supporttickets/write"
    ;       },
    ;       "properties": {
    ;         "statusCode": "Created"
    ;       },
    ;       "status": {
    ;         "value": "Succeeded",
    ;         "localizedValue": "Succeeded"
    ;       },
    ;       "subStatus": {
    ;         "value": "Created",
    ;         "localizedValue": "Created (HTTP Status Code: 201)"
    ;       },
    ;       "eventTimestamp": "2015-01-21T22:14:26.9792776Z",
    ;       "submissionTimestamp": "2015-01-21T22:14:39.9936304Z",
    ;       "subscriptionId": "089bd33f-d4ec-47fe-8ba5-0753aa5c5b33"
    ;     }
    ;   ],
    ;   "nextLink": "https://management.azure.com/########-####-####-####-############$skiptoken=######"
    ; }
    ; 

    nextLink.s
    i.i
    count_i.i
    authorizationAction.s
    authorizationRole.s
    authorizationScope.s
    caller.s
    claimsAud.s
    claimsIss.s
    claimsIat.s
    claimsNbf.s
    claimsExp.s
    claimsVer.s
    claims_identity_claims_tenantid.s
    claims_claims_authnmethodsreferences.s
    claims_identity_claims_objectidentifier.s
    claims_ws_2005_05_identity_claims_upn.s
    claimsPuid.s
    claims_ws_2005_05_identity_claims_nameidentifier.s
    claims_ws_2005_05_identity_claims_givenname.s
    claims_ws_2005_05_identity_claims_surname.s
    claimsName.s
    claimsGroups.s
    claims_ws_2005_05_identity_claims_name.s
    claimsAppid.s
    claimsAppidacr.s
    claims_identity_claims_scope.s
    claims_claims_authnclassreference.s
    correlationId.s
    description.s
    eventDataId.s
    eventNameValue.s
    eventNameLocalizedValue.s
    httpRequestClientRequestId.s
    httpRequestClientIpAddress.s
    httpRequestMethod.s
    id.s
    level.s
    resourceGroupName.s
    resourceProviderNameValue.s
    resourceProviderNameLocalizedValue.s
    operationId.s
    operationNameValue.s
    operationNameLocalizedValue.s
    propertiesStatusCode.s
    statusValue.s
    statusLocalizedValue.s
    subStatusValue.s
    subStatusLocalizedValue.s
    eventTimestamp.s
    submissionTimestamp.s
    subscriptionId.s

    nextLink = CkJsonObject::ckStringOf(jsonResponse,"nextLink")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"value")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        authorizationAction = CkJsonObject::ckStringOf(jsonResponse,"value[i].authorization.action")
        authorizationRole = CkJsonObject::ckStringOf(jsonResponse,"value[i].authorization.role")
        authorizationScope = CkJsonObject::ckStringOf(jsonResponse,"value[i].authorization.scope")
        caller = CkJsonObject::ckStringOf(jsonResponse,"value[i].caller")
        claimsAud = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.aud")
        claimsIss = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.iss")
        claimsIat = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.iat")
        claimsNbf = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.nbf")
        claimsExp = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.exp")
        claimsVer = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.ver")
        claims_identity_claims_tenantid = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.microsoft.com/identity/claims/tenantid" + Chr(34))
        claims_claims_authnmethodsreferences = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.microsoft.com/claims/authnmethodsreferences" + Chr(34))
        claims_identity_claims_objectidentifier = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.microsoft.com/identity/claims/objectidentifier" + Chr(34))
        claims_ws_2005_05_identity_claims_upn = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn" + Chr(34))
        claimsPuid = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.puid")
        claims_ws_2005_05_identity_claims_nameidentifier = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier" + Chr(34))
        claims_ws_2005_05_identity_claims_givenname = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" + Chr(34))
        claims_ws_2005_05_identity_claims_surname = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname" + Chr(34))
        claimsName = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.name")
        claimsGroups = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.groups")
        claims_ws_2005_05_identity_claims_name = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" + Chr(34))
        claimsAppid = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.appid")
        claimsAppidacr = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims.appidacr")
        claims_identity_claims_scope = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.microsoft.com/identity/claims/scope" + Chr(34))
        claims_claims_authnclassreference = CkJsonObject::ckStringOf(jsonResponse,"value[i].claims." + Chr(34) + "http://schemas.microsoft.com/claims/authnclassreference" + Chr(34))
        correlationId = CkJsonObject::ckStringOf(jsonResponse,"value[i].correlationId")
        description = CkJsonObject::ckStringOf(jsonResponse,"value[i].description")
        eventDataId = CkJsonObject::ckStringOf(jsonResponse,"value[i].eventDataId")
        eventNameValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].eventName.value")
        eventNameLocalizedValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].eventName.localizedValue")
        httpRequestClientRequestId = CkJsonObject::ckStringOf(jsonResponse,"value[i].httpRequest.clientRequestId")
        httpRequestClientIpAddress = CkJsonObject::ckStringOf(jsonResponse,"value[i].httpRequest.clientIpAddress")
        httpRequestMethod = CkJsonObject::ckStringOf(jsonResponse,"value[i].httpRequest.method")
        id = CkJsonObject::ckStringOf(jsonResponse,"value[i].id")
        level = CkJsonObject::ckStringOf(jsonResponse,"value[i].level")
        resourceGroupName = CkJsonObject::ckStringOf(jsonResponse,"value[i].resourceGroupName")
        resourceProviderNameValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].resourceProviderName.value")
        resourceProviderNameLocalizedValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].resourceProviderName.localizedValue")
        operationId = CkJsonObject::ckStringOf(jsonResponse,"value[i].operationId")
        operationNameValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].operationName.value")
        operationNameLocalizedValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].operationName.localizedValue")
        propertiesStatusCode = CkJsonObject::ckStringOf(jsonResponse,"value[i].properties.statusCode")
        statusValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].status.value")
        statusLocalizedValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].status.localizedValue")
        subStatusValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].subStatus.value")
        subStatusLocalizedValue = CkJsonObject::ckStringOf(jsonResponse,"value[i].subStatus.localizedValue")
        eventTimestamp = CkJsonObject::ckStringOf(jsonResponse,"value[i].eventTimestamp")
        submissionTimestamp = CkJsonObject::ckStringOf(jsonResponse,"value[i].submissionTimestamp")
        subscriptionId = CkJsonObject::ckStringOf(jsonResponse,"value[i].subscriptionId")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(jsonToken)
    CkHttpResponse::ckDispose(resp)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure