Thứ Ba, 29 tháng 3, 2022

Job cảnh báo user sắp hết hạn mật khẩu trong Oracle Database

Mục đích: Job cảnh báo user sắp hết hạn mật khẩu, cần phải đổi gấp trước khi bị lock

CREATE OR REPLACE PROCEDURE BINHTV.alert_db_account
is
    cursor c1 is
        select b.username user1, a.username, a.account_status, a.expiry_date, b.email, b.tel_number, b.status, b.rowid row_id, round(a.expiry_date - sysdate) expire_day from dba_users a, dangth.tctk_user b
        where a.username = b.username and a.profile = 'PROFILE_USER' and a.username not in ('BINHTV') order by a.expiry_date;
    p_msg varchar2(150);
    p_html varchar2(4000);
    p_html_2 varchar2(32767);
    is_send_email varchar2(2);
    p_new_status varchar2(10);
    p_expire number;
    p_expired_date date;
    p_status varchar2(20);
begin
    p_html_2 := ' <br><br><strong> Thong ke user Database DBAViet </font> </strong><br><br><br>
            <table style="border:1px solid black;border-collapse:collapse;">
            <tr>
            <th style="border:1px solid black;background-color:lightblue;">Username</th>
            <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
            <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
            </tr>' ;
    for v1 in c1
    loop
        p_msg := '0';
        is_send_email := '0';
            p_html_2 := p_html_2 || '<tr>
            <th style="border:1px black;background-color:white;">'||v1.username||'</th>
            <th style="border:1px black;background-color:white;">'||v1.account_status||'</th>
            <th style="border:1px black;background-color:white;">'||to_char(v1.expiry_date, 'dd/mm/yyyy hh24:mi:ss')||'</th>
            </tr>';
        if (v1.status = 'OPEN' or v1.status is null) then
            if v1.expire_day <= 0 then
                p_msg := 'Tai khoan database DBAViet ' || v1.username || ' cua ban da het han vao ngay ' || to_char(v1.expiry_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long lien he To he thong de reset tai khoan.';
                p_html := 'Kinh gui anh, chi, <br><br><strong> <font color = Red> DBA Team xin thong bao user database DBAViet cua anh/chi da het han! Vui long lien he DBA Team de reset tai khoan. </font> </strong><br><br><br>
            <table style="border:1px solid black;border-collapse:collapse;">
            <tr>
            <th style="border:1px solid black;background-color:lightblue;">Username</th>
            <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
            <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
            </tr>' ;
                p_html := p_html ||
            '<tr>
            <th style="border:1px solid black;background-color:white;"><font color = Red>'||v1.username||'</font></th>
            <th style="border:1px solid black;background-color:white;"><font color = Red>'||v1.account_status||'</font></th>
            <th style="border:1px solid black;background-color:white;"><font color = Red>'||to_char(v1.expiry_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
            </tr>';
                is_send_email := '1';
            else
                if v1.expire_day < 3 then
                    p_msg := 'Tai khoan database DBAViet ' || v1.username || ' cua ban se het han vao ngay ' || to_char(v1.expiry_date,'dd/mm/yyyy hh24:mi:ss') || '. Vui long doi mat khau truoc khi het han.';
                    p_html := 'Kinh gui anh, chi, <br><br><strong> To he thong xin thong bao user database DBAViet cua anh/chi se het han trong <font color = Red>'|| v1.expire_day || ' ngay </font> nua! Vui long doi mat khau truoc khi het han.  </strong><br><br>Cau lenh doi mat khau: alter user '||v1.username||' identified by new_password replace old_password;<br>
            <table style="border:1px solid black;border-collapse:collapse;">
            <tr>
            <th style="border:1px solid black;background-color:lightblue;">Username</th>
            <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
            <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
            </tr>' ;
                    p_html := p_html || '<tr>
            <th style="border:1px solid black;background-color:white;"><font color = Orange>'||v1.username||'</font></th>
            <th style="border:1px solid black;background-color:white;"><font color = Orange>'||v1.account_status||'</font></th>
            <th style="border:1px solid black;background-color:white;"><font color = Orange>'||to_char(v1.expiry_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
            </tr>';
                    is_send_email := '1';
                end if;
            end if;
        elsif v1.status = 'EXPIRED(GRACE)' then
            p_msg := 'Tai khoan database MobiGold ' || v1.username || ' cua ban da het han va se bi khoa vao ngay ' || to_char(v1.expiry_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long doi mat khau truoc khi bi khoa.';
            p_html := 'Kinh gui anh, chi, <br><br><strong> <font color = Red> DBA Team xin thong bao user database DBAViet cua anh/chi da het han va se bi khoa vao ngay ' || to_char(v1.expiry_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long doi mat khau truoc khi bi khoa. </font> </strong><br><br><br>
            <table style="border:1px solid black;border-collapse:collapse;">
            <tr>
            <th style="border:1px solid black;background-color:lightblue;">Username</th>
            <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
            <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
            </tr>' ;
            p_html := p_html ||
          '<tr>
             <th style="border:1px solid black;background-color:white;"><font color = Red>'||v1.username||'</font></th>
             <th style="border:1px solid black;background-color:white;"><font color = Red>'||v1.account_status||'</font></th>
             <th style="border:1px solid black;background-color:white;"><font color = Red>'||to_char(v1.expiry_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
             </tr>';
             is_send_email := '1';
        end if;
        if p_msg <> '0' then
          -- Gửi SMS (nếu có)
        end if;
        if is_send_email <> '0' then
           -- gửi email sys.send_email_html_m(v1.email,'Canh bao tai khoan Database',p_html);
        end if;
        update tctk_user set status = v1.account_status where rowid = v1.row_id;
        commit;
    end loop;
    select round(expiry_date - sysdate), account_status into p_expire, p_status from dba_users where username = 'PARTNER_SUPPORT';
    is_send_email := '0';
    if (p_status = 'OPEN' or p_status is null) then
         if p_expire <= 0 then
             p_msg := 'Tai khoan database DBAViet PARTNER_SUPPORTcua ban da het han vao ngay ' || to_char(p_expired_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long lien he DBA Team de reset tai khoan.';
             p_html := 'Kinh gui anh, chi, <br><br><strong> <font color = Red> To he thong xin thong bao user database DBaViet cua anh/chi da het han! Vui long lien he DBA Team de reset tai khoan. </font> </strong><br><br><br>
         <table style="border:1px solid black;border-collapse:collapse;">
         <tr>
         <th style="border:1px solid black;background-color:lightblue;">Username</th>
         <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
         <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
         </tr>' ;
             p_html := p_html ||
         '<tr>
         <th style="border:1px solid black;background-color:white;"><font color = Red>FPT_SUPPORT</font></th>
         <th style="border:1px solid black;background-color:white;"><font color = Red>'||p_status||'</font></th>
         <th style="border:1px solid black;background-color:white;"><font color = Red>'||to_char(p_expired_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
         </tr>';
             is_send_email := '1';
         else
             if p_expire < 3 then
                 p_msg := 'Tai khoan database DBAViet PARTNER_SUPPORT cua ban se het han vao ngay ' || to_char(p_expired_date,'dd/mm/yyyy hh24:mi:ss') || '. Vui long doi mat khau truoc khi het han.';
                 p_html := 'Kinh gui anh, chi, <br><br><strong> DBA Team xin thong bao user database DBAViet cua anh/chi se het han trong <font color = Red>'|| p_expire || ' ngay </font> nua! Vui long doi mat khau truoc khi het han.  </strong><br><br>Cau lenh doi mat khau: alter user PARTNER_SUPPORT identified by new_password replace old_password;<br>
         <table style="border:1px solid black;border-collapse:collapse;">
         <tr>
         <th style="border:1px solid black;background-color:lightblue;">Username</th>
         <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
         <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
         </tr>' ;
                 p_html := p_html || '<tr>
         <th style="border:1px solid black;background-color:white;"><font color = Orange>PARTNER_SUPPORT</font></th>
         <th style="border:1px solid black;background-color:white;"><font color = Orange>p_status</font></th>
         <th style="border:1px solid black;background-color:white;"><font color = Orange>'||to_char(p_expired_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
         </tr>';
                 is_send_email := '1';
             end if;
         end if;
     elsif p_status = 'EXPIRED(GRACE)' then
         p_msg := 'Tai khoan database DBAViet PARTNER_SUPPORT cua ban da het han va se bi khoa vao ngay ' || to_char(p_expired_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long doi mat khau truoc khi bi khoa.';
         p_html := 'Kinh gui anh, chi, <br><br><strong> <font color = Red> DBA Team xin thong bao user database DBAViet cua anh/chi da het han va se bi khoa vao ngay ' || to_char(p_expired_date,'dd/mm/yyyy hh24:mi:ss') || '! Vui long doi mat khau truoc khi bi khoa. </font> </strong><br><br><br>
         <table style="border:1px solid black;border-collapse:collapse;">
         <tr>
         <th style="border:1px solid black;background-color:lightblue;">Username</th>
         <th style="border:1px solid black;background-color:lightblue;">Trang thai</th>
         <th style="border:1px solid black;background-color:lightblue;">Ngay het han</th>
         </tr>' ;
         p_html := p_html ||
       '<tr>
          <th style="border:1px solid black;background-color:white;"><font color = Red>FPT_SUPPORT</font></th>
          <th style="border:1px solid black;background-color:white;"><font color = Red>'||p_status||'</font></th>
          <th style="border:1px solid black;background-color:white;"><font color = Red>'||to_char(p_expired_date, 'dd/mm/yyyy hh24:mi:ss')||'</font></th>
          </tr>';
          is_send_email := '1';
     end if;
    if is_send_email <> '0' then
       sys.send_email_html_m('tranbinh48ca@gmail.com','Canh bao tai khoan Database',p_html);
    end if;
    sys.send_email_html_m('tranbinh48ca@gmail.com','Thong ke tai khoan database DBAViet phong He thong',p_html_2);
    commit;
   EXCEPTION
      WHEN OTHERS THEN
         null
end;
/

=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile: 0902912888
⚡️ Skype: tranbinh48ca
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,khóa học pl/sql, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, middleware, hoc solaris, hoc linux, hoc aix, unix, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master