1 Reply Latest reply on Apr 11, 2012 3:11 AM by Rnr-Oracle

    Send SNMP trap when a Oracle Job Fails

    sdk11
      Hi,

      I am trying to understand how to setup on Oracle side to send an SNMP trap when a Oracle scheduled job fails. I have never done this in the past. Please share your thoughts.

      Thanks
        • 1. Re: Send SNMP trap when a Oracle Job Fails
          Rnr-Oracle
          Hi,

          I would do this in two steps.

          - write a plsql procedure which sends the snmp trap

          - create a second job which is event-based and runs when the first job has failed and calls the plsql procedure to send the snmp trap. Sample code to do this is below.

          Hope this helps,
          Ravi

          Code to run one job when another (called first_job) has failed. Run this code as the user owning the job.
          exec dbms_scheduler.add_event_queue_subscriber('myagent')
          exec  dbms_scheduler.set_attribute ( 'first_job' , 'raise_events' , dbms_scheduler.job_failed);
          begin
            dbms_scheduler.create_job('second_job',
                                      job_type=>'plsql_block',
                                      job_action=>'send_snmp_procedure();',
                                      event_condition =>
             'tab.user_data.object_name = ''FIRST_JOB''',
                                      queue_spec =>'sys.scheduler$_event_queue,myagent',
                                      enabled=>true);
          end;
          /

          -- this allows multiple simultaneous runs of the second job on 11g and up
          begin
            $IF DBMS_DB_VERSION.VER_LE_10 $THEN
              null;
            $ELSE
              dbms_scheduler.set_attribute('second_job', 'parallel_instances',true);
            $END
          end;
          /