ユーザーへの日次メンテナンス完了の通知

Oracle Enterprise Performance Management Cloud環境の日次メンテナンスに要する時間は、多くの場合、予定されている1時間よりもはるかに短くなります。

環境の実際の日次メンテナンス所要時間は、アクティビティ・レポートの操作メトリック・セクションにある日次メンテナンス所要時間(分単位)メトリックの値として記録されます。時間全体を待たずに環境を使用する場合は、このスクリプトのカスタム・バージョンを使用して、日次メンテナンスが完了してユーザーがアクティビティを再開できることをユーザーに通知します。

Windowsスクリプト

次のPowerShellスクリプトをコピーして、daily_maintenance_completed.ps1を作成します。スクリプトを更新して使用する方法の詳細は、スクリプトの実行を参照してください。
# Daily Maintenance Completed Notification script
#
# Update the following parameters
# -------------------------------
$emailaddresses=user1@oracle.com,user2@oracle.com
# -------------------------------

$username=$args[0]
$password=$args[1]
$url=$args[2]

if ($($args.count) -ne 3) {
    echo "Usage: ./daily_maintenance_completed.ps1 <USERNAME> <PASSWORD> <URL>"
    exit 1
}

$amw_time=""

function getDailyMaintenanceStartTime {
    $amwstring=$(epmautomate.bat getDailyMaintenanceStartTime)
    $elements=$amwstring.split(' ')
    $amwtime=$elements[0]
    return $amwtime
}

function goToSleep ($amw_time){
    $current_mdy=Get-Date -AsUTC -UFormat "%m/%d/%Y"
    $current_date_time=Get-Date -AsUTC -UFormat "%m/%d/%Y %H:%M:%S"
    $current_epoch=Get-Date -Date $current_date_time -UFormat "%s"
    $target_date_time=[DateTime]"${current_mdy} ${amw_time}"
    $target_epoch=Get-Date -Date $target_date_time -UFormat "%s"
    $sleep_seconds=$target_epoch - $current_epoch

    # Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if ($sleep_seconds -lt 0) {
        $sleep_seconds=$sleep_seconds + 86400
    }

    $sleep_ts=New-TimeSpan -Seconds ${sleep_seconds}
    $sleep_hms="${sleep_ts}" -replace '^\d+?\.'

    echo "Current time is ${current_date_time}. Sleeping for ${sleep_hms}, until daily maintenance start time of ${amw_time}."
    Start-Sleep -Seconds $sleep_seconds
}

function attemptLogin {
    $serverdown=$False
    while ($true) {
        epmautomate.bat login ${username} ${password} ${url}
        if ($?) { # login succeeded
            if ($serverdown) { # server has been brought down
                echo "Daily maintenance processing has completed ..."
                break
            } else { # server has not yet been brought down
                echo "Daily maintenance processing has not yet started. Sleeping for 2 minutes before the next check ..."
                Start-Sleep -Seconds 120
            }
        } else { # login failed
            if ($serverdown) { # server has been brought down
                echo "Waiting for daily maintenance processing to complete. Sleeping for 2 minutes before the next check ..."
                Start-Sleep -Seconds 120
            } else { # server has not yet been brought down
                echo "Daily maintenance processing is now beginning. Sleeping for 2 minutes before the next check ..."
                Start-Sleep -Seconds 120
                $serverdown=$True
            }
        }
    }
}

function sendNotification {
    $servername=$url.split("/")[2];
    $subject="Daily maintenance processing has completed"
    $formattedmessage="Daily maintenance processing has completed for server ${servername}"
    $emailaddresses=${emailaddresses}.replace(',',';')

    echo "Mailing report"
    epmautomate.bat sendmail "${emailaddresses}" "${subject}" Body="${formattedmessage}"
}

echo "Beginning daily maintenance completion notification script."
echo "Logging into server ..."
epmautomate.bat login ${username} ${password} ${url}
$amwtime=getDailyMaintenanceStartTime
goToSleep ($amwtime)
attemptLogin
sendNotification
echo "Logging out of server ..."
epmautomate.bat logout
echo "Script processing has completed."

Linux/UNIXのスクリプト

次のスクリプトをコピーして、daily_maintenance_completed.shを作成します。スクリプトを更新して使用する方法の詳細は、スクリプトの実行を参照してください。
#!/bin/bash
# Update the following parameters
# -------------------------------
epmautomatescript="LOCATION_EPM_AUTOMATE_EXECUTABLE"
javahome="LOCATION_JAVA_HOME"
emailaddresses=EMAIL_ADDRESS_1,EMAIL_ADDRESS_2,EMAIL_ADDRESS_N
# -------------------------------

