123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package models
- import (
- "errors"
- "github.com/jinzhu/gorm"
- )
- // AlarmRule 报警规则
- // 为某个产品增加一个告警规则,平台可以根据设备的实时数据产生一个告警信息,并推送给用户
- // 用来监控设备的状态异常等
- type AlarmRule struct {
- gorm.Model
- RecordId string `gorm:"primary_key;column:record_id;size:32;index"`
- AlertName string `gorm:"size:30;not null"` //规则名称
- ProtocalID string //所属数据点ID
- ProtocalName string //协议名称
- AlertCondition int //对应触发条件的属性编号
- // |1|小于|
- // |2|等于|
- // |3|大于|
- // |4|小于等于|
- // |5|大于等于|
- // |6|不等于|
- AlertValue int //触发对比数值
- AlertContent string `gorm:"size:500;not null"` // 告警内容
- AlertType int // 告警类型:1:设备异常 2:设备警告
- NoticeType int // 通知类型:1:通知型<br>2:告警型
- NoticeWay int //通知方式 1:短信通知<br>2:极光推送<br>3:微信通知<br>
- ProductID string `gorm:"column:product_id;size:32;index"` //关联的产品ID
- VendorID string `gorm:"column:vendor_id;size:32;index"` //关联厂商ID
- StartIndex int //字符串或字节数组的开始位置
- EndIndex int //字符串或字节数组的结束位置
- Status int //状态,1正常,0禁用
- }
- // Validate 验证
- func (a *AlarmRule) Validate() error {
- if a.AlertName == "" ||
- a.AlertCondition == 0 || a.AlertValue == 0 || a.AlertContent == "" ||
- a.AlertType == 0 || a.NoticeType == 0 || a.ProductID == "" {
- return errors.New("非法参数")
- }
- return nil
- }
|