Sample code for 30+ languages & platforms
Zig

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 Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

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

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    const json_token = try chilkat.JsonObject.init();
    defer json_token.deinit();
    try json_token.loadFile("qa_data/tokens/azureToken.json");
    // Assuming success..
    http.setAuthToken(try json_token.stringOf(alloc, "access_token"));
    std.debug.print("AuthToken: {s}\n", .{try http.getAuthToken(alloc)});

    http.setAccept("application/json");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("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) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});

    const json_response = try chilkat.JsonObject.init();
    defer json_response.deinit();
    json_response.load(try resp.getBodyStr(alloc)) catch {};
    json_response.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json_response.emit(alloc)});

    if (resp.getStatusCode() != 200) {
        std.debug.print("Failed.\n", .{});
        return;
    }

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

    var i: i32 = 0;
    var authorization_action: [:0]const u8 = "";
    var authorization_role: [:0]const u8 = "";
    var authorization_scope: [:0]const u8 = "";
    var caller: [:0]const u8 = "";
    var claims_aud: [:0]const u8 = "";
    var claims_iss: [:0]const u8 = "";
    var claims_iat: [:0]const u8 = "";
    var claims_nbf: [:0]const u8 = "";
    var claims_exp: [:0]const u8 = "";
    var claims_ver: [:0]const u8 = "";
    var claims_identity_claims_tenantid: [:0]const u8 = "";
    var claims_claims_authnmethodsreferences: [:0]const u8 = "";
    var claims_identity_claims_objectidentifier: [:0]const u8 = "";
    var claims_ws_2005_05_identity_claims_upn: [:0]const u8 = "";
    var claims_puid: [:0]const u8 = "";
    var claims_ws_2005_05_identity_claims_nameidentifier: [:0]const u8 = "";
    var claims_ws_2005_05_identity_claims_givenname: [:0]const u8 = "";
    var claims_ws_2005_05_identity_claims_surname: [:0]const u8 = "";
    var claims_name: [:0]const u8 = "";
    var claims_groups: [:0]const u8 = "";
    var claims_ws_2005_05_identity_claims_name: [:0]const u8 = "";
    var claims_appid: [:0]const u8 = "";
    var claims_appidacr: [:0]const u8 = "";
    var claims_identity_claims_scope: [:0]const u8 = "";
    var claims_claims_authnclassreference: [:0]const u8 = "";
    var correlation_id: [:0]const u8 = "";
    var description: [:0]const u8 = "";
    var event_data_id: [:0]const u8 = "";
    var event_name_value: [:0]const u8 = "";
    var event_name_localized_value: [:0]const u8 = "";
    var http_request_client_request_id: [:0]const u8 = "";
    var http_request_client_ip_address: [:0]const u8 = "";
    var http_request_method: [:0]const u8 = "";
    var id: [:0]const u8 = "";
    var level: [:0]const u8 = "";
    var resource_group_name: [:0]const u8 = "";
    var resource_provider_name_value: [:0]const u8 = "";
    var resource_provider_name_localized_value: [:0]const u8 = "";
    var operation_id: [:0]const u8 = "";
    var operation_name_value: [:0]const u8 = "";
    var operation_name_localized_value: [:0]const u8 = "";
    var properties_status_code: [:0]const u8 = "";
    var status_value: [:0]const u8 = "";
    var status_localized_value: [:0]const u8 = "";
    var sub_status_value: [:0]const u8 = "";
    var sub_status_localized_value: [:0]const u8 = "";
    var event_timestamp: [:0]const u8 = "";
    var submission_timestamp: [:0]const u8 = "";
    var subscription_id: [:0]const u8 = "";

    _ = try json_response.stringOf(alloc, "nextLink");
    i = 0;
    const count_i = json_response.sizeOfArray("value");
    while (i < count_i) {
        json_response.setI(i);
        authorization_action = try json_response.stringOf(alloc, "value[i].authorization.action");
        authorization_role = try json_response.stringOf(alloc, "value[i].authorization.role");
        authorization_scope = try json_response.stringOf(alloc, "value[i].authorization.scope");
        caller = try json_response.stringOf(alloc, "value[i].caller");
        claims_aud = try json_response.stringOf(alloc, "value[i].claims.aud");
        claims_iss = try json_response.stringOf(alloc, "value[i].claims.iss");
        claims_iat = try json_response.stringOf(alloc, "value[i].claims.iat");
        claims_nbf = try json_response.stringOf(alloc, "value[i].claims.nbf");
        claims_exp = try json_response.stringOf(alloc, "value[i].claims.exp");
        claims_ver = try json_response.stringOf(alloc, "value[i].claims.ver");
        claims_identity_claims_tenantid = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.microsoft.com/identity/claims/tenantid\"");
        claims_claims_authnmethodsreferences = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.microsoft.com/claims/authnmethodsreferences\"");
        claims_identity_claims_objectidentifier = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.microsoft.com/identity/claims/objectidentifier\"");
        claims_ws_2005_05_identity_claims_upn = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn\"");
        claims_puid = try json_response.stringOf(alloc, "value[i].claims.puid");
        claims_ws_2005_05_identity_claims_nameidentifier = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\"");
        claims_ws_2005_05_identity_claims_givenname = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\"");
        claims_ws_2005_05_identity_claims_surname = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\"");
        claims_name = try json_response.stringOf(alloc, "value[i].claims.name");
        claims_groups = try json_response.stringOf(alloc, "value[i].claims.groups");
        claims_ws_2005_05_identity_claims_name = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"");
        claims_appid = try json_response.stringOf(alloc, "value[i].claims.appid");
        claims_appidacr = try json_response.stringOf(alloc, "value[i].claims.appidacr");
        claims_identity_claims_scope = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.microsoft.com/identity/claims/scope\"");
        claims_claims_authnclassreference = try json_response.stringOf(alloc, "value[i].claims.\"http://schemas.microsoft.com/claims/authnclassreference\"");
        correlation_id = try json_response.stringOf(alloc, "value[i].correlationId");
        description = try json_response.stringOf(alloc, "value[i].description");
        event_data_id = try json_response.stringOf(alloc, "value[i].eventDataId");
        event_name_value = try json_response.stringOf(alloc, "value[i].eventName.value");
        event_name_localized_value = try json_response.stringOf(alloc, "value[i].eventName.localizedValue");
        http_request_client_request_id = try json_response.stringOf(alloc, "value[i].httpRequest.clientRequestId");
        http_request_client_ip_address = try json_response.stringOf(alloc, "value[i].httpRequest.clientIpAddress");
        http_request_method = try json_response.stringOf(alloc, "value[i].httpRequest.method");
        id = try json_response.stringOf(alloc, "value[i].id");
        level = try json_response.stringOf(alloc, "value[i].level");
        resource_group_name = try json_response.stringOf(alloc, "value[i].resourceGroupName");
        resource_provider_name_value = try json_response.stringOf(alloc, "value[i].resourceProviderName.value");
        resource_provider_name_localized_value = try json_response.stringOf(alloc, "value[i].resourceProviderName.localizedValue");
        operation_id = try json_response.stringOf(alloc, "value[i].operationId");
        operation_name_value = try json_response.stringOf(alloc, "value[i].operationName.value");
        operation_name_localized_value = try json_response.stringOf(alloc, "value[i].operationName.localizedValue");
        properties_status_code = try json_response.stringOf(alloc, "value[i].properties.statusCode");
        status_value = try json_response.stringOf(alloc, "value[i].status.value");
        status_localized_value = try json_response.stringOf(alloc, "value[i].status.localizedValue");
        sub_status_value = try json_response.stringOf(alloc, "value[i].subStatus.value");
        sub_status_localized_value = try json_response.stringOf(alloc, "value[i].subStatus.localizedValue");
        event_timestamp = try json_response.stringOf(alloc, "value[i].eventTimestamp");
        submission_timestamp = try json_response.stringOf(alloc, "value[i].submissionTimestamp");
        subscription_id = try json_response.stringOf(alloc, "value[i].subscriptionId");
        i = i + 1;
    }
}