username="$1"
password="$2"
url="$3"

export JAVA_HOME=${javahome}

if [ "$#" -ne 3 ]; then
    echo "Usage: ./daily_maintenance_completed.sh <USERNAME> <PASSWORD> <URL>"
    exit 1
fi

amw_time=""

getDailyMaintenanceStartTime() {
    amw_time=$(${epmautomatescript} getDailyMaintenanceStartTime | cut -d' ' -f1)
}

goToSleep() {
    current_mdy=$(date -u +%m/%d/%Y)
    current_date_time=$(date -u)
    current_epoch=$(date +%s)
    target_epoch=$(date -d "${current_mdy} ${amw_time}" +%s)
    sleep_seconds=$(($target_epoch - $current_epoch))

    # Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if [[ ${sleep_seconds} -lt 0 ]]
    then
        sleep_seconds=$((sleep_seconds + 86400))
    fi

    sleep_hms=$(date -d@${sleep_seconds} -u +%H:%M:%S)

    echo "Current time is ${current_date_time}. Sleeping for ${sleep_hms}, until daily maintenance start time of ${amw_time}."
    sleep $sleep_seconds
}

attemptLogin() {
    local serverdown=1
    while true
    do
        ${epmautomatescript} login ${username} ${password} ${url}
        if [[ $? -eq 0 ]] # login succeeded
        then
            if [[ ${serverdown} -eq 0 ]] # server has been brought down
            then
                echo "Daily maintenance processing has completed"
                break
            else # server has not yet been brought down
                echo "Daily maintenance processing has not yet started. Sleeping for 2 minutes before the next check ..."
                sleep 120
            fi
        else # login failed
            if [[ ${serverdown} -eq 0 ]] # server has been brought down
            then
                echo "Waiting for daily maintenance processing to complete. Sleeping for 2 minutes before the next check ..."
                sleep 120
            else # server has not yet been brought down
                echo "Daily maintenance processing is now beginning. Sleeping for 2 minutes before the next check ..."
                sleep 120
                serverdown=0
            fi
        fi
    done
}

sendNotification()
{
    local servername=$(echo "${url}" | cut -d '/' -f3- | rev | cut -d':' -f2- | rev)
    local subject="Daily maintenance processing has completed"
    local formattedmessage="Daily maintenance processing has completed for server ${servername}"
    local emailaddresses=$(echo ${emailaddresses} | sed "s/,/;/g")

    echo "Mailing report"
    ${epmautomatescript} sendmail "${emailaddresses}" "${subject}" Body="${formattedmessage}"
}

echo "Beginning daily maintenance completion notification script."
echo "Logging into server ..."
${epmautomatescript} login ${username} ${password} ${url}
getDailyMaintenanceStartTime
goToSleep
attemptLogin
sendNotification
echo "Logging out of server ..."
${epmautomatescript} logout
echo "Script processing has completed."

サーバー側Groovyスクリプト

次のコードをコピーして、daily_maintenance_completed Groovyスクリプトを作成します。スクリプトを更新して使用する方法の詳細は、スクリプトの実行を参照してください。

// Daily Maintenance Completed Notification script

// Update the following parameters
// -------------------------------
String username="USERNAME"
String password="PASSWORD"
String url="URL OF THE ENVIRONMENT"
String emailaddresses="EMAIL_ADDRESS_1,EMAIL_ADDRESS_2,EMAIL_ADDRESS_N"
// -------------------------------

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

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

def getDailyMaintenanceStartTime(EpmAutomate automate) {
    LogMessage("Operation: getDailyMaintenanceStartTime")
    EpmAutomateStatus amwtimestatus = automate.execute('getDailyMaintenanceStartTime')
    LogOperationStatus(amwtimestatus)
    def amwstring=(amwtimestatus.getOutput())
    def elements=amwstring.split(' ')
    def amwtime=elements[0]
    return amwtime
}

def goToSleep(String amw_time){
    def date = new Date()
    def current_mdy = new SimpleDateFormat("MM/dd/yyyy")
    def current_date_time = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
    float current_epoch = date.getTime() / 1000
    def pattern = "MM/dd/yyyy HH:mm:ss"
    def input = current_mdy.format(date) + " " + amw_time + ":00"
    def target_date_time = Date.parse(pattern, input)
    float target_epoch = target_date_time.getTime() / 1000
    int sleep_seconds = Math.round(target_epoch - current_epoch)

    //Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if (sleep_seconds < 0) {
        sleep_seconds = sleep_seconds + 86400
    }
    
    def sleep_milliseconds = sleep_seconds * 1000
    LogMessage("Current time is " + current_date_time.format(date) + ". Sleeping until daily maintenance start time of " + amw_time + ":00.")
    sleep(sleep_milliseconds)
}

