Skip to content

Commit

Permalink
🚀 Add tree node architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Cairry committed Dec 31, 2024
1 parent 0071cf4 commit dc40be0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/vt/alarmNode.go
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
package vt

import "watchAlert/internal/models"

const (
Firing string = "Firing"
Recover = "Recover"
)

// AlarmTreeNode 告警事件节点
type AlarmTreeNode struct {
Value string
Alerts map[string]models.AlertCurEvent
Children map[string]*AlarmTreeNode
}

func NewTreeNode(value string) *AlarmTreeNode {
return &AlarmTreeNode{
Value: value,
Alerts: make(map[string]models.AlertCurEvent),
Children: make(map[string]*AlarmTreeNode),
}
}

func (an *AlarmTreeNode) Set(TName string, Alerts map[string]models.AlertCurEvent) error {
if len(Alerts) == 0 {
return nil
}

exitsAlerts := an.Gets(TName)
for fingerprint, alert := range Alerts {
exitsAlerts[fingerprint] = alert
}

an.Children[TName] = &AlarmTreeNode{
Alerts: exitsAlerts,
}
return nil
}

func (an *AlarmTreeNode) Gets(TName string) map[string]models.AlertCurEvent {
if child, ok := an.Children[TName]; ok {
return child.Alerts
}

return map[string]models.AlertCurEvent{}
}

func (an *AlarmTreeNode) List() *AlarmTreeNode {
return an
}

0 comments on commit dc40be0

Please sign in to comment.