azure-sdk-for-js/sdk/monitor/arm-monitor/samples-dev/metricAlertsUpdateSample.ts

77 строки
2.4 KiB
TypeScript

/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { MetricAlertResourcePatch, MonitorClient } from "@azure/arm-monitor";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
/**
* This sample demonstrates how to Update an metric alert definition.
*
* @summary Update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/UpdateMetricAlert.json
*/
async function createOrUpdateAnAlertRule() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] ||
"14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "chiricutin";
const parameters: MetricAlertResourcePatch = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
criterionType: "StaticThresholdCriterion",
dimensions: [],
metricName: "\\Processor(_Total)\\% Processor Time",
operator: "GreaterThan",
threshold: 80.5,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "Pt1m",
scopes: [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme",
],
severity: 3,
tags: {},
windowSize: "Pt15m",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.update(
resourceGroupName,
ruleName,
parameters,
);
console.log(result);
}
async function main() {
createOrUpdateAnAlertRule();
}
main().catch(console.error);