Passing Job Status Change Information

Passing job status change attributes such as new status, job name, job type, notification rule, or rule owner to PL/SQL procedures or OS commands/scripts allows you to customize automated responses to status changes. For example, you many want to call an OS script to open a trouble ticket for an in-house support trouble ticket system if a critical job fails to run. In this case you will want to pass status such as Problems or Aborted to the script to open a trouble ticket and escalate the problem.

Passing Information to a PLSQL Procedure

The notification system passes job status change information to a PL/SQL procedure via the MGMT_NOTIFY_JOB object. An instance of this object is created for every status change. When a job changes status, the notification system calls the PL/SQL procedure associated with the notification rule and passes the populated object to the procedure. The procedure is then able to access the fields of the MGMT_NOTIFY_JOB object that has been passed to it.

The following table lists all job status change attributes that can be passed:

Attribute
Datatype
Additional Information

job_name

VARCHAR2(128)

The job name

job_owner

VARCHAR2(256)

The owner of the job
job_type VARCHAR2(32) The type of the job

job_status

NUMBER

The new status of the job

state_change_guid  

RAW(16)

The GUID of the state change record

job_guid

RAW(16)

The unique id of the job

execution_id

RAW(16)

The unique id of the execution

targets

SMP_EMD_NVPAIR_ARRAY

An array of the target name/target type pairs that the job runs on

rule_owner

VARCHAR2(64)

The name of the notification rule that cause the notification to be sent

rule_name

VARCHAR2(132)

The owner of the notification rule that cause the notification to be sent

When a job status change occurs for the job, the notification system creates an instance of the MGMT_NOTIFY_JOB object and populates it with values from the status change. The following status codes have been defined as constants in the MGMT_JOBS package and can be used to determine the type of status in the job_status field of the MGMT_NOTIFY_JOB object.

Job Status Codes

Name
Datatype
Value

SCHEDULED_STATUS

NUMBER(2)

1

EXECUTING_STATUS

NUMBER(2)

2

ABORTED_STATUS

NUMBER(2)

3

FAILED_STATUS

NUMBER(2)

4

COMPLETED_STATUS

NUMBER(2)

5

SUSPENDED_STATUS

NUMBER(2)

6

AGENTDOWN_STATUS

NUMBER(2)

7

STOPPED_STATUS

NUMBER(2)

8

SUSPENDED_LOCK_STATUS

NUMBER(2)

9

SUSPENDED_EVENT_STATUS

NUMBER(2)

10

SUSPENDED_BLACKOUT_STATUS

NUMBER(2)

11

STOP_PENDING_STATUS
NUMBER(2) 12
SUSPEND_PENDING_STATUS
NUMBER(2) 13
INACTIVE_STATUS
NUMBER(2) 14
QUEUED_STATUS
NUMBER(2) 15
FAILED_RETRIED_STATUS
NUMBER(2) 16
WAITING_STATUS
NUMBER(2) 17
SKIPPED_STATUS
NUMBER(2) 18
REASSIGNED_STATUS
NUMBER(2) 20

Example: PL/SQL Procedure Using a Status Code

CREATE TABLE job_log (jobid RAW(16),
occured DATE);

PL/SQL Procedure

CREATE OR REPLACE PROCEDURE LOG_PROBLEM_JOBS(status_change IN MGMT_NOTIFY_JOB)
IS
BEGIN
-- Log all failed jobs
IF status_change.job_status = MGMT_JOBS.FAILED_STATUS
THEN
BEGIN
INSERT INTO job_log (jobid, occured)
VALUES (status_change.job_guid, SYSDATE);
EXCEPTION
WHEN OTHERS
THEN
-- If there are any problems then get the notification retried
RAISE_APPLICATION_ERROR(-20000, 'Please retry');
END;
COMMIT;
END IF;
END LOG_PROBLEM_JOBS;

Using a PL/SQL Procedure:

  1. Create the PL/SQL procedure on the repository database using the following procedure specification:

    PROCEDURE p(status_change IN MGMT_NOTIFY_JOB)

    If an error is encountered during the running of the procedure, the Notification System can be instructed to retry the sending of the notification to the procedure by raising a user defined exception that uses the error code -20000. See the example above. The procedure initially retried after one minute, then two minutes, then three minutes and so on, until the notification is a day old, at which point it will be purged.

  2. Add this PLSQL procedure as a notification method that can be called in Notification Rules. See Adding a PLSQL Procedure.

    Make sure to use a fully qualified name that includes the schema owner, package name and procedure name. The procedure will be executed by the repository owner and so the repository owner must have EXECUTE permission on the procedure.

  3. Associate the PL/SQL procedure with a notification rule.

Passing Information to an OS Script or Executable

The notification system passes severity information to an OS script or executable via system environment variables. Conventions used to access environmental variables vary depending on the operating system:

The notification system sets the following environment variables before calling the script.

Environment Variable
Description

JOB_NAME

The name of the job

JOB_OWNER

The owner of the job

JOB_TYPE

The type of job

JOB_STATUS

The job status

TIMESTAMP

Time when the severity occurred.

NUM_TARGETS

The number of targets

TARGET_NAMEn
The name of the nth target e.g. TARGET_NAME1, TARGET_NAME2
TARGET_TYPEn
The type of the nth target e.g. TARGET_TYPE1, TARGET_TYPE2

RULE_NAME

Name of the notification rule that resulted in the severity.

RULE_OWNER

Name of the Enterprise Manager administrator who owns the rule.

Your script may reference some or all of these variables.

Using an OS Script or Executable

 

Related Topics

Enterprise Manager Information Roadmap