PATCH https://management.azure.com/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/providers/Microsoft.Insights/logprofiles/Rac46PostSwapRG?api-version=2016-03-01
{
"tags": {
"key1": "value1"
},
"properties": {
"locations": [
"global"
],
"categories": [
"Write",
"Delete",
"Action"
],
"retentionPolicy": {
"enabled": true,
"days": 3
},
"storageAccountId": "/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162",
"serviceBusRuleId": ""
}
}
import com.azure.resourcemanager.monitor.models.LogProfileResourcePatch;
import com.azure.resourcemanager.monitor.models.RetentionPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for LogProfiles Update.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/monitor/resource-manager/Microsoft.Insights/stable/2016-03-01/examples/patchLogProfile.json
*/
/**
* Sample code: Patch a log profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void patchALogProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getLogProfiles().updateWithResponse("Rac46PostSwapRG",
new LogProfileResourcePatch().withTags(mapOf("key1", "fakeTokenPlaceholder")).withStorageAccountId(
"/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162")
.withServiceBusRuleId("").withLocations(Arrays.asList("global"))
.withCategories(Arrays.asList("Write", "Delete", "Action")).withRetentionPolicy(
new RetentionPolicy().withEnabled(true).withDays(3)),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python patch_log_profile.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="df602c9c-7aa0-407d-a6fb-eb20c8bd1192",
)
response = client.log_profiles.update(
log_profile_name="Rac46PostSwapRG",
log_profiles_resource={
"properties": {
"categories": ["Write", "Delete", "Action"],
"locations": ["global"],
"retentionPolicy": {"days": 3, "enabled": True},
"serviceBusRuleId": "",
"storageAccountId": "/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162",
},
"tags": {"key1": "value1"},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2016-03-01/examples/patchLogProfile.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2016-03-01/examples/patchLogProfile.json
func ExampleLogProfilesClient_Update() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewLogProfilesClient().Update(ctx, "Rac46PostSwapRG", armmonitor.LogProfileResourcePatch{
Properties: &armmonitor.LogProfileProperties{
Categories: []*string{
to.Ptr("Write"),
to.Ptr("Delete"),
to.Ptr("Action")},
Locations: []*string{
to.Ptr("global")},
RetentionPolicy: &armmonitor.RetentionPolicy{
Days: to.Ptr[int32](3),
Enabled: to.Ptr(true),
},
ServiceBusRuleID: to.Ptr(""),
StorageAccountID: to.Ptr("/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162"),
},
Tags: map[string]*string{
"key1": to.Ptr("value1"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.LogProfileResource = armmonitor.LogProfileResource{
// Name: to.Ptr("default"),
// Type: to.Ptr(""),
// ID: to.Ptr("/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/providers/microsoft.insights/logprofiles/default"),
// Location: to.Ptr(""),
// Tags: map[string]*string{
// "key1": to.Ptr("value1"),
// },
// Properties: &armmonitor.LogProfileProperties{
// Categories: []*string{
// to.Ptr("Delete"),
// to.Ptr("Write"),
// to.Ptr("Action")},
// Locations: []*string{
// to.Ptr("global")},
// RetentionPolicy: &armmonitor.RetentionPolicy{
// Days: to.Ptr[int32](3),
// Enabled: to.Ptr(true),
// },
// ServiceBusRuleID: to.Ptr(""),
// StorageAccountID: to.Ptr("/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Updates an existing LogProfilesResource. To update other fields use the CreateOrUpdate method.
*
* @summary Updates an existing LogProfilesResource. To update other fields use the CreateOrUpdate method.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2016-03-01/examples/patchLogProfile.json
*/
async function patchALogProfile() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "df602c9c-7aa0-407d-a6fb-eb20c8bd1192";
const logProfileName = "Rac46PostSwapRG";
const logProfilesResource = {
categories: ["Write", "Delete", "Action"],
locations: ["global"],
retentionPolicy: { days: 3, enabled: true },
serviceBusRuleId: "",
storageAccountId:
"/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162",
tags: { key1: "value1" },
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.logProfiles.update(logProfileName, logProfilesResource);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2016-03-01/examples/patchLogProfile.json
// this example is just showing the usage of "LogProfiles_Update" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this LogProfileResource created on azure
// for more information of creating LogProfileResource, please refer to the document of LogProfileResource
string subscriptionId = "df602c9c-7aa0-407d-a6fb-eb20c8bd1192";
string logProfileName = "Rac46PostSwapRG";
ResourceIdentifier logProfileResourceId = LogProfileResource.CreateResourceIdentifier(subscriptionId, logProfileName);
LogProfileResource logProfile = client.GetLogProfileResource(logProfileResourceId);
// invoke the operation
LogProfilePatch patch = new LogProfilePatch
{
Tags =
{
["key1"] = "value1"
},
StorageAccountId = new ResourceIdentifier("/subscriptions/df602c9c-7aa0-407d-a6fb-eb20c8bd1192/resourceGroups/JohnKemTest/providers/Microsoft.Storage/storageAccounts/johnkemtest8162"),
ServiceBusRuleId = new ResourceIdentifier(""),
Locations = { new AzureLocation("global") },
Categories = { "Write", "Delete", "Action" },
RetentionPolicy = new RetentionPolicy(true, 3),
};
LogProfileResource result = await logProfile.UpdateAsync(patch);
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
LogProfileData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue