123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package utils
- import (
- "smart-alarm/model"
- "github.com/jaryhe/gopkgs/database"
- )
- /*
- var AlarmRuleMap = map[string]model.TAlarmRule{}
- var ruleMutex sync.Mutex
- // 初始化告警规则
- func InitAlarmRule() {
- rule := &model.TAlarmRule{}
- where := map[string]interface{}{"is_on": true}
- ruleList, err := rule.QueryAll(database.DB(), where)
- if err == nil {
- for k, _ := range ruleList {
- AlarmRuleMap[ruleList[k].Sn] = ruleList[k]
- }
- }
- }
- // 获取告警规则
- func GetAlarmRule(sn string) *model.TAlarmRule {
- ruleMutex.Lock()
- defer ruleMutex.Unlock()
- if value, ok := AlarmRuleMap[sn]; ok {
- return &value
- } else {
- return nil
- }
- }
- // 设置告警规则
- func SetAlarmRule(rule *model.TAlarmRule) {
- ruleMutex.Lock()
- defer ruleMutex.Unlock()
- AlarmRuleMap[rule.Sn] = *rule
- }
- func DeleteAlarmRule(sn string) {
- ruleMutex.Lock()
- defer ruleMutex.Unlock()
- delete(AlarmRuleMap, sn)
- }
- */
- // 获取告警规则
- func GetAlarmRule(projectId int64, sn string) *model.TAlarmRule {
- // TODO 从redis里面获取
- rule := &model.TAlarmRule{}
- filter := map[string]interface{}{"project_id": projectId, "sn": sn, "is_on": true}
- err := rule.Query(database.DB(), filter)
- if err != nil {
- return nil
- }
- return rule
- }
|