2022-07-18

send a Teams message from oracle PL/SQL

 http://oraclesean.blogspot.com/2017/06/sending-messages-from-oracle-database.html


orapki wallet add -wallet /oracle/wallet -trusted_cert -cert "/oracle/wallet/GeoTrustGlobalCA.cer" -pwd suPerStr0ngP@ssword

Send JSON from Oracle to Slack

With the certificate imported into the Wallet, all we need to do now is send a POST request to the Webhooks URL with the JSON message we want to have reported in Slack.

  declare
          req                  utl_http.req;
          res                  utl_http.resp;
          url                  varchar2(4000) := 'https://hooks.slack.com/services/your_webhook_url_goes_here';
          name                 varchar2(4000);
          buffer               varchar2(4000); 
          content              varchar2(4000);
          db_name              v$database.name%TYPE;
    begin

          utl_http.set_wallet('file:/oracle/wallet', 'suPerStr0ngP@ssword');

           select name
             into db_name
             from v$database;

         content := '{"channel": "#oracle", "username": "orabot", "text": "Test post to the #oracle channel from database ' || db_name || '", "icon_emoji": ":oracle:"}';req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
         utl_http.set_header(req, 'user-agent', 'mozilla/4.0'); 
         utl_http.set_header(req, 'content-type', 'application/json'); 
         utl_http.set_header(req, 'Content-Length', length(content));

         utl_http.write_text(req, content);

         res := utl_http.get_response(req);

             begin
              loop
                   utl_http.read_line(res, buffer);
                   dbms_output.put_line(buffer);
          end loop;
                   utl_http.end_response(res);
         exception
              when utl_http.end_of_body
              then utl_http.end_response(res);
               end;
     end;
/

The end result is the message being delivered to Slack:

Niciun comentariu:

Trimiteți un comentariu