[ Cmii ] [ Octopus ] - reformat agent-go - 2
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package a_status
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
"wdd.io/agent-common/logger"
|
||||
"wdd.io/agent-common/utils"
|
||||
"wdd.io/agent-go/g"
|
||||
"wdd.io/agent-go/rabbitmq"
|
||||
)
|
||||
|
||||
var log = logger.Log
|
||||
@@ -41,46 +45,53 @@ type AgentInfo struct {
|
||||
|
||||
func Activate() {
|
||||
log.Info("Module [ STATUS ] activated !")
|
||||
//v, ok := (octopusMessage.Content).(string)
|
||||
//if !ok {
|
||||
// log.ErrorF("convert to string is wrong %s", v)
|
||||
//}
|
||||
//
|
||||
//statusMsgString := octopusMessage.Content.(string)
|
||||
//
|
||||
//var statusMessage *a_status.StatusMessage
|
||||
//err := json.Unmarshal([]byte(statusMsgString), &statusMessage)
|
||||
//if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
// log.Error(fmt.Sprintf("status message convert to json is wrong! msg is => %s", octopusMessage))
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// OMessageStatusTypeEnum
|
||||
//var statusRes string
|
||||
//if strings.HasPrefix(statusMessage.StatusType, "PING") {
|
||||
// // ping info
|
||||
// statusRes = a_status.Ping()
|
||||
//} else if strings.HasPrefix(statusMessage.StatusType, "METRIC") {
|
||||
// // metric info
|
||||
// agentStatusString, _ := json.Marshal(a_status.ReportAgentMetric())
|
||||
// statusRes = string(agentStatusString)
|
||||
//} else if strings.HasPrefix(statusMessage.StatusType, "INFO") {
|
||||
// log.InfoF("[statusOMHandler] - call for agent info !")
|
||||
//} else {
|
||||
// log.WarnF("[statusOMHandler] - error octopus status message type of %s", statusMessage.StatusType)
|
||||
//}
|
||||
//
|
||||
//// 返回消息
|
||||
//// 组装消息
|
||||
//octopusMessage.ACTime = utils.ParseDateTimeTime()
|
||||
//octopusMessage.Result = statusRes
|
||||
//// 发送回去
|
||||
//statusOctopusReplayMessage, _ := json.Marshal(octopusMessage)
|
||||
//OctopusToServerQueue.Send(statusOctopusReplayMessage)
|
||||
//
|
||||
//// 输出日志
|
||||
//log.InfoF("接收到查询Agent状态的请求,结果为 => %s", statusRes)
|
||||
|
||||
// 死循环获取channel中的数据
|
||||
for {
|
||||
if octopusMessage, ok := <-rabbitmq.BusinessRuntimeQueue.ReceiveChan.ExecutorRChan; ok {
|
||||
// 处理数据
|
||||
|
||||
statusMsgString := octopusMessage.Content.(string)
|
||||
|
||||
var statusMessage *StatusMessage
|
||||
err := json.Unmarshal([]byte(statusMsgString), &statusMessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
log.Error(fmt.Sprintf("status message convert to json is wrong! msg is => %s", octopusMessage))
|
||||
return
|
||||
}
|
||||
|
||||
// OMessageStatusTypeEnum
|
||||
var statusRes string
|
||||
if strings.HasPrefix(statusMessage.StatusType, "PING") {
|
||||
// ping info
|
||||
statusRes = Ping()
|
||||
} else if strings.HasPrefix(statusMessage.StatusType, "METRIC") {
|
||||
// metric info
|
||||
agentStatusString, _ := json.Marshal(ReportAgentMetric())
|
||||
statusRes = string(agentStatusString)
|
||||
} else if strings.HasPrefix(statusMessage.StatusType, "INFO") {
|
||||
log.InfoF("[statusOMHandler] - call for agent info !")
|
||||
} else {
|
||||
log.WarnF("[statusOMHandler] - error octopus status message type of %s", statusMessage.StatusType)
|
||||
}
|
||||
|
||||
// 返回消息
|
||||
// 组装消息
|
||||
octopusMessage.ACTime = utils.ParseDateTimeTime()
|
||||
octopusMessage.Result = statusRes
|
||||
// 发送回去
|
||||
octopusMessage.SendToOctopusServer()
|
||||
|
||||
// 输出日志
|
||||
log.InfoF("接收到查询Agent状态的请求,结果为 => %s", statusRes)
|
||||
} else {
|
||||
// channel已关闭,跳出循环
|
||||
log.ErrorF("business queue [ STATUS ] receive chan has closed !")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Ping() string {
|
||||
|
||||
Reference in New Issue
Block a user