alert_date date,
alert_text varchar2(&&alert_length)
)
create index alert_log_idx on alert_log(alert_date)
column db new_value _DB noprint;
column bdump new_value _bdump noprint;
where name ='background_dump_dest';
drop directory BDUMP;
create directory BDUMP as '&&_bdump';
organization external (
type oracle_loader
default directory BDUMP
access parameters (
records delimited by newline nologfile nobadfile
fields terminated by "&" ltrim
)
location('alert_&&_DB..log')
)
reject limit unlimited;
/*
此存儲過程用於每天實時監控alert日誌,如有錯誤自動發送email
*/
start_updating number := 0;
rows_inserted number := 0;
alert_date date;
max_date date;
alert_text alert_log_disk.text%type;
v_alert_log varchar2(5000);
v_ora_count number := 0;
type Text_Type is table of varchar2(50);
to_addr_list Text_Type :=Text_Type('[email protected]','[email protected]','[email protected]');--收件人
v_html varchar2(30000);
begin
select max(alert_date) into max_date from alert_log;
--max_date := to_date('30-03-2011', 'dd-mm-yyyy');
max_date := sysdate;
end if;
--過濾不需要的記錄
for r in (select substr(text, 1, 180) text
from alert_log_disk
where text not like '%offlining%'
and text not like 'ARC_:%'
and text not like '%LOG_ARCHIVE_DEST_1%'
and text not like '%Thread 1 advanced to log sequence%'
and text not like '%Current log#%seq#%mem#%'
and text not like '%Undo Segment%lined%'
and text not like '%alter tablespace%back%'
and text not like
'%Log actively being archived by another process%'
and text not like
'%alter database backup controlfile to trace%'
and text not like '%Created Undo Segment%'
and text not like '%started with pid%'
and text not like '%ORA-12012%'
and text not like '%ORA-06512%'
and text not like '%ORA-000060:%'
and text not like '%coalesce%'
and text not like
'%Beginning log switch checkpoint up to RBA%'
and text not like '%Completed checkpoint up to RBA%'
and text not like '%specifies an obsolete parameter%'
and text not like '%BEGIN BACKUP%'
and text not like '%END BACKUP%'
and (text like '%ORA-%' or
substr(text, 21) in ('2010', '2011', '2012', '2013'))
) loop
isdate := 0;
alert_text := null;
--日期
select count(*)
into isdate
from dual
where substr(r.text, 21) in ('2010', '2011', '2012', '2013')
and r.text not like '%cycle_run_year%';
if (isdate = 1) then
SELECT TO_DATE(SUBSTR(R.TEXT, 5),
'Mon dd hh24:mi:ss rrrr',
'NLS_DATE_LANGUAGE = American')
into alert_date
from dual;
if (round((sysdate - alert_date) * 24 * 60) <= 5) then
start_updating := 1;
end if;
else
alert_text := r.text;
end if;
if (alert_text is not null) and (start_updating = 1) then
insert into alert_log
values
(alert_date, substr(alert_text, 1, 180));
rows_inserted := rows_inserted + 1;
--錯誤列表拼接成html
v_alert_log := v_alert_log || '<tr><td style="width:150px">' || to_char(alert_date,'yyyy/mm/dd hh24:mi:ss') || '</td><td>' ||
alert_text || '</td></tr>';
commit;
end if;
end loop;
sys.dbms_output.put_line('Inserting after date ' ||
to_char(max_date, 'MM/DD/RR HH24:MI:SS'));
sys.dbms_output.put_line('Rows Inserted: ' || rows_inserted);
if (length(v_alert_log) > 5) then
v_html := '<table style="font-size:13px">' || v_alert_log || '</table>';
for i in 1 .. to_addr_list.count loop
sp_common_mail_html('[email protected]',
to_addr_list(i),
'數據中心實時alert日誌監控!',
'test',
v_html,
'xx.xxxx.com.cn',
25);
end loop;
end if;
variable job1 number;
begin
dbms_job.submit(:job1,'sp_data_monitor_alert_log;',trunc(sysdate)+5/1440, 'sysdate+51440');
commit;
end;