v_bi_alm_all_alarm_year.sql 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. -- lawe.v_bi_alm_all_alarm_year source
  2. CREATE OR REPLACE
  3. ALGORITHM = UNDEFINED VIEW `v_bi_alm_all_alarm_year` AS
  4. select
  5. `m`.`alarm_object_ip` AS `alarm_object_ip`,
  6. `m`.`alarm_object_id` AS `alarm_object_id`,
  7. `m`.`alarm_object_type` AS `alarm_object_type`,
  8. `m`.`alarm_object_name` AS `alarm_object_name`,
  9. `m`.`severity_id` AS `severity_id`,
  10. `m`.`title` AS `title`,
  11. `m`.`alarm_text` AS `alarm_text`,
  12. `m`.`clr_status` AS `clr_status`,
  13. `m`.`alarm_count` AS `alarm_count`,
  14. `m`.`bg_time` AS `bg_time`,
  15. `m`.`ed_time` AS `ed_time`,
  16. `m`.`years` AS `years`,
  17. `m`.`dtype` AS `dtype`,
  18. `m`.`thedvalue` AS `thedvalue`,
  19. `m`.`is_active_alarm` AS `is_active_alarm`,
  20. floor((`m`.`alarm_count` / `m`.`years`)) AS `avg_alarm_count`,
  21. if((`m`.`alarm_source` = '性能告警'),
  22. ((60 / 5) * 24 * 365),
  23. ((60 * 2) * 24 * 365)) AS `collection_frequency`
  24. from
  25. (
  26. select
  27. `aa`.`alarm_object_ip` AS `alarm_object_ip`,
  28. `aa`.`alarm_object_id` AS `alarm_object_id`,
  29. `aa`.`alarm_object_type` AS `alarm_object_type`,
  30. `aa`.`alarm_object_name` AS `alarm_object_name`,
  31. `aa`.`severity_id` AS `severity_id`,
  32. `aa`.`title` AS `title`,
  33. `aa`.`alarm_text` AS `alarm_text`,
  34. `aa`.`clr_status` AS `clr_status`,
  35. `aa`.`alarm_count` AS `alarm_count`,
  36. cast(date_format(`aa`.`occur_time`, '%Y') as unsigned) AS `bg_time`,
  37. cast(date_format(`aa`.`update_time`, '%Y') as unsigned) AS `ed_time`,
  38. (timestampdiff(YEAR,
  39. `aa`.`occur_time`,
  40. `aa`.`update_time`) + 1) AS `years`,
  41. 'YEAR' AS `dtype`,
  42. `dates`.`thedvalue` AS `thedvalue`,
  43. 1 AS `is_active_alarm`,
  44. alarm_source
  45. from
  46. (`t_alm_active_alarm` `aa`
  47. join (
  48. select
  49. distinct floor((`dd`.`YYYYMMDD` / 10000)) AS `thedvalue`
  50. from
  51. `dim_date` `dd`
  52. where
  53. (`dd`.`YYYYMMDD` between 20230101 and 20261231)) `dates`)
  54. union all
  55. select
  56. `ha`.`alarm_object_ip` AS `alarm_object_ip`,
  57. `ha`.`alarm_object_id` AS `alarm_object_id`,
  58. `ha`.`alarm_object_type` AS `alarm_object_type`,
  59. `ha`.`alarm_object_name` AS `alarm_object_name`,
  60. `ha`.`severity_id` AS `severity_id`,
  61. `ha`.`title` AS `title`,
  62. `ha`.`alarm_text` AS `alarm_text`,
  63. `ha`.`clr_status` AS `clr_status`,
  64. `ha`.`alarm_count` AS `alarm_count`,
  65. cast(date_format(`ha`.`occur_time`, '%Y') as unsigned) AS `bg_time`,
  66. cast(date_format(`ha`.`update_time`, '%Y') as unsigned) AS `ed_time`,
  67. (timestampdiff(YEAR,
  68. `ha`.`occur_time`,
  69. `ha`.`update_time`) + 1) AS `years`,
  70. 'YEAR' AS `dtype`,
  71. `dates`.`thedvalue` AS `thedvalue`,
  72. 0 AS `is_active_alarm`,
  73. alarm_source
  74. from
  75. (`t_alm_history_alarm` `ha`
  76. join (
  77. select
  78. distinct floor((`dd`.`YYYYMMDD` / 10000)) AS `thedvalue`
  79. from
  80. `dim_date` `dd`
  81. where
  82. (`dd`.`YYYYMMDD` between 20230101 and 20261231)) `dates`)) `m`
  83. where
  84. (`m`.`thedvalue` between `m`.`bg_time` and `m`.`ed_time`);