简体   繁体   English

是否可以使用 Azure Graph API 来更改 PIM 中的通知

[英]Is it possible to use Azure Graph API to change Notifications in PIM

I'm new to stackoverflow so if you have any feedback please let me know.我是 stackoverflow 的新手,所以如果您有任何反馈,请告诉我。 I have created a powershell script to set eligible role assignments at ResourceGroups by using the Microsoft (beta) Graph API for PIM: I use invoke-restmethod to call the api like :我创建了一个 powershell 脚本,通过使用 Microsoft(测试版)Graph API 为 PIM 在 ResourceGroups 设置合格的角色分配:我使用 invoke-restmethod 调用 Z8A5DA52ED126447D359E70C0572

$queryApiUri = "https://graph.microsoft.com/beta/privilegedAccess/azureResources/resources/$ResourceID/roleAssignments"
$Headers = @{}
$Headers.Add("Authorization","$($Token.token_type) "+ " " + "$($Token.access_token)")
$query = Invoke-RestMethod -Method Get -Uri $queryApiUri -Headers $Headers

This works fine but people and admins get crazy by all the email that's sent as notification when activating roles.这工作正常,但激活角色时作为通知发送的所有 email 都会让人们和管理员抓狂。 Notifications are sent at creation and activation times and when approvers are needed.在创建和激活时间以及需要批准者时发送通知。 It is possible to set Notifications to 'Critical emails only' at the portal by hand, to eliminate email flooding.可以在门户中手动将通知设置为“仅限关键电子邮件”,以消除 email 泛滥。 Does someone know if this is possible to do this by use of the Graph API?有人知道这是否可以通过使用图表 API 来做到这一点?

When we modify the 'Critical emails only' at the portal and try to get governanceRoleSetting , we will see that there is no change in the result.当我们在门户中修改“Critical emails only”并尝试获取GovernanceRoleSetting时,我们会看到结果没有任何变化。

Obviously Microsoft Graph hasn't exposed the method to update 'Critical emails only'.显然,Microsoft Graph 并没有公开更新“仅限关键电子邮件”的方法。

But in fact, we can make it via Microsoft Graph.但实际上,我们可以通过 Microsoft Graph 实现。 Here I'll share my steps.在这里我将分享我的步骤。 Please note it's not mentioned in Microsoft Graph document.请注意,Microsoft Graph 文档中没有提到它。 It's just for your reference.仅供您参考。

Take subscription owner role as the example.以订阅所有者角色为例。

Open the edit role setting page of subscription owner in the browser and press F12 to open developer tool.在浏览器中打开订阅所有者的编辑角色设置页面,按F12打开开发者工具。 Click on Update .点击更新 Then we will see a request named 'roleSettingsv2'.然后我们将看到一个名为“roleSettingsv2”的请求。 (It is not Microsoft Graph API) (它不是 Microsoft Graph API)

在此处输入图像描述

Looking into the response, we will find such a 'NotificationRule' in it.查看响应,我们会在其中找到这样的“NotificationRule”。

{
    "ruleIdentifier": "NotificationRule",
    "setting": "{\"policies\":[{\"deliveryMechanism\":\"email\",\"setting\":[{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":2},{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":0},{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":1}]}]}"
}

It is missing in Microsoft Graph API. Microsoft Graph API 中缺少它。

So we just need to update this 'NotificationRule' in Microsoft Graph using Update governanceRoleSetting .因此,我们只需要使用UpdateGovernanceRoleSetting在 Microsoft Graph 中更新此“NotificationRule”。

For example:例如:

PATCH https://graph.microsoft.com/beta/privilegedAccess/azureResources/roleSettings/b12d879d-e521-4b0b-971c-7a2b6ac979ba

{
    "adminEligibleSettings": [{
            "ruleIdentifier": "ExpirationRule",
            "setting": "{\"permanentAssignment\":false,\"maximumGrantPeriodInMinutes\":525600}"
        }, {
            "ruleIdentifier": "MfaRule",
            "setting": "{\"mfaRequired\":false}"
        }, {
            "ruleIdentifier": "NotificationRule",
            "setting": "{\"policies\":[{\"deliveryMechanism\":\"email\",\"setting\":[{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":2},{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":0},{\"customreceivers\":null,\"isdefaultreceiverenabled\":true,\"notificationlevel\":2,\"recipienttype\":1}]}]}"
        }
    ]
}

You should set the value for notificationlevel .您应该设置notificationlevel的值。

Please note that \"notificationlevel\":2 is setting 'Critical emails only' as False and \"notificationlevel\":1 is True .请注意\"notificationlevel\":2将 'Critical emails only' 设置为False并且\"notificationlevel\":1True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM