Azure Data Factory - Send email with the activity status and Logs stored in Storage account using LogicApp

 

Introduction

Recently i've been working on one of requirement for copying the data between On-Premises to Azure. I did propose the Azure Data Factory and we have successfully demonstrated the copy between the source and destinations. So i thought of documenting the same and might be useful for others who ever come across this requirement, because i did worked on some additional automations like Custom Output, Validations. 

The tool that i've used for this requirement is,

Azure Data Factory,
Azure LogicApp,
Storage Account and Email account for testing.

First, I have created a storage account with couple of containers,



Then we have a Azure Data factory and created datasets of Azure storage account as Source and Destination.






















Next, pipeline creation from Azure Data Factory, Select the Copy Data Activity then configure Source & Sink be providing the Source and Destination storage account.








































Enable Logging in the Copy Data activity so that the logs would be stored and can be attached in the email. 





















Select the Web Activity and configure the properties like URL, Method, Headers & Body

For URL, Go to Logic Apps and add action "When a HTTP request is received" and copy the link,






























Body JSON:

{
"Subject":"Pipeline was executed successfully and here is the log details @{pipeline().Pipeline}-pipeline",
"DataFactoryName":"@{pipeline().DataFactory}",
"ActivityRunId":"@{activity('copy-storageaccount-files').ActivityRunId}",
"DataSource":"@{activity('copy-storageaccount-files').output.executionDetails[0].source}",
"DataTarget":"@{activity('copy-storageaccount-files').output.executionDetails[0].sink}",
"SourceSize":"@{activity('copy-storageaccount-files').output.dataRead}",
"TargetSize":"@{activity('copy-storageaccount-files').output.dataWritten}",
"TotalSourceFilesRead":"@{activity('copy-storageaccount-files').output.filesRead}",
"TotalTargetFilesWritten":"@{activity('copy-storageaccount-files').output.filesWritten}",
"CopyDuration":"@{activity('copy-storageaccount-files').output.copyDuration}",
"Status":"@{activity('copy-storageaccount-files').output.executionDetails[0].status}",
"PipelineName":"@{pipeline().Pipeline}"
}

Once it's configured link the Copy Data, Web(Send-mail) & Web(Send-Mail-Failure).



















Then go back to the Logic Apps and configure the rest,






















Configure the action "When a HTTP request is received", 
















Request Body JSON Schema:
{
    "properties": {
        "CopyDuration": {
            "type""string"
        },
        "DataFactoryName": {
            "type""string"
        },
        "DataSource": {
            "type""string"
        },
        "DataTarget": {
            "type""string"
        },
        "ErrorMessage": {
            "type""string"
        },
        "PipelineName": {
            "type""string"
        },
        "SourceSize": {
            "type""string"
        },
        "Status": {
            "type""string"
        },
        "Subject": {
            "type""string"
        },
        "TargetSize": {
            "type""string"
        },
        "TotalSourceFilesRead": {
            "type""string"
        },
        "TotalTargetFilesWritten": {
            "type""string"
        },
        "activityRunId": {
            "type""string"
        }
    },
    "type""object"
}

Configure the action "List Blobs (V2)" : This is to list the Log file stored in the Azure Storage Account. 












Folder: /adflogs/copyactivity-logs/copy-storageaccount-files/activityRunId/

Next Filter Array action is used to retrieve the log file,









Next action is "Get blob content using path (V2)": This action is to get the file from the storage account.












For Body expression content "body('Filter_array')[0]['DisplayName']"
Click on the Add dynamic Content -> Expression -> Paste the above data















Finally, Add mail action to send the mail.

















Attachment:









All the configuration part is completed, Now run the Data Factory pipeline and see if the mail is triggered. 

Final mail would be with attachment of Logs and the below details.







































Comments