alarmrule.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. RecordId string `gorm:"primary_key;column:record_id;size:32;index"`
  12. AlertName string `gorm:"size:30;not null"` //规则名称
  13. ProtocalID string //所属数据点ID
  14. ProtocalName string //协议名称
  15. AlertCondition int //对应触发条件的属性编号
  16. // |1|小于|
  17. // |2|等于|
  18. // |3|大于|
  19. // |4|小于等于|
  20. // |5|大于等于|
  21. // |6|不等于|
  22. AlertValue int //触发对比数值
  23. AlertContent string `gorm:"size:500;not null"` // 告警内容
  24. AlertType int // 告警类型:1:设备异常 2:设备警告
  25. NoticeType int // 通知类型:1:通知型<br>2:告警型
  26. NoticeWay int //通知方式 1:短信通知<br>2:极光推送<br>3:微信通知<br>
  27. ProductID string `gorm:"column:product_id;size:32;index"` //关联的产品ID
  28. VendorID string `gorm:"column:vendor_id;size:32;index"` //关联厂商ID
  29. StartIndex int //字符串或字节数组的开始位置
  30. EndIndex int //字符串或字节数组的结束位置
  31. Status int //状态,1正常,0禁用
  32. }
  33. // Validate 验证
  34. func (a *AlarmRule) Validate() error {
  35. if a.AlertName == "" ||
  36. a.AlertCondition == 0 || a.AlertValue == 0 || a.AlertContent == "" ||
  37. a.AlertType == 0 || a.NoticeType == 0 || a.ProductID == "" {
  38. return errors.New("非法参数")
  39. }
  40. return nil
  41. }