Googleアナリティクス

2019年2月16日土曜日

Notify Logic Apps API Connection Error

Original Post is here.

In Logic Apps and Flow, sometimes API connection may fail. It is mainly due to the expiration of certificate deadline. It is necessary to check regularly or when an error occurs. This time I checked the API connection used in Logic Apps and let me notify of e-mail notification of errors.

First of all, it will be as follows.

First thing to do is to "get connection information list" and "obtain provider information", using ARM connector.

In this way, by acquiring the connection list, what is checked is specified.In Logic Apps, API connection information is specified because it is managed by Microsoft.Web provider.

Although get provider information, you need to specify the version information of the API to be used when acquiring the connection information that is going on later. I am trying to get information on Microsoft.Web provider for that. A condition is specified for Expand, but it seems to be different from Filter.

Therefore, filtering is performed on the provider information that can be acquired. It seems to designate the same item, but since it is slightly different, I will also check the display with CodePeek.

The actual designation is like this. From To Specify the array to be processed. Specify ResourceType s of the provider information you obtained earlier. Please note that "s" is attached. On the filtering condition side, specify ResourceType and its value is connections, limited to it because it represents API connection information.

The execution result is like this. You can see that filtering is working. Obtain the latest API version from the filtered result.

Following function input on the dialog.

first(first(body('配列のフィルター処理'))?['apiVersions'])

Filtered results are also arrays, so use the first function to narrow down to the first result. In the result, an array called apiVersions is set, so we get the first element. As you can see from the result of the previous execution, it seems that the API version information of the provider is set in descending order from the latest one, so it will be acquired by further specifying the first function.

Create a new array variable to set the error check result. This is add information on the error to this variable.

Here is the main processing part. Check all items with ForEach against the list of connection information.

The details of the connection information are acquired by the Read a Resource action of the ARM connector, but the following information is necessary at this time.

  • Subscription
  • Resource Group
  • Resource Provider
  • Short Resource ID
  • API Version
You need to specify these values. Subscriptions and resource providers are fixed as they do not change. The API version sets the value acquired earlier.The problem is the resource group, short resource ID, but these values ​​can be obtained from the connection information acquired as a list.

This is the connection information actually acquired, but you can extract the resource group and short resource ID from the one set to the id value.

{ "id": "/subscriptions/{subscription ID}/resourceGroups/{Resource Groupe}/providers/Microsoft.Web/connections/{Connection Name}", "name": "azureeventgrid", "type": "Microsoft.Web/connections", "location": "westus2" },

id has the form as above. In the URL format, you can see that the target resource group name is set after resourceGroups and the target connection name is set at the end. In order to obtain necessary information from here, divide the value of id into an array with / and use a specific element.When splitting by Split function, the first element is empty, so the resource group name is fifth and the connection name is Last function to get the end.

On the Logic Flow, processing in this way.

Function specified by each is like this. In the name of the resource group, it is described as [4], but this is the way to fifth of the array directly . Array starts at 0, so you need to specify 4 for the 5th.

JSON analysis of the details of the connection information acquired by the ARM connector makes it easy to use in subsequent processing. The schema at this time can be created by executing once and designating the result.

In the detailed information, there is a value called status that indicates whether the connection is valid, and if it is Connected, it indicates a normal state. Conversely, if any other value is set, it means that an error has occurred in the connection. The actual judgment formula is as follows.

If the value is not "Connected", add to the variable created as a connection error. At this time, in order to form it into a form that is easy to see later, we make it JSON value. In the case of an array variable, since the element to be added is Object, some conversion by function is necessary when using it.

Although it is described directly, since it is an array for the error message,

body('接続状況の解析')?['properties']?['statuses'][0]?['error']?['message']

set it on the dialog, we are referring directly to the element.

Perform all checks, and notify you of e-mails only when there is an error. If some value is set in the created variable, it is judged that there was an error. By processing in this way, notifications are sent by e-mail about the connection where the error occurred.

Even in Logic Apps, when you notice, due to updating of connectors or expiration of connection information, you may get an error. If it is detected and notified by this Logic Flow, will it be of help in actual operation as well?

0 件のコメント:

コメントを投稿