File: post_test_notifications.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (127 lines) | stat: -rw-r--r-- 6,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from azure.identity import DefaultAzureCredential

from azure.mgmt.monitor import MonitorManagementClient

"""
# PREREQUISITES
    pip install azure-identity
    pip install azure-mgmt-monitor
# USAGE
    python post_test_notifications.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="187f412d-1758-44d9-b052-169e2564721d",
    )

    response = client.action_groups.begin_post_test_notifications(
        notification_request={
            "alertType": "budget",
            "armRoleReceivers": [
                {
                    "name": "ArmRole-Common",
                    "roleId": "11111111-1111-1111-1111-111111111111",
                    "useCommonAlertSchema": True,
                },
                {
                    "name": "ArmRole-nonCommon",
                    "roleId": "11111111-1111-1111-1111-111111111111",
                    "useCommonAlertSchema": False,
                },
            ],
            "automationRunbookReceivers": [
                {
                    "automationAccountId": "/subscriptions/187f412d-1758-44d9-b052-169e2564721d/resourceGroups/runbookTest/providers/Microsoft.Automation/automationAccounts/runbooktest",
                    "isGlobalRunbook": False,
                    "name": "testRunbook",
                    "runbookName": "Sample runbook",
                    "serviceUri": "http://test.me",
                    "useCommonAlertSchema": True,
                    "webhookResourceId": "/subscriptions/187f412d-1758-44d9-b052-169e2564721d/resourceGroups/runbookTest/providers/Microsoft.Automation/automationAccounts/runbooktest/webhooks/Alert1510184037084",
                }
            ],
            "azureAppPushReceivers": [{"emailAddress": "johndoe@email.com", "name": "Sample azureAppPush"}],
            "azureFunctionReceivers": [
                {
                    "functionAppResourceId": "/subscriptions/5def922a-3ed4-49c1-b9fd-05ec533819a3/resourceGroups/aznsTest/providers/Microsoft.Web/sites/testFunctionApp",
                    "functionName": "HttpTriggerCSharp1",
                    "httpTriggerUrl": "http://test.me",
                    "name": "Sample azureFunction",
                    "useCommonAlertSchema": True,
                }
            ],
            "emailReceivers": [
                {"emailAddress": "johndoe@email.com", "name": "John Doe's email", "useCommonAlertSchema": False},
                {"emailAddress": "janesmith@email.com", "name": "Jane Smith's email", "useCommonAlertSchema": True},
            ],
            "eventHubReceivers": [
                {
                    "eventHubName": "testEventHub",
                    "eventHubNameSpace": "testEventHubNameSpace",
                    "name": "Sample eventHub",
                    "subscriptionId": "187f412d-1758-44d9-b052-169e2564721d",
                    "tenantId": "68a4459a-ccb8-493c-b9da-dd30457d1b84",
                }
            ],
            "itsmReceivers": [
                {
                    "connectionId": "a3b9076c-ce8e-434e-85b4-aff10cb3c8f1",
                    "name": "Sample itsm",
                    "region": "westcentralus",
                    "ticketConfiguration": '{"PayloadRevision":0,"WorkItemType":"Incident","UseTemplate":false,"WorkItemData":"{}","CreateOneWIPerCI":false}',
                    "workspaceId": "5def922a-3ed4-49c1-b9fd-05ec533819a3|55dfd1f8-7e59-4f89-bf56-4c82f5ace23c",
                }
            ],
            "logicAppReceivers": [
                {
                    "callbackUrl": "https://prod-27.northcentralus.logic.azure.com/workflows/68e572e818e5457ba898763b7db90877/triggers/manual/paths/invoke/azns/test?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=Abpsb72UYJxPPvmDo937uzofupO5r_vIeWEx7KVHo7w",
                    "name": "Sample logicApp",
                    "resourceId": "/subscriptions/187f412d-1758-44d9-b052-169e2564721d/resourceGroups/LogicApp/providers/Microsoft.Logic/workflows/testLogicApp",
                    "useCommonAlertSchema": False,
                }
            ],
            "smsReceivers": [
                {"countryCode": "1", "name": "John Doe's mobile", "phoneNumber": "1234567890"},
                {"countryCode": "1", "name": "Jane Smith's mobile", "phoneNumber": "0987654321"},
            ],
            "voiceReceivers": [{"countryCode": "1", "name": "Sample voice", "phoneNumber": "1234567890"}],
            "webhookReceivers": [
                {
                    "name": "Sample webhook 1",
                    "serviceUri": "http://www.example.com/webhook1",
                    "useCommonAlertSchema": True,
                },
                {
                    "identifierUri": "http://someidentifier/d7811ba3-7996-4a93-99b6-6b2f3f355f8a",
                    "name": "Sample webhook 2",
                    "objectId": "d3bb868c-fe44-452c-aa26-769a6538c808",
                    "serviceUri": "http://www.example.com/webhook2",
                    "tenantId": "68a4459a-ccb8-493c-b9da-dd30457d1b84",
                    "useAadAuth": True,
                    "useCommonAlertSchema": True,
                },
            ],
        },
    ).result()
    print(response)


# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2022-06-01/examples/postTestNotifications.json
if __name__ == "__main__":
    main()