From 51bc04de4255236929056306611000088dafbce5 Mon Sep 17 00:00:00 2001 From: Parth Shah Date: Tue, 20 Apr 2021 12:31:48 -0700 Subject: [PATCH 1/4] created a new branch called parth/templates and added a template using the UI which executes a query and sends results on recurrence --- templates/execute-query-send-result.json | 305 +++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 templates/execute-query-send-result.json diff --git a/templates/execute-query-send-result.json b/templates/execute-query-send-result.json new file mode 100644 index 0000000..e367e53 --- /dev/null +++ b/templates/execute-query-send-result.json @@ -0,0 +1,305 @@ +{ + "id": "execute-query-send-result", + "title": "execute-query-send-result", + "description": "Executes and sends you the query results on recurrence", + "iconType": "ScheduledTask", + "data": { + "definition": { + "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", + "actions": { + "ExecuteQuery": { + "inputs": { + "body": { + "query": "@parameters('queryString')" + }, + "host": { + "connection": { + "name": "@parameters('$connections')['sql']['connectionId']" + } + }, + "method": "post", + "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('sql-server-tasks.database.windows.net'))},@{encodeURIComponent(encodeURIComponent('sql-sample-tasks'))}/query/sql" + }, + "runAfter": {}, + "type": "ApiConnection" + }, + "Send_an_email_(V2)": { + "inputs": { + "body": { + "Body": "

@{body('ExecuteQuery')?['resultsets']}
\n
\n
\n
\n
\n
\n

", + "Subject": "Query results from ", + "To": "shahparth@microsoft.com" + }, + "host": { + "connection": { + "name": "@parameters('$connections')['office365']['connectionId']" + } + }, + "method": "post", + "path": "/v2/Mail" + }, + "runAfter": { + "ExecuteQuery": [ + "Succeeded" + ] + }, + "type": "ApiConnection" + } + }, + "contentVersion": "1.0.0.0", + "outputs": {}, + "parameters": { + "$connections": { + "defaultValue": {}, + "type": "Object" + }, + "Database name": { + "type": "String", + "metadata": { + "isLinkedResource": true, + "sourceParameter": "name" + } + }, + "EmailID": { + "type": "String", + "defaultValue": "email@example.com", + "metadata": { + "displayName": "Email To", + "required": false, + "description": "Query results will be sent to" + } + }, + "Frequency": { + "type": "String", + "allowedValues": [ + "Month", + "Week", + "Day", + "Hour", + "Minute", + "Seconds" + ], + "metadata": { + "displayName": "Frequency", + "required": true, + "description": "How often should schedule run. i.e. Weekly" + } + }, + "Interval": { + "type": "Int", + "metadata": { + "displayName": "Interval", + "format": "number", + "required": true, + "description": "Time interval for recurrence" + } + }, + "ResourceGroup": { + "type": "String", + "metadata": { + "isLinkedResource": true, + "sourceParameter": "resourceGroup" + } + }, + "Start Time": { + "type": "String", + "defaultValue": "start ", + "metadata": { + "displayName": "Time", + "format": "timeFormat", + "required": false, + "description": "Starts executing query on this time" + } + }, + "SubscriptionID": { + "type": "String", + "metadata": { + "isLinkedResource": true, + "sourceParameter": "subscriptionId" + } + }, + "Timezone": { + "type": "String", + "allowedValues": [ + "Dateline Standard Time", + "UTC-11", + "Aleutian Standard Time", + "Hawaiian Standard Time", + "Marquesas Standard Time", + "Alaskan Standard Time", + "UTC-09", + "Pacific Standard Time (Mexico)", + "UTC-08", + "Pacific Standard Time", + "US Mountain Standard Time", + "Mountain Standard Time (Mexico)", + "Mountain Standard Time", + "Central America Standard Time", + "Central Standard Time", + "Easter Island Standard Time", + "Central Standard Time (Mexico)", + "Canada Central Standard Time", + "SA Pacific Standard Time", + "Eastern Standard Time (Mexico)", + "Eastern Standard Time", + "Haiti Standard Time", + "Cuba Standard Time", + "US Eastern Standard Time", + "Paraguay Standard Time", + "Atlantic Standard Time", + "Venezuela Standard Time", + "Central Brazilian Standard Time", + "SA Western Standard Time", + "Pacific SA Standard Time", + "Turks And Caicos Standard Time", + "Newfoundland Standard Time", + "Tocantins Standard Time", + "E. South America Standard Time", + "SA Eastern Standard Time", + "Argentina Standard Time", + "Greenland Standard Time", + "Montevideo Standard Time", + "Saint Pierre Standard Time", + "Bahia Standard Time", + "UTC-02", + "Mid-Atlantic Standard Time", + "Azores Standard Time", + "Cape Verde Standard Time", + "UTC", + "Morocco Standard Time", + "GMT Standard Time", + "Greenwich Standard Time", + "W. Europe Standard Time", + "Central Europe Standard Time", + "Romance Standard Time", + "Central European Standard Time", + "W. Central Africa Standard Time", + "Namibia Standard Time", + "Jordan Standard Time", + "GTB Standard Time", + "Middle East Standard Time", + "Egypt Standard Time", + "E. Europe Standard Time", + "Syria Standard Time", + "West Bank Standard Time", + "South Africa Standard Time", + "FLE Standard Time", + "Turkey Standard Time", + "Israel Standard Time", + "Kaliningrad Standard Time", + "Libya Standard Time", + "Arabic Standard Time", + "Arab Standard Time", + "Belarus Standard Time", + "Russian Standard Time", + "E. Africa Standard Time", + "Iran Standard Time", + "Arabian Standard Time", + "Astrakhan Standard Time", + "Azerbaijan Standard Time", + "Russia Time Zone 3", + "Mauritius Standard Time", + "Georgian Standard Time", + "Caucasus Standard Time", + "Afghanistan Standard Time", + "West Asia Standard Time", + "Ekaterinburg Standard Time", + "Pakistan Standard Time", + "India Standard Time", + "Sri Lanka Standard Time", + "Nepal Standard Time", + "Central Asia Standard Time", + "Bangladesh Standard Time", + "N. Central Asia Standard Time", + "Myanmar Standard Time", + "SE Asia Standard Time", + "Altai Standard Time", + "W. Mongolia Standard Time", + "North Asia Standard Time", + "Tomsk Standard Time", + "China Standard Time", + "North Asia East Standard Time", + "Singapore Standard Time", + "W. Australia Standard Time", + "Taipei Standard Time", + "Ulaanbaatar Standard Time", + "North Korea Standard Time", + "Aus Central W. Standard Time", + "Transbaikal Standard Time", + "Tokyo Standard Time", + "Korea Standard Time", + "Yakutsk Standard Time", + "Cen. Australia Standard Time", + "AUS Central Standard Time", + "E. Australia Standard Time", + "AUS Eastern Standard Time", + "West Pacific Standard Time", + "Tasmania Standard Time", + "Vladivostok Standard Time", + "Lord Howe Standard Time", + "Bougainville Standard Time", + "Russia Time Zone 10", + "Magadan Standard Time", + "Norfolk Standard Time", + "Sakhalin Standard Time", + "Central Pacific Standard Time", + "Russia Time Zone 11", + "New Zealand Standard Time", + "UTC+12", + "Fiji Standard Time", + "Kamchatka Standard Time", + "Chatham Islands Standard Time", + "Tonga Standard Time", + "Samoa Standard Time", + "Line Islands Standard Time" + ], + "metadata": { + "displayName": "Timezone", + "required": true, + "description": "Select time zone for task schedule" + } + }, + "queryString": { + "type": "String", + "defaultValue": "query", + "metadata": { + "displayName": "Query Text", + "required": false, + "description": "Enter your SQL query" + } + } + }, + "triggers": { + "Recurrence": { + "recurrence": { + "frequency": "Minute", + "interval": 3 + }, + "type": "Recurrence" + } + } + }, + "parameters": { + "$connections": { + "value": { + "office365": { + "connectionId": "", + "connectionName": "", + "id": "/subscriptions/80d4fe69-c95b-4dd2-a938-9250f1c8ab03/providers/Microsoft.Web/locations/westus/managedApis/office365" + }, + "sql": { + "connectionId": "", + "connectionName": "", + "id": "/subscriptions/80d4fe69-c95b-4dd2-a938-9250f1c8ab03/providers/Microsoft.Web/locations/westus/managedApis/sql" + } + } + } + } + }, + "supportedResources": [ + "Microsoft.Sql/servers/databases" + ], + "excludeResources": [ + "Microsoft.Resources/resourceGroups" + ] +} \ No newline at end of file From bbd685886507c77f8d0e9a51a6c0573555d6731b Mon Sep 17 00:00:00 2001 From: shahparth-lab <80121421+shahparth-lab@users.noreply.github.com> Date: Thu, 6 May 2021 15:46:05 -0700 Subject: [PATCH 2/4] Update execute-query-send-result.json --- templates/execute-query-send-result.json | 51 +++++++++++++----------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/templates/execute-query-send-result.json b/templates/execute-query-send-result.json index e367e53..41323e4 100644 --- a/templates/execute-query-send-result.json +++ b/templates/execute-query-send-result.json @@ -1,7 +1,7 @@ { - "id": "execute-query-send-result", - "title": "execute-query-send-result", - "description": "Executes and sends you the query results on recurrence", + "id": "Send_query_result_via_e-mail", + "title": "Send query result via e-mail", + "description": "Execute a query and send email on schedule", "iconType": "ScheduledTask", "data": { "definition": { @@ -18,7 +18,7 @@ } }, "method": "post", - "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('sql-server-tasks.database.windows.net'))},@{encodeURIComponent(encodeURIComponent('sql-sample-tasks'))}/query/sql" + "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent(parameters('ServerID')))},@{encodeURIComponent(encodeURIComponent(parameters('DatabaseID')))}/query/sql" }, "runAfter": {}, "type": "ApiConnection" @@ -27,8 +27,8 @@ "inputs": { "body": { "Body": "

@{body('ExecuteQuery')?['resultsets']}
\n
\n
\n
\n
\n
\n

", - "Subject": "Query results from ", - "To": "shahparth@microsoft.com" + "Subject": "Query results from @{parameters('DatabaseID')}", + "To": "@parameters('Email To')" }, "host": { "connection": { @@ -53,20 +53,20 @@ "defaultValue": {}, "type": "Object" }, - "Database name": { + "DatabaseID": { "type": "String", "metadata": { "isLinkedResource": true, - "sourceParameter": "name" + "sourceParameter": "id" } }, - "EmailID": { + "Email To": { "type": "String", "defaultValue": "email@example.com", "metadata": { "displayName": "Email To", "required": false, - "description": "Query results will be sent to" + "description": "Send the query results to this email" } }, "Frequency": { @@ -101,14 +101,20 @@ "sourceParameter": "resourceGroup" } }, - "Start Time": { + "ScheduleTime": { "type": "String", - "defaultValue": "start ", + "defaultValue": "start time", "metadata": { "displayName": "Time", "format": "timeFormat", "required": false, - "description": "Starts executing query on this time" + "description": "Runs the query at this time" + } + }, + "ServerID": { + "type": "String", + "metadata": { + "isLinkedResource": true } }, "SubscriptionID": { @@ -261,19 +267,21 @@ }, "queryString": { "type": "String", - "defaultValue": "query", + "defaultValue": "SELECT * FROM table", "metadata": { "displayName": "Query Text", "required": false, - "description": "Enter your SQL query" + "description": "Query to be executed" } } }, "triggers": { "Recurrence": { "recurrence": { - "frequency": "Minute", - "interval": 3 + "frequency": "@parameters('Frequency')", + "interval": "@parameters('Interval')", + "startTime": "@formatDateTime(parameters('ScheduleTime'), 'yyyy-MM-ddTHH:mm:ss')", + "timeZone": "@parameters('TimeZone')" }, "type": "Recurrence" } @@ -285,12 +293,12 @@ "office365": { "connectionId": "", "connectionName": "", - "id": "/subscriptions/80d4fe69-c95b-4dd2-a938-9250f1c8ab03/providers/Microsoft.Web/locations/westus/managedApis/office365" + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Web/locations/westus/managedApis/office365" }, "sql": { "connectionId": "", "connectionName": "", - "id": "/subscriptions/80d4fe69-c95b-4dd2-a938-9250f1c8ab03/providers/Microsoft.Web/locations/westus/managedApis/sql" + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Web/locations/westus/managedApis/sql" } } } @@ -298,8 +306,5 @@ }, "supportedResources": [ "Microsoft.Sql/servers/databases" - ], - "excludeResources": [ - "Microsoft.Resources/resourceGroups" ] -} \ No newline at end of file +} From 4afc79da6efb2e8922409cb20878d997837ae50a Mon Sep 17 00:00:00 2001 From: Derek Li Date: Thu, 6 May 2021 16:06:12 -0700 Subject: [PATCH 3/4] Update manifest.json --- templates/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/manifest.json b/templates/manifest.json index f0af446..7368133 100644 --- a/templates/manifest.json +++ b/templates/manifest.json @@ -1,4 +1,5 @@ [ + "execute-query-send-result.json", "send-monthly-cost.json", "notify-when-resource-deleted.json", "start-vm-new.json", From f3138aabfb832740a1cc6c74a4db8281320a7c5e Mon Sep 17 00:00:00 2001 From: shahparth-lab <80121421+shahparth-lab@users.noreply.github.com> Date: Thu, 6 May 2021 16:48:35 -0700 Subject: [PATCH 4/4] Update execute-query-send-result.json --- templates/execute-query-send-result.json | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/templates/execute-query-send-result.json b/templates/execute-query-send-result.json index 41323e4..5a12eab 100644 --- a/templates/execute-query-send-result.json +++ b/templates/execute-query-send-result.json @@ -54,11 +54,7 @@ "type": "Object" }, "DatabaseID": { - "type": "String", - "metadata": { - "isLinkedResource": true, - "sourceParameter": "id" - } + "type": "String" }, "Email To": { "type": "String", @@ -112,10 +108,7 @@ } }, "ServerID": { - "type": "String", - "metadata": { - "isLinkedResource": true - } + "type": "String" }, "SubscriptionID": { "type": "String",