-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |