interfaces.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 alerting
  15. import (
  16. "context"
  17. "time"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/onecloud/pkg/apis/monitor"
  20. "yunion.io/x/onecloud/pkg/monitor/models"
  21. "yunion.io/x/onecloud/pkg/monitor/notifydrivers"
  22. )
  23. type evalHandler interface {
  24. Eval(ctx *EvalContext)
  25. }
  26. type scheduler interface {
  27. Tick(time time.Time, execQueue chan *Job)
  28. Update(rules []*Rule)
  29. }
  30. // ConditionResult is the result of a condition evaluation.
  31. type ConditionResult struct {
  32. Firing bool
  33. NoDataFound bool
  34. Operator string
  35. EvalMatches []*monitor.EvalMatch
  36. AlertOkEvalMatches []*monitor.EvalMatch
  37. }
  38. // Condition is responsible for evaluating an alert condition.
  39. type Condition interface {
  40. Eval(result *EvalContext) (*ConditionResult, error)
  41. }
  42. type Notifier interface {
  43. notifydrivers.Notifier
  44. Notify(evalContext *EvalContext, params jsonutils.JSONObject) error
  45. // ShouldNotify checks this evaluation should send an alert notification
  46. ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.SAlertnotification) bool
  47. }