Sample code for 30+ languages & platforms
Rust

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

Rust

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

let http = chilkat::Http::new();

// Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/azureToken.json").is_ok();
// Assuming success..
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
println!("AuthToken: {}", http.auth_token());

http.set_accept("application/json");

let resp = chilkat::HttpResponse::new();
if http.http_no_body("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).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Response Status Code: {}", resp.status_code());

let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&resp.body_str());
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());

if resp.status_code() != 200 {
    println!("Failed.");
    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=######"
// }
// 

let mut i: i32 = 0;

let next_link = json_response.string_of("nextLink").unwrap_or_default();
i = 0;
let count_i = json_response.size_of_array("value");
while i < count_i {
    json_response.set_i(i);
    let _ = json_response.string_of("value[i].authorization.action").unwrap_or_default();
    let _ = json_response.string_of("value[i].authorization.role").unwrap_or_default();
    let _ = json_response.string_of("value[i].authorization.scope").unwrap_or_default();
    let _ = json_response.string_of("value[i].caller").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.aud").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.iss").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.iat").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.nbf").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.exp").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.ver").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.microsoft.com/identity/claims/tenantid\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.microsoft.com/claims/authnmethodsreferences\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.microsoft.com/identity/claims/objectidentifier\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.puid").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.name").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.groups").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.appid").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.appidacr").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.microsoft.com/identity/claims/scope\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].claims.\"http://schemas.microsoft.com/claims/authnclassreference\"").unwrap_or_default();
    let _ = json_response.string_of("value[i].correlationId").unwrap_or_default();
    let _ = json_response.string_of("value[i].description").unwrap_or_default();
    let _ = json_response.string_of("value[i].eventDataId").unwrap_or_default();
    let _ = json_response.string_of("value[i].eventName.value").unwrap_or_default();
    let _ = json_response.string_of("value[i].eventName.localizedValue").unwrap_or_default();
    let _ = json_response.string_of("value[i].httpRequest.clientRequestId").unwrap_or_default();
    let _ = json_response.string_of("value[i].httpRequest.clientIpAddress").unwrap_or_default();
    let _ = json_response.string_of("value[i].httpRequest.method").unwrap_or_default();
    let _ = json_response.string_of("value[i].id").unwrap_or_default();
    let _ = json_response.string_of("value[i].level").unwrap_or_default();
    let _ = json_response.string_of("value[i].resourceGroupName").unwrap_or_default();
    let _ = json_response.string_of("value[i].resourceProviderName.value").unwrap_or_default();
    let _ = json_response.string_of("value[i].resourceProviderName.localizedValue").unwrap_or_default();
    let _ = json_response.string_of("value[i].operationId").unwrap_or_default();
    let _ = json_response.string_of("value[i].operationName.value").unwrap_or_default();
    let _ = json_response.string_of("value[i].operationName.localizedValue").unwrap_or_default();
    let _ = json_response.string_of("value[i].properties.statusCode").unwrap_or_default();
    let _ = json_response.string_of("value[i].status.value").unwrap_or_default();
    let _ = json_response.string_of("value[i].status.localizedValue").unwrap_or_default();
    let _ = json_response.string_of("value[i].subStatus.value").unwrap_or_default();
    let _ = json_response.string_of("value[i].subStatus.localizedValue").unwrap_or_default();
    let _ = json_response.string_of("value[i].eventTimestamp").unwrap_or_default();
    let _ = json_response.string_of("value[i].submissionTimestamp").unwrap_or_default();
    let _ = json_response.string_of("value[i].subscriptionId").unwrap_or_default();
    i = i + 1;
}