Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer...

35
Azure Automation Advanced Runbook Design @JakobGSvendsen – CT Global

Transcript of Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer...

Page 1: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Azure AutomationAdvanced Runbook Design

@JakobGSvendsen – CT Global

Page 2: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Agenda

• Runbook Structure

• Logging

• Runbook Watchers

• Scenario: Service Now – SCOM Alerts

• Adv Scenario: New Email to Service Now Incident (Event Based)

• Runbook Development and Management

Page 3: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Jakob Gottlieb Svendsen

Principal Consultant &

Chief Developer

• 10 years in Automation Consultancy

• 15+ years in ITCo-Founder

PowerShell User Group

Cloud & Datacenter MVP

@JakobGSvendsen

Page 4: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Runbook Structure

• Comment Based Help

• Parameters

• Mandatory / Optional

• Input Type

• Preferences

• ErrorActionPreference = Stop

• VerbosePreference?

• Catch All Errors

• Might need more than one (inside foreach)

• Control Return / Output

Page 5: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Demo

Runbook Structure

Page 6: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Logging

• Log before actions! (Write-Verbose)

• Optional: Log after actions!

• Use TraceLog

• Collect Log entries in $TraceLog

• Write-Verbose $Tracelog in the end

• Send $TraceLog with runbook output

Page 7: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Demo

Logging

Page 8: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Runbook Watchers (Monitor)

• In private preview

• Execute every minute or more.

• Watcher Runbook

• Checks then Invokes Action

• Free to run, only runs on Hybrid Worker

• Action Runbook

• Perform integrations

• Not Free

• Runs in Azure or Hybrid Worker

Page 9: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Watcher – SCOM Alerts

New/Update Incident

Page 10: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Demo

Watcher

SCOM Alerts

Page 11: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

• #Watcher

• #Trigger Action(s)

• [hashtable]$prop = @{}

• $prop.alerts = "$($alerts | ConvertTo-JSON -Depth1)"

• Invoke-AutomationWatcherAction -Message "New Alert"`

• -CustomProperties $prop

Page 12: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

• #Action

• #Property Bag

• $EVENTDATA.EventProperties.PropertyBag

• #Action Input

• class PSCustomObject

• {

• Type = WatcherEvent

• InvocationId = c1a3a509-c5da-4f51-9dd7-ce81a25d2e33

• EventProperties =

• class PSCustomObject

• {

• TimeStamp = 2017-05-01T13:06:24.7941901Z

• PropertyBag =

• class PSCustomObject

• {

• alerts = {

• "ManagementGroup": "OMCloudMG",

• ...

• "ResolutionState": 1,

• ...

• "Severity": 2,

• ...

Page 13: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Watcher pitfalls

• Set “check date” right after check

• Multiple watcher instances might execute in parallel

• Only Errors and invoke-actions are logged to watcher log

Page 14: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Event Based AutomationAdvanced Scenario

New Email to Service Now Incident

(Event Based)

Page 15: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

New Email Service Now Incident

End Users

Email Sent

OMS Automation

Webhook

New/Update Incident

Page 16: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Microsoft Graph API

Page 17: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Graph – Webhook Subscriptions

• Actions• Created, Updated, Deleted

• Outlook• Mail

• Events• Contacts

• Outlook groups• Conversations

• Drives• SharePoint

• OneDrive

Page 18: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Graph API – Webhook Validation

POST using Validation Token

Return Validation Token

Page 19: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

New Email Service Now Incident

End Users

Email Sent

OMS Automation

Webhook

New/Update Incident

AzureFunction

Page 20: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Demo

Graph API + Functions

Page 21: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Microsoft Graph API - How ?

Get SDKs at

http://graph.microsoft.io/en-us/code-samples-and-sdks

PowerShell Module (Community - Beta)

Get it at

https://www.powershellgallery.com/packages/MicrosoftGraphAPI/

Page 22: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Update Subscriptions

• Maximum expire date = 3 days from creation!

• What to do?

• Scheduled Runbook!!

Page 23: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Update Subscriptions

Where to save the settings?

Custom DB?

SharePoint?

Page 24: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Calling all SharePoint Fans!

Page 25: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

All SharePoint Fans!

Go To the Pool!

Page 26: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Runbook Development

Page 27: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Editors

• PowerShell ISE

• Built-in• Azure Automation Add-in for direct development

• Visual Studio Code

• Still has bugs!• Open Source• Great shortcuts such as F12 to go to function

• Auto formatting and more!• NEW! Community AA Extension by Morten Christiansen @

automateyouself.wordspress.comhttps://automateyourself.wordpress.com/2017/08/31/vs-code-azure-automation-extension/

Page 28: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Runbook Management

Page 29: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Export Tool

• Preview!

• Export Runbooks

• Auto Export referenced runbook

• Auto export used assets

• Join the project:

https://github.com/JakobGSvendsen/AzureAutomationImportExport

Page 30: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Source Control (git)

• Source Control is “master”

• Use branches

• Use Visual Studio Code

• Trigger automatic import to Automation Account(s)

Page 31: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Source Control - Sync

• VSTS – Git• Use script provided by MSFT

https://github.com/azureautomation/runbooks/blob/master/Utility/ARM/Sync-VSTS.ps1

• Or Pull Request/Enhanced CT Global Version at

http://blog.ctglobalservices.com/powershell/jgs/azure-automation-runbook-template-1-0/• Setup Service Hook or build/release process

https://docs.microsoft.com/en-us/azure/automation/automation-scenario-source-control-integration-with-vsts

Page 32: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Demo

Source Control Sync

Page 33: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Summary

• Use base template & module!

• Log Log Log

• Watcher runbooks for monitoring!

• Event based monitoring is even better!

• Export tool for exporting packages of runbooks / complete solutions

• Source control! ! !

Page 34: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

Q / A

@JakobGSvendsen

[email protected]

Page 35: Azure Automation · 2017. 9. 22. · Jakob Gottlieb Svendsen Principal Consultant & Chief Developer •10 years in Automation Consultancy •15+ years in IT Co-Founder PowerShell

ØVRIGE SPONSORER

SPECIAL SPONSORER