commalert.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package monitor
  15. import (
  16. time "time"
  17. )
  18. const (
  19. ALERT_STATUS_READY = "ready"
  20. ALERT_STATUS_DELETE = "start_delete"
  21. ALERT_STATUS_DELETE_FAIL = "delete_fail"
  22. ALERT_STATUS_DELETING = "deleting"
  23. ALERT_STATUS_DELETED = "deleted"
  24. CommonAlertSystemAlertType = "system"
  25. CommonAlertNomalAlertType = "normal"
  26. CommonAlertServiceAlertType = "service"
  27. MonitorComponentType = "default-monitor"
  28. MonitorComponentPort = 30093
  29. SubscribAPI = "subscriptions"
  30. MonitorDefaultRC = "30day_only"
  31. MonitorSubName = "commonalert"
  32. MonitorSubDataBase = "telegraf"
  33. CommonAlertDefaultRecipient = "commonalert-default"
  34. DEFAULT_SEND_NOTIFY_CHANNEL = "users"
  35. METRIC_QUERY_TYPE_NO_DATA = "nodata_query"
  36. METRIC_QUERY_NO_DATA_THESHOLD = "nodata"
  37. CommonAlertLevelNormal = "normal"
  38. CommonAlertLevelImportant = "important"
  39. CommonAlertLevelFatal = "fatal"
  40. )
  41. type CommonAlertFieldOpt string
  42. const (
  43. //metirc fields 之间的运算
  44. CommonAlertFieldOptDivision CommonAlertFieldOpt = "/"
  45. )
  46. var CommonAlertLevels = []string{CommonAlertLevelNormal, CommonAlertLevelImportant, CommonAlertLevelFatal}
  47. type CommonAlertCreateBaseInput struct {
  48. // 报警连续持续周期数
  49. AlertDuration int64 `json:"alert_duration"`
  50. // 通知方式, 比如: email, mobile
  51. Channel []string `json:"channel"`
  52. // 通知接受者
  53. Recipients []string `json:"recipients"`
  54. RobotIds []string `json:"robot_ids"`
  55. // 角色 id 或者 name
  56. Roles []string `json:"roles"`
  57. // 为 true 时不发送恢复通知(OK)
  58. DisableNotifyRecovery *bool `json:"disable_notify_recovery"`
  59. // 静默期
  60. SilentPeriod string `json:"silent_period"`
  61. // 报警类型
  62. AlertType string `json:"alert_type"`
  63. // Scope Resource
  64. Scope string `json:"scope"`
  65. DomainId string `json:"domain_id"`
  66. ProjectId string `json:"project_id"`
  67. GetPointStr bool `json:"get_point_str"`
  68. MetaName string `json:"meta_name"`
  69. Description string `json:"description"`
  70. }
  71. type CommonAlertCreateInput struct {
  72. CommonMetricInputQuery
  73. AlertCreateInput
  74. CommonAlertCreateBaseInput
  75. // 查询指标周期
  76. Period string `json:"period"`
  77. }
  78. type CommonMetricInputQuery struct {
  79. From string `json:"from"`
  80. To string `json:"to"`
  81. Interval string `json:"interval"`
  82. MetricQuery []*CommonAlertQuery `json:"metric_query"`
  83. }
  84. type CommonAlertQuery struct {
  85. *AlertQuery
  86. // metric points'value的运算方式
  87. Reduce string `json:"reduce"`
  88. // 比较运算符, 比如: >, <, >=, <=, within_range, outside_range
  89. Comparator string `json:"comparator"`
  90. // 报警阀值 (用于 gt, lt, eq)
  91. Threshold float64 `json:"threshold"`
  92. // 范围参数 (用于 within_range, outside_range)
  93. ThresholdRange []float64 `json:"threshold_range"`
  94. // field 运算
  95. FieldOpt CommonAlertFieldOpt `json:"field_opt"`
  96. ConditionType string `json:"condition_type"`
  97. // Operator should be chosen from 'and | or'
  98. Operator string `json:"operator"`
  99. }
  100. // TopQueryInput 用于 top 查询的通用时间段和 top 参数
  101. type TopQueryInput struct {
  102. // 查询时间段开始时间
  103. StartTime time.Time `json:"start_time"`
  104. // 查询时间段结束时间
  105. EndTime time.Time `json:"end_time"`
  106. // 返回 top N(默认 5)
  107. Top *int `json:"top"`
  108. }
  109. type CommonAlertListInput struct {
  110. AlertListInput
  111. //V1AlertListInput
  112. // 报警类型
  113. AlertType string `json:"alert_type"`
  114. // 监控指标名称
  115. Metric string `json:"metric"`
  116. Level string `json:"level"`
  117. ResType []string `json:"res_type"`
  118. UsedBy string `json:"used_by"`
  119. Name string `json:"name"`
  120. // Top 查询参数(用于统计报警资源最多的监控策略)
  121. TopQueryInput
  122. }
  123. type CommonAlertUpdateInput struct {
  124. CommonMetricInputQuery
  125. V1AlertUpdateInput
  126. // 查询指标周期
  127. Period string `json:"period"`
  128. // 报警连续持续周期数
  129. AlertDuration int64 `json:"alert_duration"`
  130. // 通知方式, 比如: email, mobile
  131. Channel []string `json:"channel"`
  132. // 通知接受者
  133. Recipients []string `json:"recipients"`
  134. // 为 true 时不发送恢复通知(OK)
  135. DisableNotifyRecovery *bool `json:"disable_notify_recovery"`
  136. // 静默期
  137. SilentPeriod string `json:"silent_period"`
  138. // systemalert policy may need update through operator
  139. ForceUpdate bool `json:"force_update"`
  140. GetPointStr bool `json:"get_point_str"`
  141. MetaName string `json:"meta_name"`
  142. }
  143. type CommonAlertDetails struct {
  144. AlertDetails
  145. Period string `json:"period"`
  146. // 报警连续持续周期数
  147. AlertDuration int64 `json:"alert_duration"`
  148. Level string `json:"level"`
  149. NotifierId string `json:"notifier_id"`
  150. Channel []string `json:"channel"`
  151. Recipients []string `json:"recipients"`
  152. RobotIds []string `json:"robot_ids"`
  153. RoleIds []string `json:"role_ids"`
  154. DisableNotifyRecovery bool `json:"disable_notify_recovery"`
  155. // 静默期
  156. SilentPeriod string `json:"silent_period"`
  157. Status string `json:"status"`
  158. // 报警类型
  159. AlertType string `json:"alert_type"`
  160. CommonAlertMetricDetails []*CommonAlertMetricDetails `json:"common_alert_metric_details"`
  161. }
  162. type CommonAlertMetricDetails struct {
  163. Operator string `json:"operator"`
  164. Comparator string `json:"comparator"`
  165. Threshold float64 `json:"threshold"`
  166. ThresholdRange []float64 `json:"threshold_range"`
  167. ConditionType string `json:"condition_type"`
  168. ThresholdStr string `json:"threshold_str"`
  169. // metric points'value的运算方式
  170. Reduce string `json:"reduce"`
  171. DB string `json:"db"`
  172. Measurement string `json:"measurement"`
  173. MeasurementDisplayName string `json:"measurement_display_name"`
  174. ResType string `json:"res_type"`
  175. Field string `json:"field"`
  176. Groupby string `json:"groupby"`
  177. Filters []MetricQueryTag `json:"filters"`
  178. FieldDescription MetricFieldDetail
  179. FieldOpt string `json:"field_opt"`
  180. GetPointStr bool `json:"get_point_str"`
  181. }