创建 alertRule
本文内容
命名空间:microsoft.graph.deviceManagement
重要
Microsoft Graph 中版本下的 /beta
API 可能会更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 在 v1.0 中是否可用,请使用 版本 选择器。
创建 alertRule 对象。
权限
调用此 API 需要以下权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
CloudPC.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
CloudPC.ReadWrite.All
HTTP 请求
POST /deviceManagement/monitoring/alertRules
名称
说明
Authorization
持有者 {token}。 必填。
Content-Type
application/json. 必需。
请求正文
在请求正文中,仅 提供应更新的属性的值。 请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。
下表指定可更新的属性。
属性
类型
说明
alertRuleTemplate
alertRuleTemplate
警报事件的规则模板。 可能的值包括 cloudPcProvisionScenario
、cloudPcImageUploadScenario
、cloudPcOnPremiseNetworkConnectionCheckScenario
、unknownFutureValue
。
说明
String
规则说明。
displayName
String
规则的显示名称。
enabled
Boolean
指示规则是启用还是禁用的规则的状态。 如果 true
为 ,则启用规则;否则禁用该规则。
isSystemRule
Boolean
指示规则是否为系统规则。 如果 true
为 ,则规则是系统规则;否则,该规则是自定义定义的规则,可以编辑。 系统规则是内置的,只能编辑几个属性。
notificationChannels
microsoft.graph.deviceManagement.notificationChannel 集合
用户选择的规则的通知通道。
severity
ruleSeverityType
规则的严重性。 可能的值包括 unknown
、informational
、warning
、critical
、unknownFutureValue
。
阈 值
microsoft.graph.deviceManagement.ruleThreshold
规则的阈值。
响应
如果成功,此方法在 201 Created
响应正文中返回响应代码和 microsoft.graph.deviceManagement.alertRule 对象。
示例
请求
请求示例如下所示。
POST https://graph.microsoft.com/beta/deviceManagement/monitoring/alertRules
Content-Type: application/json
{
"id": "215c55cc-b1c9-4d36-a870-be5778101714",
"displayName": "Azure network connection failure impacting Cloud PCs",
"severity": "informational",
"isSystemRule": true,
"description": "Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs",
"enabled": true,
"alertRuleTemplate": "cloudPcOnPremiseNetworkConnectionCheckScenario",
"threshold": {
"aggregation": "count",
"operator": "greaterOrEqual",
"target": 90
},
"notificationChannels": [
{
"notificationChannelType": "portal",
"receivers": [
""
],
"notificationReceivers": []
},
{
"notificationChannelType": "email",
"receivers": [
"serena.davis@contoso.com"
],
"notificationReceivers": [
{
"locale": "en-us",
"contactInformation": "serena.davis@contoso.com"
}
]
}
]
}
const options = {
authProvider,
};
const client = Client.init(options);
const alertRule = {
id: '215c55cc-b1c9-4d36-a870-be5778101714',
displayName: 'Azure network connection failure impacting Cloud PCs',
severity: 'informational',
isSystemRule: true,
description: 'Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs',
enabled: true,
alertRuleTemplate: 'cloudPcOnPremiseNetworkConnectionCheckScenario',
threshold: {
aggregation: 'count',
operator: 'greaterOrEqual',
target: 90
},
notificationChannels: [
{
notificationChannelType: 'portal',
receivers: [
''
],
notificationReceivers: []
},
{
notificationChannelType: 'email',
receivers: [
'serena.davis@contoso.com'
],
notificationReceivers: [
{
locale: 'en-us',
contactInformation: 'serena.davis@contoso.com'
}
]
}
]
};
await client.api('/deviceManagement/monitoring/alertRules')
.version('beta')
.post(alertRule);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
AlertRule alertRule = new AlertRule();
alertRule.id = "215c55cc-b1c9-4d36-a870-be5778101714";
alertRule.displayName = "Azure network connection failure impacting Cloud PCs";
alertRule.severity = RuleSeverityType.INFORMATIONAL;
alertRule.isSystemRule = true;
alertRule.description = "Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs";
alertRule.enabled = true;
alertRule.alertRuleTemplate = AlertRuleTemplate.CLOUD_PC_ON_PREMISE_NETWORK_CONNECTION_CHECK_SCENARIO;
RuleThreshold threshold = new RuleThreshold();
threshold.aggregation = AggregationType.COUNT;
threshold.operator = OperatorType.GREATER_OR_EQUAL;
threshold.target = 90;
alertRule.threshold = threshold;
LinkedList<NotificationChannel> notificationChannelsList = new LinkedList<NotificationChannel>();
NotificationChannel notificationChannels = new NotificationChannel();
notificationChannels.notificationChannelType = NotificationChannelType.PORTAL;
LinkedList<String> receiversList = new LinkedList<String>();
receiversList.add("");
notificationChannels.receivers = receiversList;
LinkedList<NotificationReceiver> notificationReceiversList = new LinkedList<NotificationReceiver>();
notificationChannels.notificationReceivers = notificationReceiversList;
notificationChannelsList.add(notificationChannels);
NotificationChannel notificationChannels1 = new NotificationChannel();
notificationChannels1.notificationChannelType = NotificationChannelType.EMAIL;
LinkedList<String> receiversList1 = new LinkedList<String>();
receiversList1.add("serena.davis@contoso.com");
notificationChannels1.receivers = receiversList1;
LinkedList<NotificationReceiver> notificationReceiversList1 = new LinkedList<NotificationReceiver>();
NotificationReceiver notificationReceivers = new NotificationReceiver();
notificationReceivers.locale = "en-us";
notificationReceivers.contactInformation = "serena.davis@contoso.com";
notificationReceiversList1.add(notificationReceivers);
notificationChannels1.notificationReceivers = notificationReceiversList1;
notificationChannelsList.add(notificationChannels1);
alertRule.notificationChannels = notificationChannelsList;
graphClient.deviceManagement().monitoring().alertRules()
.buildRequest()
.post(alertRule);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewAlertRule()
id := "215c55cc-b1c9-4d36-a870-be5778101714"
requestBody.SetId(&id)
displayName := "Azure network connection failure impacting Cloud PCs"
requestBody.SetDisplayName(&displayName)
severity := graphmodels.INFORMATIONAL_RULESEVERITYTYPE
requestBody.SetSeverity(&severity)
isSystemRule := true
requestBody.SetIsSystemRule(&isSystemRule)
description := "Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs"
requestBody.SetDescription(&description)
enabled := true
requestBody.SetEnabled(&enabled)
alertRuleTemplate := graphmodels.CLOUDPCONPREMISENETWORKCONNECTIONCHECKSCENARIO_ALERTRULETEMPLATE
requestBody.SetAlertRuleTemplate(&alertRuleTemplate)
threshold := graphmodels.NewRuleThreshold()
aggregation := graphmodels.COUNT_AGGREGATIONTYPE
threshold.SetAggregation(&aggregation)
operator := graphmodels.GREATEROREQUAL_OPERATORTYPE
threshold.SetOperator(&operator)
target := int32(90)
threshold.SetTarget(&target)
requestBody.SetThreshold(threshold)
notificationChannel := graphmodels.NewNotificationChannel()
notificationChannelType := graphmodels.PORTAL_NOTIFICATIONCHANNELTYPE
notificationChannel.SetNotificationChannelType(¬ificationChannelType)
receivers := []string {
"",
}
notificationChannel.SetReceivers(receivers)
notificationReceivers := []graphmodels.NotificationReceiverable {
}
notificationChannel.SetNotificationReceivers(notificationReceivers)
notificationChannel1 := graphmodels.NewNotificationChannel()
notificationChannelType := graphmodels.EMAIL_NOTIFICATIONCHANNELTYPE
notificationChannel1.SetNotificationChannelType(¬ificationChannelType)
receivers := []string {
"serena.davis@contoso.com",
}
notificationChannel1.SetReceivers(receivers)
notificationReceiver := graphmodels.NewNotificationReceiver()
locale := "en-us"
notificationReceiver.SetLocale(&locale)
contactInformation := "serena.davis@contoso.com"
notificationReceiver.SetContactInformation(&contactInformation)
notificationReceivers := []graphmodels.NotificationReceiverable {
notificationReceiver,
}
notificationChannel1.SetNotificationReceivers(notificationReceivers)
notificationChannels := []graphmodels.NotificationChannelable {
notificationChannel,
notificationChannel1,
}
requestBody.SetNotificationChannels(notificationChannels)
result, err := graphClient.DeviceManagement().Monitoring().AlertRules().Post(context.Background(), requestBody, nil)
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new AlertRule();
$requestBody->setId('215c55cc-b1c9-4d36-a870-be5778101714');
$requestBody->setDisplayName('Azure network connection failure impacting Cloud PCs');
$requestBody->setSeverity(new RuleSeverityType('informational'));
$requestBody->setIsSystemRule(true);
$requestBody->setDescription('Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs');
$requestBody->setEnabled(true);
$requestBody->setAlertRuleTemplate(new AlertRuleTemplate('cloudpconpremisenetworkconnectioncheckscenario'));
$threshold = new RuleThreshold();
$threshold->setAggregation(new AggregationType('count'));
$threshold->setOperator(new OperatorType('greaterorequal'));
$threshold->setTarget(90);
$requestBody->setThreshold($threshold);
$notificationChannelsNotificationChannel1 = new NotificationChannel();
$notificationChannelsNotificationChannel1->setNotificationChannelType(new NotificationChannelType('portal'));
$notificationChannelsNotificationChannel1->setReceivers(['', ]);
$notificationChannelsNotificationChannel1->setNotificationReceivers([]);
$notificationChannelsArray []= $notificationChannelsNotificationChannel1;
$notificationChannelsNotificationChannel2 = new NotificationChannel();
$notificationChannelsNotificationChannel2->setNotificationChannelType(new NotificationChannelType('email'));
$notificationChannelsNotificationChannel2->setReceivers(['serena.davis@contoso.com', ]);
$notificationReceiversNotificationReceiver1 = new NotificationReceiver();
$notificationReceiversNotificationReceiver1->setLocale('en-us');
$notificationReceiversNotificationReceiver1->setContactInformation('serena.davis@contoso.com');
$notificationReceiversArray []= $notificationReceiversNotificationReceiver1;
$notificationChannelsNotificationChannel2->setNotificationReceivers($notificationReceiversArray);
$notificationChannelsArray []= $notificationChannelsNotificationChannel2;
$requestBody->setNotificationChannels($notificationChannelsArray);
$requestResult = $graphServiceClient->deviceManagement()->monitoring()->alertRules()->post($requestBody);
响应
下面展示了示例响应。
HTTP/1.1 201 CREATED
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#deviceManagement/monitoring/alertRules/$entity",
"id": "215c55cc-b1c9-4d36-a870-be5778101714",
"displayName": "Azure network connection failure impacting Cloud PCs",
"severity": "informational",
"isSystemRule": true,
"description": "Azure network connection checks have failed and is potentially impacting existing Cloud PCs and blocking the provisioning of new Cloud PCs",
"enabled": true,
"alertRuleTemplate": "cloudPcOnPremiseNetworkConnectionCheckScenario",
"threshold": {
"aggregation": "count",
"operator": "greaterOrEqual",
"target": 90
},
"notificationChannels": [
{
"notificationChannelType": "portal",
"receivers": [
""
],
"notificationReceivers": []
},
{
"notificationChannelType": "email",
"receivers": [
"serena.davis@contoso.com"
],
"notificationReceivers": [
{
"locale": "en-us",
"contactInformation": "serena.davis@contoso.com"
}
]
}
]
}