alarmrule.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // AlarmRule 报警规则
  7. // 为某个产品增加一个告警规则,平台可以根据设备的实时数据产生一个告警信息,并推送给用户
  8. // 用来监控设备的状态异常等
  9. type AlarmRule struct {
  10. gorm.Model
  11. AlertName string `gorm:"size:30;not null"` //规则名称
  12. ProtocalID int //所属数据点ID
  13. ProtocalName string //协议名称
  14. AlertCondition int //对应触发条件的属性编号
  15. // |1|小于|
  16. // |2|等于|
  17. // |3|大于|
  18. // |4|小于等于|
  19. // |5|大于等于|
  20. // |6|不等于|
  21. AlertValue int //触发对比数值
  22. AlertContent string `gorm:"size:500;not null"` // 告警内容
  23. AlertType int // 告警类型:1:设备异常 2:设备警告
  24. NoticeType int // 通知类型:1:通知型<br>2:告警型
  25. NoticeWay int //通知方式 1:短信通知<br>2:极光推送<br>3:微信通知<br>
  26. ProductID int //关联的产品ID
  27. VendorID uint //关联厂商ID
  28. }
  29. // Validate 验证
  30. func (a *AlarmRule) Validate() error {
  31. if a.AlertName == "" ||
  32. a.AlertCondition == 0 || a.AlertValue == 0 || a.AlertContent == "" ||
  33. a.AlertType == 0 || a.NoticeType == 0 || a.ProductID == 0 {
  34. return errors.New("非法参数")
  35. }
  36. return nil
  37. }