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.
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.
| 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 |
CREATE TABLE job_log (jobid RAW(16),
occured DATE);
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;
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.
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.
Associate the PL/SQL procedure with a notification rule.
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:
UNIX: $ENV_VARIABLE
MS Windows: %ENV_VARIABLE%
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.
Create an OS command on the repository host machine.
Create an OS Command on each Management Service machine that connects to the Management Repository. The OS Command should be an absolute pathname and must be the same on each Management Service host machine e.g. /u1/bin/logSeverity.sh. The command is run by the user who started the Management Service. If an error is encountered during the running of the OS Command, the Notification System can be instructed to retry the sending of the notification to the OS Command by returning an exit code of 100. The procedure is 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.
The following parameter in emoms.properties controls how long the OS Command can execute without being killed by the Management Service. This is to prevent OS Commands from running for an inordinate length of time and blocking the delivery of other notifications. By default the command is allowed to run for 30 seconds before it is killed. See (add a pointer to the other doc that discusses all these parameters)
# The amount of time in seconds after which an OS Command started by the
# Notification System will be killed if it has not exited
# em.notification.os_cmd_timeout=30
Add this OS command as a notification method that can be called in Notification Rules. See Adding an OS Command.
Define a notification rule (choose the targets and conditions for which you want to be notified), and associate the OS command with the rule. See Defining Notification Rules.
Enterprise Manager Information Roadmap
Copyright © 1996, 2007, Oracle. All rights reserved.