v_bi_alm_all_alarm_day.sql 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. -- lawe.v_bi_alm_all_alarm_day source
  2. CREATE OR REPLACE
  3. ALGORITHM = UNDEFINED VIEW `v_bi_alm_all_alarm_day` AS
  4. select
  5. `m`.`alarm_object_ip` AS `alarm_object_ip`,
  6. `m`.`alarm_object_id` AS `alarm_object_id`,
  7. (case
  8. when (`m`.`alarm_object_type` = '000100001') then '物理机'
  9. when (`m`.`alarm_object_type` = '000100002') then '云主机'
  10. when (`m`.`alarm_object_type` = '000100004') then '宿主机'
  11. when (substr(`m`.`alarm_object_type`, 1, 4) = '0001') then '其他主机'
  12. when (`m`.`alarm_object_type` = '000200001') then '交换机'
  13. when (`m`.`alarm_object_type` = '000200002') then '路由器'
  14. when (`m`.`alarm_object_type` = '000300001') then '存储设备'
  15. when (substr(`m`.`alarm_object_type`, 1, 4) = '0004') then '安全设备'
  16. when (substr(`m`.`alarm_object_type`, 1, 4) = '0014') then '网络'
  17. when ((`m`.`alarm_object_type` like '%0012%')
  18. or (`m`.`alarm_object_type` like '%app%')) then '应用'
  19. else '其它未知类型'
  20. end) AS `alarm_object_type`,
  21. `m`.`alarm_object_name` AS `alarm_object_name`,
  22. `m`.`severity_id` AS `severity_id`,
  23. `m`.`title` AS `title`,
  24. `m`.`alarm_text` AS `alarm_text`,
  25. `m`.`clr_status` AS `clr_status`,
  26. `m`.`alarm_count` AS `alarm_count`,
  27. `m`.`bg_time` AS `bg_time`,
  28. `m`.`ed_time` AS `ed_time`,
  29. `m`.`days` AS `days`,
  30. `m`.`dtype` AS `dtype`,
  31. `m`.`thedvalue` AS `thedvalue`,
  32. `m`.`is_active_alarm` AS `is_active_alarm`,
  33. floor((`m`.`alarm_count` / `m`.`days`)) AS `avg_alarm_count`,
  34. if((`m`.`alarm_source` = '性能告警'),
  35. ((60 / 5) * 24),
  36. ((60 * 2) * 24)) AS `collection_frequency`,
  37. (case
  38. when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
  39. and (`m`.`update_time` >= `m`.`thedvalue_e`)) then (60 * 24)
  40. when ((`m`.`occur_time` > `m`.`thedvalue_b`)
  41. and (`m`.`update_time` >= `m`.`thedvalue_e`)) then ((60 * 24) - (`m`.`occur_time` % 100))
  42. when ((`m`.`occur_time` <= `m`.`thedvalue_b`)
  43. and (`m`.`update_time` < `m`.`thedvalue_e`)) then (`m`.`update_time` % 100)
  44. when ((`m`.`occur_time` > `m`.`thedvalue_b`)
  45. and (`m`.`update_time` < `m`.`thedvalue_e`)) then ((`m`.`update_time` % 100) - (`m`.`occur_time` % 100))
  46. end) AS `alarm_duration`
  47. from
  48. (
  49. select
  50. `aa`.`alarm_object_ip` AS `alarm_object_ip`,
  51. `aa`.`alarm_object_id` AS `alarm_object_id`,
  52. `aa`.`alarm_object_type` AS `alarm_object_type`,
  53. `aa`.`alarm_object_name` AS `alarm_object_name`,
  54. `aa`.`severity_id` AS `severity_id`,
  55. `aa`.`title` AS `title`,
  56. `aa`.`alarm_text` AS `alarm_text`,
  57. `aa`.`clr_status` AS `clr_status`,
  58. `aa`.`alarm_count` AS `alarm_count`,
  59. cast(date_format(`aa`.`occur_time`, '%Y%m%d') as unsigned) AS `bg_time`,
  60. cast(date_format(`aa`.`update_time`, '%Y%m%d') as unsigned) AS `ed_time`,
  61. (abs((to_days(`aa`.`update_time`) - to_days(`aa`.`occur_time`))) + 1) AS `days`,
  62. 'DAY' AS `dtype`,
  63. `dates`.`YYYYMMDD` AS `thedvalue`,
  64. 1 AS `is_active_alarm`,
  65. `aa`.`alarm_source` AS `alarm_source`,
  66. date_format(str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m'), '%Y%m%d%H00') AS `thedvalue_b`,
  67. date_format((str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m') + interval 1 day), '%Y%m%d%H00') AS `thedvalue_e`,
  68. date_format(`aa`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
  69. date_format(`aa`.`update_time`, '%Y%m%d%H%m') AS `update_time`
  70. from
  71. (`t_alm_active_alarm` `aa`
  72. join (
  73. select
  74. `dd`.`YYYYMMDD` AS `YYYYMMDD`
  75. from
  76. `dim_date` `dd`
  77. where
  78. (`dd`.`YYYYMMDD` between 20230101 and 20241231)) `dates`)
  79. union all
  80. select
  81. `ha`.`alarm_object_ip` AS `alarm_object_ip`,
  82. `ha`.`alarm_object_id` AS `alarm_object_id`,
  83. `ha`.`alarm_object_type` AS `alarm_object_type`,
  84. `ha`.`alarm_object_name` AS `alarm_object_name`,
  85. `ha`.`severity_id` AS `severity_id`,
  86. `ha`.`title` AS `title`,
  87. `ha`.`alarm_text` AS `alarm_text`,
  88. `ha`.`clr_status` AS `clr_status`,
  89. `ha`.`alarm_count` AS `alarm_count`,
  90. cast(date_format(`ha`.`occur_time`, '%Y%m%d') as unsigned) AS `bg_time`,
  91. cast(date_format(`ha`.`update_time`, '%Y%m%d') as unsigned) AS `ed_time`,
  92. (abs((to_days(`ha`.`update_time`) - to_days(`ha`.`occur_time`))) + 1) AS `days`,
  93. 'DAY' AS `dtype`,
  94. `dates`.`YYYYMMDD` AS `thedvalue`,
  95. 0 AS `is_active_alarm`,
  96. `ha`.`alarm_source` AS `alarm_source`,
  97. date_format(str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m'), '%Y%m%d%H00') AS `thedvalue_b`,
  98. date_format((str_to_date(`dates`.`YYYYMMDD`, '%Y%m%d%H%m') + interval 1 day), '%Y%m%d%H00') AS `thedvalue_e`,
  99. date_format(`ha`.`occur_time`, '%Y%m%d%H%m') AS `occur_time`,
  100. date_format(`ha`.`update_time`, '%Y%m%d%H%m') AS `update_time`
  101. from
  102. (`t_alm_history_alarm` `ha`
  103. join (
  104. select
  105. `dd`.`YYYYMMDD` AS `YYYYMMDD`
  106. from
  107. `dim_date` `dd`
  108. where
  109. (`dd`.`YYYYMMDD` between 20230101 and 20241231)) `dates`)) `m`
  110. where
  111. (`m`.`thedvalue` between `m`.`bg_time` and `m`.`ed_time`);