Oracle Fusion Analytics Event Notifications with OCI Functions

August 3, 2023 | 6 minute read
Krishna Prasad Kotti
Senior Member of Technical Staff
Text Size 100%:

Introduction

Oracle Fusion Analytics (FAW) is an Oracle Cloud Infrastructure (OCI) native service that leverages the power of Oracle Autonomous Data Warehouse (ADW) and Oracle Analytics Cloud (OAC).  It provides a comprehensive analytics solution that includes a data pipeline, data warehouse, semantic model, and content such as dashboards and reports. Fusion Analytics extracts data from various sources, transforms it, and loads it into an ADW.

As businesses expand and develop, the importance of automation in managing data and analytics applications also grows. Based on user input, Oracle has rolled out the FAW Event Producer service that gives you more control over tracking customized events and notifications. This service is an effective automated solution for creating consolidated events and notification workflows that can streamline your Fusion Analytics business operations. This feature is available in Preview.

To review the Event Notifications feature, see Get notified when your data refresh completes using event notifications and Features Available for Preview.

This post describes a specific use case and provides step-by-step instructions for using custom functions to send email notifications based on FAW events.

Overview of Functions

Oracle Cloud Infrastructure Functions offer a fully managed, multi-tenant, highly scalable, and on-demand Functions-as-a-Service platform. It’s built on enterprise-grade Oracle Cloud Infrastructure and powered by the Fn Project open-source engine. Use OCI Functions (sometimes abbreviated to just Functions and formerly known as Oracle Functions) when you want to focus on writing code to meet your business needs.

Functions are units coded in Java, Python, Node, Go, Ruby, and C# languages and regrouped in Applications. This example uses Python, the most widely used language for Data Science.

Functions are stored as Docker images in a specified container registry. You can invoke them in different ways:

  • Using the Fn Project CLI.

  • Using the Oracle Cloud Infrastructure CLI / Cloud Shell.

  • Using the Oracle Cloud Infrastructure SDKs.

  • Making a signed HTTP request to the function's invoke endpoint. Every function has an invoke endpoint

How do I use the custom functions to send email notifications based on FAW Events?

Set up an OCI user and SMTP credentials. The SMTP credentials are necessary to send emails through email delivery. Each user is limited to a maximum of two SMTP credentials. If you need more than two, create another user.

  1. Sign in to the OCI Console.
  2. Create a user or use an existing user.
  3. Navigate to User Settings.
  4. Click SMTP Credentials.
  5. Copy the user name and password. You can't retrieve the password after closing the dialog for security reasons.

Create a function

Follow the steps described in Functions QuickStart on Cloud Shell to set up functions.

You can use code such as the following to create the function. 

#

import io
import json
import smtplib
import email.utils
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

from fdk import response

def handler(ctx, data: io.BytesIO = None):

# Update the below values based on your configurations"
    smtp_username = ""
    smtp_password = ""
    smtp_host = ""
    smtp_port = ""
    sender_email = ""
    sender_name = ""
    recipient = ""
    subject = ""

#Variables to store the various Tags from JSON Event output"
    eventTime = ""
    resourceName = ""
    refreshType = ""
    estimatedCompletionTime = ""
    eventType = ""
    completionTime = ""
    sourceType=""

    try:
        payload = json.loads(data.getvalue())
        eventTime = payload.get("eventTime")
        resourceName = payload.get("data").get("resourceName")
        refreshType = payload.get("data").get("additionalDetails").get("refreshType")
        sourceType = payload.get("data").get("additionalDetails").get("sourceType")
        eventType = payload.get("eventType")
        body = ""

#You can modify the body and a custom message based your requirements        
        if eventType == 'com.oraclecloud.analyticswarehouse.pipeline.datarefresh.estimate':
            estimatedCompletionTime = payload.get("data").get("additionalDetails").get("estimatedCompletionTime")
            body2 = "FAW Pipeline Estimator Details\n Instance: " + resourceName + "\n Refresh Type: " \
                     + refreshType + "\n Estimated completion: " + estimatedCompletionTime +"\n Source Type: " + sourceType + "."
            body = body + body2
        elif eventType == 'com.oraclecloud.analyticswarehouse.pipeline.datarefresh.complete':
            completionTime = payload.get("data").get("additionalDetails").get("completionTime")
            body3 = "FAW Pipeline Completion Details\n Instance: " + resourceName + "\n Refresh Type: " \
                     + refreshType + "\n Completion Time: " + completionTime +"\n Source Type: " + sourceType + "."
            body = body + body3
        else:
            body = body + eventTime + " " + resourceName + " " + eventType + " " + refreshType
    except Exception as ex:
        print('ERROR: Missing key in payload', ex, flush=True)
        raise

    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = email.utils.formataddr((sender_name, sender_email))
    msg['To'] = recipient
    msg.attach(MIMEText(body, 'plain'))

    try:
        server = smtplib.SMTP(smtp_host, smtp_port)
        server.ehlo()
        server.starttls()
        server.ehlo()
        server.login(smtp_username, smtp_password)
        server.sendmail(sender_email, recipient, msg.as_string())
        server.close()
    except Exception as ex:
        print("ERROR: ", ex, flush=True)
        raise
    else:
        print("INFO: Email successfully sent!", flush=True)

    return response.Response(
        ctx,
        response_data="Email successfully sent!",
        headers={"Content-Type": "application/json"}
    )

Ensure that you complete all the steps needed to create an OCI function.

Review the code and update the SMTP configurations and email address details in the code. 

To enable the FAW event service feature and create custom automation that sends an email using the FAW Event Producer service, follow these steps:

  1. Sign in to the FAW Console, click Enable Features, and enable Event Notification.
  2. Sign in to the OCI Console and create a topic for “FAW Data Load Complete."
  3. Subscribe to the topic with your function.

References
Consult these resources:

Events Service | Oracle
Overview of Notifications (oracle.com)
Overview of Functions (oracle.com)

Call to Action

If you need a secure and reliable means to automate events and notifications for your Oracle Fusion Analytics implementation, then try the FAW Event Producer service. By subscribing to these events, you can create custom workflows and eliminate the need for ad-hoc communications such as emails and service request tickets.

You can choose to be automatically notified of important events such as the daily data pipeline completion and you can eliminate the need to constantly check the system for completion.

Krishna Prasad Kotti

Senior Member of Technical Staff


Previous Post

Choosing the proper Oracle Autonomous Data Warehouse database service name for Oracle Analytics Cloud

Lisa Garczynski | 6 min read

Next Post


Span of Control & Manager Assignment – A Dataset based Approach

Sivakumaran Muthusamy | 7 min read