locked
Export and copy service health alert with powershell RRS feed

  • Question

  • Hello,

    I created one health alert over ui at azure.

    Now I want to export this health alert, modify the location and create a new health alert over powershell.

    I hope somebody can help me at this :-D

    I don't find any command to do this.

    Thanks,

    Horst


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Thursday, July 19, 2018 10:46 AM

All replies

  • You may refer the following article to setup Azure Service Health Alerts programmatically using PowerShell. Also, I would suggest you to check the following template here, which allows you to deploy a simple alert which uses an action group to send email notifications for any Service Health records in the Azure Activity Log. See if this helps.

    Disclaimer: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 

    -----------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here.

    • Proposed as answer by YASWANTH MADI Thursday, July 19, 2018 11:22 AM
    Thursday, July 19, 2018 11:22 AM
  • Hello,

    thanks for the link.

    Now I created the json script and also created the alert over powershell.

    The only thing which happens now is, the description field is empty.

    This is my .json file.

    {
      "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion":"1.0.0.0",
      "parameters":{
         "activityLogAlertName":{
            "type":"string",
            "metadata":{
               "description":"Unique name (within the Resource Group) for the Activity log alert."
            }
         },
         "activityLogAlertEnabled":{
            "type":"bool",
            "defaultValue":true,
            "metadata":{
               "description":"Indicates whether or not the alert is enabled."
            }
         }
      },
      "resources":[
         {
            "type":"Microsoft.Insights/activityLogAlerts",
            "apiVersion":"2017-04-01",
            "name":"[parameters('activityLogAlertName')]",
            "location":"Global",
            "kind":null,
            "tags":{
    
            },
            "properties":{
               "enabled":"[parameters('activityLogAlertEnabled')]",
               "description":"",
               "scopes":[
                  "[subscription().id]"
               ],
                "condition": {
                  "allOf": [
                    {
                      "field": "category",
                      "equals": "ServiceHealth",
                      "containsAny": null
                    },
                    {
                      "anyOf": [
                        {
                          "field": "properties.incidentType",
                          "equals": "Maintenance",
                          "containsAny": null
                        }
                      ]
                    },
                    {
                      "field": "properties.impactedServices[*].ServiceName",
                      "equals": null,
                      "containsAny": [
                        "Action Groups",
                        "Activity Logs & Alerts",
                        "Advisor",
                        "Alerts & Metrics",
                        "API Management",
                        "App Service",
                        "App Service (Linux)",
                        "App Service (Linux) \\ Web Apps",
                        "App Service \\ API Apps",
                        "App Service \\ Mobile Apps",
                        "App Service \\ Web Apps",
                        "Application Insights",
                        "Automation",
                        "Automation and Control",
                        "AutoScale",
                        "Azure Active Directory",
                        "Azure Active Directory B2C",
                        "Azure Active Directory Domain Services",
                        "Azure DNS",
                        "Azure IoT Hub",
                        "Azure IoT Suite",
                        "Azure Monitor",
                        "Azure Policy",
                        "Azure Resource Manager",
                        "azure.microsoft.com",
                        "Backup",
                        "Batch",
                        "CDN",
                        "Cloud Services",
                        "Cloud Shell",
                        "Event Grid",
                        "Event Hubs",
                        "ExpressRoute",
                        "ExpressRoute Circuits",
                        "ExpressRoute \\ ExpressRoute Gateways",
                        "Functions",
                        "Insight and Analytics",
                        "IoT Hub \\ IoT Hub Device Provisioning Service",
                        "Key Vault",
                        "Load Balancer",
                        "Log Analytics",
                        "Logic Apps",
                        "Microsoft Azure portal",
                        "Microsoft Azure portal \\ Marketplace",
                        "Multi-Factor Authentication",
                        "Network Infrastructure",
                        "Notification Hubs",
                        "Scheduler",
                        "Security and Compliance",
                        "Security Center",
                        "SQL Database",
                        "Storage",
                        "StorSimple",
                        "Virtual Machine Scale Sets",
                        "Virtual Machines",
                        "Virtual Network",
                        "VPN Gateway"
                      ]
                    },
                    {
                      "field": "properties.impactedServices[*].ImpactedRegions[*].RegionName",
                      "equals": null,
                      "containsAny": [
                        "North Europe",
                        "West Europe"
                      ]
                    }
                  ]
                },
               "actions":{
                  "actionGroups":[
                      {
                          "actionGroupId": "/subscriptions/...../microsoft.insights/actiongroups/alert_azure_admin",
                          "webhookProperties": {}
                      }
                  ]
               }
            }
         }
      ]
    }

    I hope somebody can help me,

    Horst


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Friday, July 20, 2018 6:44 AM
  • The description field in the arm template is argument reference for the alert rule that will be included in the alert email.

    -----------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here.

    • Proposed as answer by YASWANTH MADI Sunday, July 22, 2018 2:37 PM
    Sunday, July 22, 2018 2:37 PM
  • Hallo,

    I know about the description field.

    But when created the rule over powershell the Field is Empty.

    How can i Set this Value from description Field over json File?

    Horst


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Sunday, July 22, 2018 5:21 PM
  • Could you share the script ?
    Monday, July 23, 2018 4:03 PM
  • Hello,

    see the json script at post above.

    The PS Script - command is:

    Login-AzureRmAccount
     
    Select-AzureRmSubscription -SubscriptionName <subscription_name>
     
    New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName <resource_group> -TemplateFile C:\to\servicehealthalert.json
    Horst


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Monday, July 23, 2018 4:41 PM
  • In the description field, you have to specify the properties of the resource name.

    When i tried the above scenario, iam able to get the output.


    -----------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here.

    • Proposed as answer by YASWANTH MADI Tuesday, July 24, 2018 12:46 PM
    Tuesday, July 24, 2018 12:46 PM
  • Hello,

    I get also this output.

    But If you look inside in the defined rule over ui, you will see the the descrption field is empty and the rule is not active.

    You must edit the rule over ui.

    This field is marked with a red star - mandatry field - value


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Tuesday, July 24, 2018 4:51 PM
  • For more clarification, are you getting below error in the  Azure portal with the redmark in the step2 define alerts?


    Could you share the screen shot with error code?

    Wednesday, July 25, 2018 1:23 PM
  • Yes,, exact  the same error. 

    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    Wednesday, July 25, 2018 5:13 PM
  • @wuwu do you have the ability to open a technical support ticket? If not, could you email me at AzCommunity@microsoft.com and provide me with your SubscriptionID and link to this thread? I can enable one for you and that way you can work 1:1 with an engineer over a phonecall and screenshare to get this resolved. 
    Friday, July 27, 2018 2:36 AM