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

Post on 04-Sep-2020

2 views 1 download

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

Azure AutomationAdvanced Runbook Design

@JakobGSvendsen – CT Global

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

Jakob Gottlieb Svendsen

Principal Consultant &

Chief Developer

• 10 years in Automation Consultancy

• 15+ years in ITCo-Founder

PowerShell User Group

Cloud & Datacenter MVP

@JakobGSvendsen

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

Demo

Runbook Structure

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

Demo

Logging

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

Watcher – SCOM Alerts

New/Update Incident

Demo

Watcher

SCOM Alerts

• #Watcher

• #Trigger Action(s)

• [hashtable]$prop = @{}

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

• Invoke-AutomationWatcherAction -Message "New Alert"`

• -CustomProperties $prop

• #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,

• ...

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

Event Based AutomationAdvanced Scenario

New Email to Service Now Incident

(Event Based)

New Email Service Now Incident

End Users

Email Sent

OMS Automation

Webhook

New/Update Incident

Microsoft Graph API

Graph – Webhook Subscriptions

• Actions• Created, Updated, Deleted

• Outlook• Mail

• Events• Contacts

• Outlook groups• Conversations

• Drives• SharePoint

• OneDrive

Graph API – Webhook Validation

POST using Validation Token

Return Validation Token

New Email Service Now Incident

End Users

Email Sent

OMS Automation

Webhook

New/Update Incident

AzureFunction

Demo

Graph API + Functions

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/

Update Subscriptions

• Maximum expire date = 3 days from creation!

• What to do?

• Scheduled Runbook!!

Update Subscriptions

Where to save the settings?

Custom DB?

SharePoint?

Calling all SharePoint Fans!

All SharePoint Fans!

Go To the Pool!

Runbook Development

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/

Runbook Management

Export Tool

• Preview!

• Export Runbooks

• Auto Export referenced runbook

• Auto export used assets

• Join the project:

https://github.com/JakobGSvendsen/AzureAutomationImportExport

Source Control (git)

• Source Control is “master”

• Use branches

• Use Visual Studio Code

• Trigger automatic import to Automation Account(s)

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

Demo

Source Control Sync

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! ! !

Q / A

@JakobGSvendsen

jgs@ctglobalservices.com

ØVRIGE SPONSORER

SPECIAL SPONSORER