feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -9,8 +9,8 @@ import (
"be.ems/src/framework/config"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
neService "be.ems/src/modules/network_element/service"
wsModel "be.ems/src/modules/ws/model"
)
@@ -137,8 +137,8 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
// 必传requestId确认消息
if reqMsg.RequestID == "" {
msg := "message requestId is required"
logger.Infof("ws IPerf Run UID %s err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(result.ErrMsg(msg))
logger.Infof("ws IPerf Run UID %d err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
client.MsgChan <- msgByte
return
}
@@ -149,7 +149,7 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
switch reqMsg.Type {
case "close":
// 主动关闭
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
client.MsgChan <- resultByte
// 等待1s后关闭连接
time.Sleep(1 * time.Second)
@@ -184,8 +184,8 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
}
if err != nil {
logger.Warnf("ws IPerf Run UID %s err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
logger.Warnf("ws IPerf Run UID %d err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
client.MsgChan <- msgByte
if err == io.EOF {
// 等待1s后关闭连接

View File

@@ -8,8 +8,8 @@ import (
"time"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
neService "be.ems/src/modules/network_element/service"
"be.ems/src/modules/tool/model"
wsModel "be.ems/src/modules/ws/model"
@@ -47,8 +47,8 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
// 必传requestId确认消息
if reqMsg.RequestID == "" {
msg := "message requestId is required"
logger.Infof("ws Commont UID %s err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(result.ErrMsg(msg))
logger.Infof("ws Commont UID %d err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
client.MsgChan <- msgByte
return
}
@@ -59,7 +59,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
switch reqMsg.Type {
case "close":
// 主动关闭
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
client.MsgChan <- resultByte
// 等待1s后关闭连接
time.Sleep(1 * time.Second)
@@ -81,7 +81,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
// 接收的数据包
pinger.OnRecv = func(pkt *probing.Packet) {
resultByte, _ := json.Marshal(result.Ok(map[string]any{
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
"requestId": reqMsg.RequestID,
"data": fmt.Sprintf("%d bytes from %s: icmp_seq=%d time=%v\\r\\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt),
}))
@@ -89,7 +89,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
}
// 已接收过的数据包
pinger.OnDuplicateRecv = func(pkt *probing.Packet) {
resultByte, _ := json.Marshal(result.Ok(map[string]any{
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
"requestId": reqMsg.RequestID,
"data": fmt.Sprintf("%d bytes from %s: icmp_seq=%d time=%v ttl=%v (DUP!)\\r\\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt, pkt.TTL),
}))
@@ -100,13 +100,13 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
end1 := fmt.Sprintf("\\r\\n--- %s ping statistics ---\\r\\n", stats.Addr)
end2 := fmt.Sprintf("%d packets transmitted, %d packets received, %v%% packet loss\\r\\n", stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
end3 := fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\\r\\n", stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
resultByte, _ := json.Marshal(result.Ok(map[string]any{
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
"requestId": reqMsg.RequestID,
"data": fmt.Sprintf("%s%s%s", end1, end2, end3),
}))
client.MsgChan <- resultByte
}
resultByte, _ := json.Marshal(result.Ok(map[string]any{
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
"requestId": reqMsg.RequestID,
"data": fmt.Sprintf("PING %s (%s) %d bytes of data.\\r\\n", pinger.Addr(), pinger.IPAddr(), pinger.Size),
}))
@@ -120,8 +120,8 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
}
if err != nil {
logger.Warnf("ws ping run UID %s err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
logger.Warnf("ws ping run UID %d err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
client.MsgChan <- msgByte
if err == io.EOF {
// 等待1s后关闭连接
@@ -150,8 +150,8 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
// 必传requestId确认消息
if reqMsg.RequestID == "" {
msg := "message requestId is required"
logger.Infof("ws ping run UID %s err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(result.ErrMsg(msg))
logger.Infof("ws ping run UID %d err: %s", client.BindUid, msg)
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
client.MsgChan <- msgByte
return
}
@@ -162,7 +162,7 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
switch reqMsg.Type {
case "close":
// 主动关闭
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
client.MsgChan <- resultByte
// 等待1s后关闭连接
time.Sleep(1 * time.Second)
@@ -197,8 +197,8 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
}
if err != nil {
logger.Warnf("ws ping run UID %s err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
logger.Warnf("ws ping run UID %d err: %s", client.BindUid, err.Error())
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
client.MsgChan <- msgByte
if err == io.EOF {
// 等待1s后关闭连接