models.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package alerting
  2. import (
  3. "time"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. )
  6. type AlertJob struct {
  7. Offset int64
  8. Delay bool
  9. Running bool
  10. RetryCount int
  11. Rule *AlertRule
  12. }
  13. func (aj *AlertJob) Retryable() bool {
  14. return aj.RetryCount < maxAlertExecutionRetries
  15. }
  16. func (aj *AlertJob) ResetRetry() {
  17. aj.RetryCount = 0
  18. }
  19. func (aj *AlertJob) IncRetry() {
  20. aj.RetryCount++
  21. }
  22. type AlertResultContext struct {
  23. Triggered bool
  24. IsTestRun bool
  25. Details []*AlertResultDetail
  26. Logs []*AlertResultLogEntry
  27. Error error
  28. Description string
  29. StartTime time.Time
  30. EndTime time.Time
  31. Rule *AlertRule
  32. DoneChan chan bool
  33. CancelChan chan bool
  34. }
  35. func (a *AlertResultContext) GetDurationSeconds() float64 {
  36. return float64(a.EndTime.Nanosecond()-a.StartTime.Nanosecond()) / float64(1000000000)
  37. }
  38. func NewAlertResultContext(rule *AlertRule) *AlertResultContext {
  39. return &AlertResultContext{
  40. StartTime: time.Now(),
  41. Rule: rule,
  42. Logs: make([]*AlertResultLogEntry, 0),
  43. DoneChan: make(chan bool, 1),
  44. CancelChan: make(chan bool, 1),
  45. }
  46. }
  47. type AlertResultLogEntry struct {
  48. Message string
  49. Data interface{}
  50. }
  51. type AlertResultDetail struct {
  52. Value float64
  53. Metric string
  54. State string
  55. Tags map[string]string
  56. }
  57. type Level struct {
  58. Operator string
  59. Value float64
  60. }
  61. type AlertQuery struct {
  62. Model *simplejson.Json
  63. DatasourceId int64
  64. From string
  65. To string
  66. }