alarm_statistics.go 853 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package utils
  4. import "fmt"
  5. type AlarmStatistics struct {
  6. Timestamp int64 `json:"timestamp"`
  7. AlarmCount int32 `json:"alarm_count"`
  8. IsSend bool `json:"is_send"`
  9. }
  10. var AlarmStatisticsMap = map[string]AlarmStatistics{}
  11. func InitAlarmStatistics() {
  12. // TODO从redis获取
  13. AlarmStatisticsMap = make(map[string]AlarmStatistics)
  14. }
  15. // 设置告警
  16. func SetAlarmStatistics(sn string, alarmCode string, statistic *AlarmStatistics) {
  17. key := fmt.Sprintf("%s-%s", sn, alarmCode)
  18. AlarmStatisticsMap[key] = *statistic
  19. }
  20. //
  21. func GetAlarmStatistics(sn string, alarmCode string) *AlarmStatistics {
  22. key := fmt.Sprintf("%s-%s", sn, alarmCode)
  23. if value, ok := AlarmStatisticsMap[key]; ok {
  24. return &value
  25. } else {
  26. return &AlarmStatistics{}
  27. }
  28. }