FM_FREQ_PRD.sql 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. --/
  2. CREATE PROCEDURE FM_FREQ_PRD
  3. AS
  4. -- create by duf 2017-11-30 产品:梁梅
  5. --四川_20171115_智能网与EPC重大故障预警需求描述文档V1.3 以下章节的 “同一网元30分钟内3次及以上闪断,每次闪断条数大于等于10条” 判断
  6. --3.1.3.5 智能网场景五
  7. --3.1.3.7 彩信场景二
  8. -- 需求要求30秒轮巡一次,sch job 调度
  9. v_time date:=sysdate;
  10. v_title varchar2(128);
  11. v_ne_id varchar2(128);
  12. v_first_time date;
  13. v_max_event_id number;
  14. v_device_class varchar2(64);
  15. v_first_time_cur date; -- 发现时间-当前
  16. v_cnt number; -- 1分钟内内断的告警数量
  17. v_rn number; --告警排序
  18. v_num number:=0;--闪断次数计次
  19. BEGIN
  20. dbms_output.put_line('v_time='||to_char(v_time,'yyyy-mm-dd hh24:mi:ss'));
  21. for cur_1 in (
  22. -- 只需要告警 与SIPFEP链路中断,由于这个告警少,暂时加了一个告警 告警指示信号(LP-AIS) 做验证
  23. select * from
  24. (
  25. select count(*) over(partition by e.ne_id,e.title,e.device_class) cnt,
  26. row_number() over(partition by e.ne_id,e.title,e.device_class order by e.first_occurrence_time) rn,
  27. max(e.event_id) over(partition by e.ne_id,e.title,e.device_class) max_event_id,
  28. e.*
  29. from fm_alarm_recent e
  30. where e.is_cleared=1
  31. and e.title in ('与SIPFEP链路中断')
  32. and e.first_occurrence_time>=v_time-30/1440
  33. and e.first_occurrence_time<v_time
  34. and e.first_occurrence_time>e.clear_time-1/1440
  35. and e.construct_alarm_flag=0
  36. and e.device_class in ('SCP','彩铃','SDH')
  37. and not exists (select 1 from fm_alarm_freq f where e.ne_id=f.ne_id and e.title=f.title and e.device_class=f.device_class and e.first_occurrence_time<=f.first_occurrence_time)
  38. ) where cnt>=30
  39. order by ne_id,title,rn
  40. )loop
  41. v_title:=cur_1.title;
  42. v_ne_id:=cur_1.ne_id;
  43. v_device_class:=cur_1.device_class;
  44. v_max_event_id:=cur_1.max_event_id;
  45. v_rn:=cur_1.rn;
  46. v_first_time:=cur_1.first_occurrence_time;
  47. if v_rn=1
  48. then
  49. -- 闪断计次初始化
  50. v_num:=0;
  51. v_first_time_cur:=v_first_time;
  52. -- dbms_output.put_line('new ne_id --------------------------');
  53. dbms_output.put_line('ne_id='||v_ne_id);
  54. -- 新的ne_id+title 告警组开始
  55. select count(*) into v_cnt
  56. from fm_alarm_recent e
  57. where e.is_cleared=1
  58. and e.title=v_title
  59. and e.ne_id=v_ne_id
  60. and e.first_occurrence_time>=v_time-30/1440
  61. and e.first_occurrence_time<v_time
  62. and e.first_occurrence_time>e.clear_time-1/1440
  63. and e.first_occurrence_time>=v_first_time
  64. and e.first_occurrence_time<=v_first_time+1/1440;
  65. if v_cnt>=10
  66. then
  67. dbms_output.put_line(to_char(v_first_time,'yyyy-mm-dd hh24:mi:ss')||'-'||to_char(v_first_time+1/1440,'yyyy-mm-dd hh24:mi:ss')||' 1分钟内闪断达到'||v_cnt||',计闪断1次');
  68. v_first_time_cur:=v_first_time+1/1440;
  69. v_num:=v_num+1;
  70. end if;
  71. else
  72. if v_num>=3
  73. then
  74. continue;
  75. end if;
  76. if v_first_time_cur>=v_first_time
  77. then
  78. -- 这个是已经被计为闪断的告警
  79. continue;
  80. else
  81. -- 这个是没有被计为闪断的告警,重新按这个告警的时间再统计1分钟内闪断次数据是否达到要求
  82. select count(*) into v_cnt
  83. from fm_alarm_recent e
  84. where e.is_cleared=1
  85. and e.title=v_title
  86. and e.ne_id=v_ne_id
  87. and e.first_occurrence_time>=v_time-30/1440
  88. and e.first_occurrence_time<v_time
  89. and e.first_occurrence_time>e.clear_time-1/1440
  90. and e.first_occurrence_time>=v_first_time
  91. and e.first_occurrence_time<=v_first_time+1/1440;
  92. if v_cnt>=10
  93. then
  94. dbms_output.put_line(to_char(v_first_time,'yyyy-mm-dd hh24:mi:ss')||'-'||to_char(v_first_time+1/1440,'yyyy-mm-dd hh24:mi:ss')||' 1分钟内闪断达到'||v_cnt||',计闪断1次');
  95. v_first_time_cur:=v_first_time+1/1440;
  96. v_num:=v_num+1;
  97. if v_num=3
  98. then
  99. dbms_output.put_line('闪断次数已达到3次');
  100. insert into fm_alarm_freq(ne_id,title,first_occurrence_time,device_class,event_id) values (v_ne_id,v_title,v_time,v_device_class,v_max_event_id);
  101. commit;
  102. v_num:=v_num+1;
  103. continue;
  104. end if;
  105. end if;
  106. end if;
  107. end if;
  108. end loop;
  109. -- 清除闪断告警
  110. update fm_alarm_freq e set e.is_cleared=1,e.clear_time=sysdate
  111. where not exists (select 1 from fm_alarm_freq e1 where e.ne_id=e1.ne_id and e.title=e1.title and e1.first_occurrence_time>sysdate-30/1440)
  112. and e.is_cleared=0;
  113. commit;
  114. -- 只保留3天的数据
  115. delete from fm_alarm_freq where first_occurrence_time<trunc(sysdate-3);
  116. commit;
  117. END;
  118. /