def attemptLogin(EpmAutomate automate, String username, String password, String url) {
    def serverdown=1
    while (true) {
        LogMessage("Operation: login " + username + " " + password + " " + url)
        EpmAutomateStatus status = automate.execute('login',username,password,url)
        def returncode = status.getStatus()
        if (returncode == 0) { 
            if (serverdown == 0){
                LogMessage("Daily maintenance processing has completed ...")
                break
            } else {
                LogMessage("Daily maintenance processing has not yet started. Sleeping for 2 minutes before the next check ...")
                sleep(120000)
            }
        } else {
            if (serverdown == 0){
                LogMessage("Waiting for daily maintenance processing to complete. Sleeping for 2 minutes before the next check ...")
                sleep(120000)
            } else {
                LogMessage("Daily maintenance processing is now beginning. Sleeping for 2 minutes before the next check ...")
                sleep(120000)
                serverdown=0
            }
        }
    }
}

def sendNotification(EpmAutomate automate, String url, String emailaddresses) {
    def servername=url.tokenize("/")[-1];
    def subject="Daily maintenance processing has completed"
    def formattedmessage="Daily maintenance processing has completed for server " + servername
    def emailaddressesformatted = emailaddresses.replaceAll(',',';')

    LogMessage("Operation: sendmail " + emailaddressesformatted + " " + subject + " Body=" + formattedmessage)
    EpmAutomateStatus status = automate.execute('sendmail',emailaddressesformatted,subject,'Body=' + formattedmessage)
    LogOperationStatus(status)
}

LogMessage("Beginning daily maintenance completion notification script.")

EpmAutomate automate = getEpmAutomate()

LogMessage("Operation: login " + username + " " + password + " " + url)
EpmAutomateStatus status = automate.execute('login',username,password,url)
LogOperationStatus(status)

String amwtime = getDailyMaintenanceStartTime(automate)
goToSleep (amwtime)
attemptLogin(automate,username,password,url)
sendNotification(automate,url,emailaddresses)

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

LogMessage ("Script processing has completed.")

スクリプトの実行

WindowsおよびLinux/UNIX
  1. 前述の項のスクリプトをコピーして、daily_maintenance_completed.ps1またはdaily_maintenance_completed.shを作成します。
  2. スクリプトを更新します:
    • Windows: 日次メンテナンスが完了したときに通知する必要がある電子メール・アドレスのカンマ区切りリストを指定して、emailaddressesの値を更新します。
    • Linux/UNIX: 次の変数を更新します:
      • epmautomatescript (EPM自動化の実行可能ファイルの場所を指定)。例: epmautomatescript="/home/utils/EPMAutomate/bin/epmautomate.sh"
      • javahome (EPM自動化で使用されるJDKがインストールされているディレクトリを指定)。例: "/home/user1/jdk1.8.0_191"
      • emailaddresses (日次メンテナンスが完了したときに通知する必要がある電子メール・アドレスのカンマ区切りリストを指定)。例: jdoe@example.com,jane_doe@example.com
  3. コマンド・ウィンドウまたはコンソールで、daily_maintenance_completedスクリプトが格納されたフォルダにナビゲートします。
  4. 次のコマンドを実行します。
    • Windows: ./daily_maintenance_completed.ps1 USERNAME PASSWORD URL
    • Linux/UNIX: ./daily_maintenance_completed.sh USERNAME PASSWORD URL、ここで:
      • USERNAMEは、サービス管理者のユーザー名です
      • PASSWORDは、サービス管理者のパスワードです
      • URLは、EPM Cloud環境のURLです
サーバー側Groovy:
  1. 前述の項のスクリプトをコピーして、daily_maintenance_completed.groovy Groovyスクリプトを作成します。
  2. 次の値を更新します。
    • username (サービス管理者のユーザー名を指定)。
    • password (サービス管理者のパスワードを指定)
    • url (日次メンテナンス完了通知を送信する必要があるEPM Cloud環境のURLを指定)。次に例を示します。例: https://testExample-idDomain.pbcs.us1.oraclecloud.com
    • emailaddresses (日次メンテナンスが完了したときに通知する必要がある電子メール・アドレスのカンマ区切りリストを指定)。
  3. EPM Cloudビジネス・プロセスでGroovy画面を使用するか、runBusinessRuleを使用してスクリプトの実行を自動化します。詳細は、次の情報ソースを参照してください: