Created
July 5, 2018 16:09
-
-
Save dabedin/1cde55d1885d1a468e7c371f3fb09c12 to your computer and use it in GitHub Desktop.
Template of a logic app invoking an Automation script collecting info of VMs, processing and formattin output and sending it via Office 365
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"logicAppName": { | |
"type": "string", | |
"defaultValue": "dbreportVMlist", | |
"metadata": { | |
"description": "Name of the Logic App." | |
} | |
}, | |
"logicAppLocation": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"allowedValues": [ | |
"[resourceGroup().location]", | |
"eastasia", | |
"southeastasia", | |
"centralus", | |
"eastus", | |
"eastus2", | |
"westus", | |
"northcentralus", | |
"southcentralus", | |
"northeurope", | |
"westeurope", | |
"japanwest", | |
"japaneast", | |
"brazilsouth", | |
"australiaeast", | |
"australiasoutheast", | |
"westcentralus", | |
"westus2" | |
], | |
"metadata": { | |
"description": "Location of the Logic App." | |
} | |
}, | |
"Call_Function_CountVMsBySubscription-ResourceGroup": { | |
"type": "string" | |
}, | |
"Call_Function_CountVMsBySubscription-FunctionApp": { | |
"type": "string", | |
"defaultValue": "dbautomationfunc" | |
}, | |
"Call_Function_CountVMsBySubscription-FunctionName": { | |
"type": "string", | |
"defaultValue": "Compose_SubscriptionVMCount" | |
}, | |
"RecurrenceFrequency": { | |
"type": "string", | |
"defaultValue": "Day" | |
}, | |
"RecurrenceInterval": { | |
"type": "int", | |
"defaultValue": 1 | |
}, | |
"RecurrenceTimeZone": { | |
"type": "string", | |
"defaultValue": "W. Europe Standard Time" | |
}, | |
"RecurrenceSchedule": { | |
"type": "Object", | |
"defaultValue": { | |
"hours": [ | |
6 | |
] | |
} | |
}, | |
"azureautomation_name": { | |
"type": "string", | |
"defaultValue": "azureautomation" | |
}, | |
"azureautomation_displayName": { | |
"type": "string" | |
}, | |
"azureautomation_token:clientId": { | |
"type": "string", | |
"defaultValue": null, | |
"metadata": { | |
"description": "Client (or Application) ID of the Azure Active Directory application." | |
} | |
}, | |
"azureautomation_token:clientSecret": { | |
"type": "securestring", | |
"defaultValue": null, | |
"metadata": { | |
"description": "Client secret of the Azure Active Directory application." | |
} | |
}, | |
"azureautomation_token:TenantId": { | |
"type": "string", | |
"metadata": { | |
"description": "The tenant of ID for the Azure Active Directory application." | |
} | |
}, | |
"azureautomation_token:resourceUri": { | |
"type": "string", | |
"defaultValue": null, | |
"metadata": { | |
"description": "The resource you are requesting authorization to use." | |
} | |
}, | |
"azureautomation_token:grantType": { | |
"type": "string", | |
"defaultValue": "code", | |
"allowedValues": [ | |
"code", | |
"client_credentials" | |
], | |
"metadata": { | |
"description": "Grant type" | |
} | |
}, | |
"office365_name": { | |
"type": "string", | |
"defaultValue": "office365" | |
}, | |
"office365_displayName": { | |
"type": "string" | |
} | |
}, | |
"variables": {}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Logic/workflows", | |
"apiVersion": "2016-06-01", | |
"name": "[parameters('logicAppName')]", | |
"location": "[parameters('logicAppLocation')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Web/connections', parameters('azureautomation_name'))]", | |
"[resourceId('Microsoft.Web/connections', parameters('office365_name'))]" | |
], | |
"properties": { | |
"definition": { | |
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"$connections": { | |
"defaultValue": {}, | |
"type": "Object" | |
} | |
}, | |
"triggers": { | |
"Recurrence": { | |
"recurrence": { | |
"frequency": "[parameters('RecurrenceFrequency')]", | |
"interval": "[parameters('RecurrenceInterval')]", | |
"schedule": "[parameters('RecurrenceSchedule')]", | |
"timeZone": "[parameters('RecurrenceTimeZone')]" | |
}, | |
"type": "Recurrence" | |
} | |
}, | |
"actions": { | |
"Call_Function_CountVMsBySubscription": { | |
"runAfter": { | |
"Create_CSV_ListOfVMs": [ | |
"Succeeded" | |
] | |
}, | |
"type": "Function", | |
"inputs": { | |
"body": "@body('Parse_JSON_ListOfVMs')", | |
"function": { | |
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',parameters('Call_Function_CountVMsBySubscription-ResourceGroup'),'/providers/Microsoft.Web/sites/',parameters('Call_Function_CountVMsBySubscription-FunctionApp'),'/functions/',parameters('Call_Function_CountVMsBySubscription-FunctionName'))]" | |
} | |
} | |
}, | |
"Create_CSV_ListOfVMs": { | |
"runAfter": { | |
"Parse_JSON_ListOfVMs": [ | |
"Succeeded" | |
] | |
}, | |
"type": "Table", | |
"inputs": { | |
"columns": [ | |
{ | |
"header": "Subscription", | |
"value": "@item()['Subscription']" | |
}, | |
{ | |
"header": "Name", | |
"value": "@item()['Name']" | |
}, | |
{ | |
"header": "Size", | |
"value": "@item()['Size']" | |
}, | |
{ | |
"header": "vCPU", | |
"value": "@item()['vCPU']" | |
}, | |
{ | |
"header": "RAM", | |
"value": "@item()['RAM']" | |
}, | |
{ | |
"header": "OSType", | |
"value": "@item()['OSType']" | |
}, | |
{ | |
"header": "Status", | |
"value": "@item()['Status']" | |
}, | |
{ | |
"header": "Location", | |
"value": "@item()['Location']" | |
}, | |
{ | |
"header": "VNet", | |
"value": "@item()['VNet']" | |
}, | |
{ | |
"header": "Subnet", | |
"value": "@item()['Subnet']" | |
}, | |
{ | |
"header": "ResourceGroup", | |
"value": "@item()['ResourceGroup']" | |
}, | |
{ | |
"header": "ResourceId", | |
"value": "@item()['ResourceId']" | |
}, | |
{ | |
"header": "Tags", | |
"value": "@item()['Tags']" | |
} | |
], | |
"format": "CSV", | |
"from": "@body('Parse_JSON_ListOfVMs')" | |
} | |
}, | |
"Create_HTML_CountVMsBySubscription": { | |
"runAfter": { | |
"Call_Function_CountVMsBySubscription": [ | |
"Succeeded" | |
] | |
}, | |
"type": "Table", | |
"inputs": { | |
"format": "HTML", | |
"from": "@body('Call_Function_CountVMsBySubscription')" | |
} | |
}, | |
"Create_job": { | |
"runAfter": {}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"connection": { | |
"name": "@parameters('$connections')['azureautomation']['connectionId']" | |
} | |
}, | |
"method": "put", | |
"path": "/subscriptions/@{encodeURIComponent('5f1d2528-75ba-4252-8ad1-bc89b7e89388')}/resourceGroups/@{encodeURIComponent('DB-AUT-NPA-RGP023')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('dbautnpaaut001')}/jobs", | |
"queries": { | |
"runbookName": "GetVMList", | |
"wait": true, | |
"x-ms-api-version": "2015-10-31" | |
} | |
} | |
}, | |
"Get_job_output": { | |
"runAfter": { | |
"Create_job": [ | |
"Succeeded" | |
] | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"connection": { | |
"name": "@parameters('$connections')['azureautomation']['connectionId']" | |
} | |
}, | |
"method": "get", | |
"path": "/subscriptions/@{encodeURIComponent('5f1d2528-75ba-4252-8ad1-bc89b7e89388')}/resourceGroups/@{encodeURIComponent('DB-AUT-NPA-RGP023')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('dbautnpaaut001')}/jobs/@{encodeURIComponent(body('Create_job')?['properties']['jobId'])}/output", | |
"queries": { | |
"x-ms-api-version": "2015-10-31" | |
} | |
} | |
}, | |
"Parse_JSON_ListOfVMs": { | |
"runAfter": { | |
"Get_job_output": [ | |
"Succeeded" | |
] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Get_job_output')", | |
"schema": { | |
"items": { | |
"properties": { | |
"Location": { | |
"type": "string" | |
}, | |
"Name": { | |
"type": "string" | |
}, | |
"OSType": { | |
"type": "string" | |
}, | |
"RAM": { | |
"type": "string" | |
}, | |
"ResourceGroup": { | |
"type": "string" | |
}, | |
"ResourceId": { | |
"type": "string" | |
}, | |
"Size": { | |
"type": "string" | |
}, | |
"Status": { | |
"type": "string" | |
}, | |
"Subnet": { | |
"type": "string" | |
}, | |
"Subscription": { | |
"type": "string" | |
}, | |
"Tags": { | |
"type": "string" | |
}, | |
"VNet": { | |
"type": "string" | |
}, | |
"vCPU": { | |
"type": "string" | |
} | |
}, | |
"required": [ | |
"Subscription", | |
"Name", | |
"Size", | |
"vCPU", | |
"RAM", | |
"OSType", | |
"Status", | |
"Location", | |
"VNet", | |
"Subnet", | |
"ResourceGroup", | |
"ResourceId", | |
"Tags" | |
], | |
"type": "object" | |
}, | |
"type": "array" | |
} | |
} | |
}, | |
"Send_an_email": { | |
"runAfter": { | |
"Create_HTML_CountVMsBySubscription": [ | |
"Succeeded" | |
] | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"body": { | |
"Attachments": [ | |
{ | |
"ContentBytes": "@{base64(body('Create_CSV_ListOfVMs'))}", | |
"Name": "@{concat('ListVM-',formatDateTime(utcNow(),'ddMMyyyy'),'.csv')}" | |
} | |
], | |
"Body": "at @{body('Create_job')?['properties']['endTime']}\n@{body('Create_HTML_CountVMsBySubscription')}", | |
"Importance": "Normal", | |
"IsHtml": true, | |
"Subject": "List of Azure VM, extracted on @{formatDateTime(utcNow(),'dd/MM/yyyy')}", | |
"To": "[email protected]" | |
}, | |
"host": { | |
"connection": { | |
"name": "@parameters('$connections')['office365']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"path": "/Mail" | |
} | |
} | |
}, | |
"outputs": {} | |
}, | |
"parameters": { | |
"$connections": { | |
"value": { | |
"azureautomation": { | |
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/azureautomation')]", | |
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('azureautomation_name'))]", | |
"connectionName": "[parameters('azureautomation_name')]" | |
}, | |
"office365": { | |
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/office365')]", | |
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('office365_name'))]", | |
"connectionName": "[parameters('office365_name')]" | |
} | |
} | |
} | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Web/connections", | |
"apiVersion": "2016-06-01", | |
"location": "[parameters('logicAppLocation')]", | |
"name": "[parameters('office365_name')]", | |
"properties": { | |
"api": { | |
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/office365')]" | |
}, | |
"displayName": "[parameters('office365_displayName')]", | |
"parameterValues": {} | |
} | |
}, | |
{ | |
"type": "Microsoft.Web/connections", | |
"apiVersion": "2016-06-01", | |
"location": "[parameters('logicAppLocation')]", | |
"name": "[parameters('azureautomation_name')]", | |
"properties": { | |
"api": { | |
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/providers/Microsoft.Web/locations/',parameters('logicAppLocation'),'/managedApis/azureautomation')]" | |
}, | |
"displayName": "[parameters('azureautomation_displayName')]", | |
"parameterValues": { | |
"token:clientId": "[parameters('azureautomation_token:clientId')]", | |
"token:clientSecret": "[parameters('azureautomation_token:clientSecret')]", | |
"token:TenantId": "[parameters('azureautomation_token:TenantId')]", | |
"token:resourceUri": "[parameters('azureautomation_token:resourceUri')]", | |
"token:grantType": "[parameters('azureautomation_token:grantType')]" | |
} | |
} | |
} | |
], | |
"outputs": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what should be the actual value given to
azureautomation_token:resourceUri
.I understand that
clientId
andclientSecret
are from the service principal which is used to create this api connector for logic app.But i am confused about
resourceUri