Skip to content

Commit

Permalink
frontend: trivial patch
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskaliX committed Oct 27, 2024
1 parent 3b1bd9e commit afdc6fc
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 11 deletions.
5 changes: 5 additions & 0 deletions server/webconsole/api/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package common

var AssetAllowList = []string{
"plugins", "users", "sockets", "processes", "crons", "apps", "kmods", "iptables", "net_interfaces", "containers",
}
20 changes: 20 additions & 0 deletions server/webconsole/api/grpc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"hboat/api/common"
"hboat/grpc/handler"
"hboat/pkg/basic/mongo"
"hboat/pkg/conf"
"time"
Expand Down Expand Up @@ -50,6 +51,7 @@ type ConnStatRsp struct {
AgentInfo map[string]interface{} `json:"agent_info"`
PluginsInfo []map[string]interface{} `json:"plugins_info"`
Tags []string `json:"tags"`
AppOverview map[string]int64 `json:"app_overview"`
}

func AgentStat(c *gin.Context) {
Expand Down Expand Up @@ -79,10 +81,14 @@ func AgentStat(c *gin.Context) {
pluginList = append(pluginList, as.PluginDetail[k])
}

// app overview
overview, _ := handleAppOverview(agentid)

res := ConnStatRsp{
AgentInfo: agentInfo,
PluginsInfo: pluginList,
Tags: as.Tags,
AppOverview: overview,
}

common.Response(c, common.SuccessCode, res)
Expand Down Expand Up @@ -163,3 +169,17 @@ func AgentClear(c *gin.Context) {
fmt.Printf("Deleted %d documents\n", deleteResult.DeletedCount)
common.Response(c, common.SuccessCode, deleteResult.DeletedCount)
}


func handleAppOverview(agent_id string) (map[string]int64, error) {
var pageReq common.PageReq
res := map[string]int64{}
for _, t := range common.AssetAllowList {
respCommon, err := common.DBPageSearch(context.TODO(), mongo.MongoProxyImpl.AssetC, &pageReq, bson.M{"agent_id": agent_id, "data_type": handler.EventNameCache[t].ID()})
if err != nil {
continue
}
res[t] = respCommon.Total
}
return res, nil
}
6 changes: 1 addition & 5 deletions server/webconsole/api/host/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
"go.mongodb.org/mongo-driver/bson"
)

var typeAllowlist = []string{
"plugins", "users", "sockets", "processes", "crons", "apps", "kmods", "iptables", "net_interfaces", "containers",
}

// agentAssetResp represents the response structure for agent assets
type agentAssetResp struct {
Total int32 `json:"total"`
Expand Down Expand Up @@ -80,7 +76,7 @@ func bindRequests(c *gin.Context, pageReq *common.PageReq, assetReq *agentAssetR

// validateAssetType checks if the provided asset type is allowed
func validateAssetType(assetType string) error {
if !slices.Contains(typeAllowlist, assetType) {
if !slices.Contains(common.AssetAllowList, assetType) {
return fmt.Errorf("type %s is not supported", assetType)
}
if _, ok := handler.EventNameCache[assetType]; !ok {
Expand Down
4 changes: 2 additions & 2 deletions server/webconsole/api/static/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<title>Hades</title>
<link rel="stylesheet" href="/umi.46830b22.css">
<script async src="/scripts/loading.js"></script>
<script src="/preload_helper.2295b86c.js"></script>
<script src="/preload_helper.cb40182c.js"></script>
</head>
<body>
<div id="root"></div>
<script src="/umi.f0312187.js"></script>
<script src="/umi.3ed3b2d3.js"></script>
</body>
</html>

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit afdc6fc

Please sign in to comment.