1234567891011121314151617181920212223242526272829303132333435 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package utils
- import "fmt"
- type AlarmStatistics struct {
- Timestamp int64 `json:"timestamp"`
- AlarmCount int32 `json:"alarm_count"`
- IsSend bool `json:"is_send"`
- }
- var AlarmStatisticsMap = map[string]AlarmStatistics{}
- func InitAlarmStatistics() {
- // TODO从redis获取
- AlarmStatisticsMap = make(map[string]AlarmStatistics)
- }
- // 设置告警
- func SetAlarmStatistics(sn string, alarmCode string, statistic *AlarmStatistics) {
- key := fmt.Sprintf("%s-%s", sn, alarmCode)
- AlarmStatisticsMap[key] = *statistic
- }
- //
- func GetAlarmStatistics(sn string, alarmCode string) *AlarmStatistics {
- key := fmt.Sprintf("%s-%s", sn, alarmCode)
- if value, ok := AlarmStatisticsMap[key]; ok {
- return &value
- } else {
- return &AlarmStatistics{}
- }
- }
|