Thursday, March 16, 2023

Automating ADDM Recommendations: How to Stay Ahead of Performance Issues with Hourly Email Updates

 Here is a general outline of the automation process to send an email of the latest ADDM recommendation on an hourly basis. Here's how you can do it:

Write a script to extract the latest ADDM recommendation from the AWR repository. You can use SQL commands to query the AWR repository and retrieve the latest ADDM report.

Configure your email client to send an email programmatically. You can use the Simple Mail Transfer Protocol (SMTP) to send an email from your email account to a designated email recipient.

Integrate the script and email client to automate the email sending process. You can use a scheduling tool like cron to run the script on an hourly basis and send the email automatically.

Here's an example code snippet in Python:



import smtplib
from email.mime.text import MIMEText

def send_email(recommendation):
    # configure the email message
    msg = MIMEText(recommendation)
    msg['Subject'] = 'Latest ADDM Recommendation'
    msg['From'] = 'sender_email_address'
    msg['To'] = 'recipient_email_address'

    # configure the SMTP server
    smtp_server = smtplib.SMTP('smtp.gmail.com', 587)
    smtp_server.starttls()
    smtp_server.login('sender_email_address', 'sender_email_password')

    # send the email
    smtp_server.sendmail('sender_email_address', 'recipient_email_address', msg.as_string())
    smtp_server.quit()

# extract the latest ADDM recommendation from the AWR repository
latest_recommendation = extract_latest_addm_recommendation()

# send the email on an hourly basis
while True:
    send_email(latest_recommendation)
    time.sleep(3600) # wait for an hour

Here is a general outline of the automation process to send an email of the latest ADDM recommendation on an hourly basis. 
Here's how you can do it:
This Python script that extracts the latest ADDM recommendation from the AWR repository and sends it via email on an hourly basis using the extract_latest_addm_recommendation and send_email functions:

import smtplib
from email.mime.text import MIMEText
import cx_Oracle
import time

# database connection details
username = 'your_database_username'
password = 'your_database_password'
dsn = 'your_database_dsn'

# email details
sender_email = 'sender_email_address'
sender_password = 'sender_email_password'
recipient_email = 'recipient_email_address'

def extract_latest_addm_recommendation():
    # connect to the database
    connection = cx_Oracle.connect(username, password, dsn)

    # execute the SQL query to retrieve the latest ADDM report
    cursor = connection.cursor()
    cursor.execute('''
        SELECT db_name, start_snap_id, end_snap_id, report_html
        FROM dba_hist_snapshot
        JOIN dba_hist_snapshot_report
        ON dba_hist_snapshot.snap_id = dba_hist_snapshot_report.snap_id
        WHERE dba_hist_snapshot_report.report_name = 'ADDM Report'
        ORDER BY end_interval_time DESC
        FETCH FIRST 1 ROW ONLY
    ''')
    result = cursor.fetchone()

    # close the cursor and database connection
    cursor.close()
    connection.close()

    # return the ADDM report HTML as a string
    if result is not None:
        return result[3].read()

def send_email(recommendation):
    # configure the email message
    msg = MIMEText(recommendation)
    msg['Subject'] = 'Latest ADDM Recommendation'
    msg['From'] = sender_email
    msg['To'] = recipient_email

    # configure the SMTP server
    smtp_server = smtplib.SMTP('smtp.gmail.com', 587)
    smtp_server.starttls()
    smtp_server.login(sender_email, sender_password)

    # send the email
    smtp_server.sendmail(sender_email, recipient_email, msg.as_string())
    smtp_server.quit()

# send the email on an hourly basis
while True:
    # extract the latest ADDM recommendation from the AWR repository
    latest_recommendation = extract_latest_addm_recommendation()

    # send the email with the latest ADDM recommendation
    if latest_recommendation is not None:
        send_email(latest_recommendation)

    # wait for an hour before sending the next email
    time.sleep(3600)
This script assumes that you have installed the cx_Oracle library for connecting to the Oracle database and configured your email account settings properly. You may need to modify the script to suit your specific database and email environment.

Popular Posts