Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 8263e73

Browse files
committed
[agent]App列表根据监控项数据变颜色
1 parent 048da46 commit 8263e73

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

teaweb/actions/default/agents/apps/index.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package apps
22

33
import (
44
"github.com/TeaWeb/code/teaconfigs/agents"
5+
"github.com/TeaWeb/code/teaconfigs/notices"
6+
"github.com/TeaWeb/code/teamongo"
57
"github.com/iwind/TeaGo/actions"
68
"github.com/iwind/TeaGo/lists"
79
"github.com/iwind/TeaGo/maps"
@@ -23,6 +25,26 @@ func (this *IndexAction) Run(params struct {
2325
// 用户自定义App
2426
this.Data["apps"] = lists.Map(agent.Apps, func(k int, v interface{}) interface{} {
2527
app := v.(*agents.AppConfig)
28+
29+
// 最新一条数据
30+
level := notices.NoticeLevelNone
31+
for _, item := range app.Items {
32+
if !item.On {
33+
continue
34+
}
35+
value, err := teamongo.NewAgentValueQuery().
36+
Agent(agent.Id).
37+
App(app.Id).
38+
Item(item.Id).
39+
Desc("_id").
40+
Find()
41+
if err == nil && value != nil {
42+
if value.NoticeLevel == notices.NoticeLevelWarning || value.NoticeLevel == notices.NoticeLevelError && value.NoticeLevel > level {
43+
level = value.NoticeLevel
44+
}
45+
}
46+
}
47+
2648
return maps.Map{
2749
"on": app.On,
2850
"id": app.Id,
@@ -32,6 +54,8 @@ func (this *IndexAction) Run(params struct {
3254
"manualTasks": app.FindManualTasks(),
3355
"schedulingTasks": app.FindSchedulingTasks(),
3456
"isSharedWithGroup": app.IsSharedWithGroup,
57+
"isWarning": level == notices.NoticeLevelWarning,
58+
"isError": level == notices.NoticeLevelError,
3559
}
3660
})
3761

teaweb/actions/default/agents/apps/monitor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ func (this *MonitorAction) RunPost(params struct {
8686
"thresholds": item.Thresholds,
8787
"latestValue": latestValue,
8888
"latestTime": latestTime,
89-
"latestLevel": notices.FindNoticeLevel(latestLevel),
89+
"isWarning": latestLevel == notices.NoticeLevelWarning,
90+
"isError": latestLevel == notices.NoticeLevelError,
9091
}
9192

9293
source := item.Source()

0 commit comments

Comments
 (0)