mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
@@ -5,6 +5,7 @@ package alarms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/internal/atom"
|
||||
"github.com/absmach/magistrala/pkg/authn"
|
||||
@@ -71,8 +72,26 @@ func alarmProjection(a Alarm) atom.Resource {
|
||||
res.Attributes["rule_id"] = a.RuleID
|
||||
res.Attributes["channel_id"] = a.ChannelID
|
||||
res.Attributes["client_id"] = a.ClientID
|
||||
res.Attributes["subtopic"] = a.Subtopic
|
||||
res.Attributes["severity"] = a.Severity
|
||||
res.Attributes["measurement"] = a.Measurement
|
||||
res.Attributes["value"] = a.Value
|
||||
res.Attributes["unit"] = a.Unit
|
||||
res.Attributes["threshold"] = a.Threshold
|
||||
res.Attributes["cause"] = a.Cause
|
||||
res.Attributes["assignee_id"] = a.AssigneeID
|
||||
res.Attributes["assigned_at"] = alarmTimeString(a.AssignedAt)
|
||||
res.Attributes["assigned_by"] = a.AssignedBy
|
||||
res.Attributes["acknowledged_at"] = alarmTimeString(a.AcknowledgedAt)
|
||||
res.Attributes["acknowledged_by"] = a.AcknowledgedBy
|
||||
res.Attributes["resolved_at"] = alarmTimeString(a.ResolvedAt)
|
||||
res.Attributes["resolved_by"] = a.ResolvedBy
|
||||
return res
|
||||
}
|
||||
|
||||
func alarmTimeString(ts time.Time) string {
|
||||
if ts.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return ts.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ func TestAtomServiceCreateAlarmProjectsCreatedAlarm(t *testing.T) {
|
||||
ClientID: "client-1",
|
||||
Cause: "high temperature",
|
||||
Measurement: "temperature",
|
||||
Value: "92.4",
|
||||
Unit: "C",
|
||||
Threshold: "80",
|
||||
Severity: 90,
|
||||
Status: ActiveStatus,
|
||||
},
|
||||
@@ -40,6 +43,9 @@ func TestAtomServiceCreateAlarmProjectsCreatedAlarm(t *testing.T) {
|
||||
if projector.resource.Attributes["rule_id"] != "rule-1" {
|
||||
t.Fatalf("missing rule projection: %#v", projector.resource.Attributes)
|
||||
}
|
||||
if projector.resource.Attributes["value"] != "92.4" || projector.resource.Attributes["threshold"] != "80" {
|
||||
t.Fatalf("missing alarm value projection: %#v", projector.resource.Attributes)
|
||||
}
|
||||
}
|
||||
|
||||
type alarmService struct {
|
||||
|
||||
Reference in New Issue
Block a user