{"id":4408,"date":"2017-06-11T14:40:10","date_gmt":"2017-06-11T12:40:10","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=4408"},"modified":"2017-06-13T11:16:23","modified_gmt":"2017-06-13T09:16:23","slug":"keep-your-azure-subscription-tidy-with-azure-automation-and-log-analytics","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=4408","title":{"rendered":"Keep your Azure subscription tidy with Azure Automation and Log Analytics"},"content":{"rendered":"<p>When delivering Azure training or Azure engagements there is always a discussion about how important it is to have a policy and a lifecycle for Azure resources. Not only do we need a process to deploy resources to Azure, we also need a process to remove resources. From a cost perspective this is extra important, as an orphan IP address or disk will cost many, even if they are not in use. We also need policy to make sure everything is configured according to company policy. Much can be solved with <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-resource-manager\/resource-manager-policy\">ARM policies<\/a>, but not everything. For example, you can\u00e2\u20ac\u2122t make sure all resources have locks configured.<\/p>\n<p>To keep the Azure subscription tidy and to get an event\/recommendation when something is not configured correctly we can use an Azure Automation and OMS Log Analytics. In this blog post, I will show an example how this can be done \u00f0\u0178\u02dc\u0160 The data flow is<\/p>\n<ol>\n<li>Azure Automation runbook triggers based on a schedule or manual. The runbook run several checks, for example if there are any orphan disks.<\/li>\n<li>If there is anything that should be investigated an event is created in OMS Log Analytics.<\/li>\n<li>In the OMS portal, we can build a dashboard to get a good overview of these events.<\/li>\n<\/ol>\n<p>The example dashboard shows (down the example dashboard <a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/Contoso-Azure-Check.zip\">here<\/a>)<\/p>\n<ul>\n<li>Total number of recommendations\/events<\/li>\n<li>Number of resource types with recommendations<\/li>\n<linumber of resources with recommendations<\/li>\n<li>Number of resources groups with recommendations. If each resource group correspond to a service, it is easy to see number of services that are not configured according to policy<\/li>\n<\/linumber><\/ul>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4411\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001-300x116.png\" alt=\"\" width=\"484\" height=\"187\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001-300x116.png 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001-768x296.png 768w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001-1024x394.png 1024w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-001.png 1831w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/a><\/p>\n<p>The runbook is this example checks if there are any disks without an owner, any VMs without automatically shut down, any public IP addresses not in use and databases without lock configured. The runbook is based on PowerShell and it is easy to add more checks. The runbook submit data to OMS Log Analytics with Tao Yang PS module for OMSDataInjection, download <a href=\"https:\/\/www.powershellgallery.com\/packages\/OMSDataInjection\/1.2.0\">here<\/a>. That show up in Log Analytics as a custom log called ContosoAzureCompliance_CL. The name of the log can be changed in the runbook.<\/p>\n<p>The figure below shows the log search interface in the OMS portal. On the left side, you can see that we can filter based on resource, resource type, severity and resource group. This makes it easy to drill into a specific type of resource or resource group.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-002.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-4414\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-002-190x300.png\" alt=\"\" width=\"190\" height=\"300\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-002-190x300.png 190w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-002-648x1024.png 648w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2017\/06\/20170611-Azure-Tidy-002.png 733w\" sizes=\"(max-width: 190px) 100vw, 190px\" \/><\/a><\/p>\n<p><span lang=\"EN-US\" style=\"background: white; margin: 0px; color: #404040; line-height: 107%; font-family: 'Titillium Web',serif; font-size: 13.5pt;\">Disclaimer: Cloud is very fast-moving target. It means that by the time you\u00e2\u20ac\u2122re reading this post everything described here could have been changed completely.<\/span><span lang=\"EN-US\" style=\"margin: 0px; color: #404040; line-height: 107%; font-family: 'Titillium Web',serif; font-size: 13.5pt;\"><br \/>\nNote that this is provided \u00e2\u20ac\u0153AS-IS\u00e2\u20ac\u009d with no warranties at all. This is not a production ready\u00c2\u00a0solution for your production environment, just an idea and an example.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When delivering Azure training or Azure engagements there is always a discussion about how important it is to have a policy and a lifecycle for Azure resources. Not only do we need a process to deploy resources to Azure, we also need a process to remove resources. From a cost perspective this is extra important, &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=4408\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4411,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[64,68,70],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4408"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4408"}],"version-history":[{"count":8,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4408\/revisions"}],"predecessor-version":[{"id":4419,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4408\/revisions\/4419"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/media\/4411"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4408"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}