Emailing the Activity Report Using a Server-side Groovy Script

This script can be used to email the Activity Report to a list of recipients. This script can then be scheduled to run daily to get the daily Activity Report. This script performs the following functions:

  • Encrypts the password of the Service Administrator who executes the Groovy script.
  • Signs into the Oracle Enterprise Performance Management Cloud environment using the encrypted password.
  • Emails the Activity Report available in the environment to a list of recipients, generally, Service Administrators
  • Signs out of the environment.

If passwords contain special characters, see Handling Special Characters. Also, be sure to replace these parameter values to suit your environments:

Table 4-2 Parameters to Change

Parameter Description
user The user ID of a Service Administrator to sign into the environment.
password The password of the Service Administrator.
url URL of the EPM Cloud environment from which the Activity Report is to be emailed.
emailaddresses A semicolon separated list of email addresses to which the Activity Report is to be sent.

For detailed information on using Groovy rules, see Using Groovy Rules in Administering Planning .

/*RTPS: {user} {password} {url} {emailaddresses}*/
import java.text.SimpleDateFormat

String user = 'service_administrator'
String password = 'examplePWD'
String url = 'example_EPM_URL'
String emailaddresses = 'service_administrator@oracle.com'

EpmAutomate automate = getEpmAutomate()

def LogMessage(String message) {
    def date = new Date()
    def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
    println('[' + sdf.format(date) + '][GROOVY] ' + message);
}

def LogOperationStatus(EpmAutomateStatus opstatus) {
    def returncode = opstatus.getStatus()
    LogMessage(opstatus.getOutput())
    LogMessage('return code: ' + returncode)
}

LogMessage('Starting mail activity report processing')

// encrypt
LogMessage("Operation: encrypt " + password + " oracleKey password.epw")
EpmAutomateStatus status = automate.execute('encrypt',password,"oracleKey","password.epw")
LogOperationStatus(status)

// login
LogMessage("Operation: login " + user + " password.epw " + url)
status = automate.execute('login',user,"password.epw",url)
LogOperationStatus(status)

// listfiles
LogMessage('Operation: listfiles')
status = automate.execute('listfiles')
LogOperationStatus(status)

String filelist = status.getItemsList()
String[] str = filelist.split(',');
String reportfile = ''

for( String svalues : str ) {
    String[] ftr = svalues.split('/')
    for( String fvalues : ftr ) {
        if (fvalues.startsWith('2') && fvalues.endsWith('html')) {
            reportfile = fvalues
        }
    }
}

def reportdir = reportfile.tokenize(".")[0]
String reportpath = 'apr/' + reportdir + '/' + reportfile

// sendMail
LogMessage('Operation: sendMail ' + emailaddresses + ' Daily Activity Report Body=Daily Activity Report Attachments=' + reportpath)
status = automate.execute('sendmail',emailaddresses,'Daily Activity Report','Body=Daily Activity Report',"Attachments=${reportpath}")
LogOperationStatus(status)

// logout
LogMessage('Operation: logout')
status = automate.execute('logout')
LogOperationStatus(status)