trace
This commit is contained in:
@@ -2,6 +2,7 @@ package trace
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -23,7 +24,7 @@ var (
|
||||
UriTraceTaskV1 = config.DefaultUriPrefix + "/traceManagement/v1/subscriptions"
|
||||
UriTraceTask = config.DefaultUriPrefix + "/traceManagement/{apiVersion}/subscriptions"
|
||||
UriTraceRawMsg = config.DefaultUriPrefix + "/traceManagement/{apiVersion}/rawMessage/{id}"
|
||||
UriTraceDecMsg = config.DefaultUriPrefix + "/traceManagement/{apiVersion}/decMessage/{id}"
|
||||
UriTraceDecMsg = config.DefaultUriPrefix + "/traceManagement/{apiVersion}/decMessage/{id}" // decode message api
|
||||
|
||||
CustomUriTraceTaskV1 = config.UriPrefix + "/traceManagement/v1/subscriptions"
|
||||
CustomUriTraceTask = config.UriPrefix + "/traceManagement/{apiVersion}/subscriptions"
|
||||
@@ -399,11 +400,11 @@ func ParseRawMsg2Html(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
log.Trace("traceData:", traceData)
|
||||
pathFile := traceData.DecMsg
|
||||
filePath := traceData.DecMsg
|
||||
if traceData.DecMsg == "" {
|
||||
htmlFile := fmt.Sprintf("traceDecMessage-%d-%d.html", traceData.TaskID, traceData.ID)
|
||||
pathFile = config.GetYamlConfig().OMC.FrontTraceDir + "/" + htmlFile
|
||||
command := fmt.Sprintf("ipdata2html -f %s -t %d -i N%d -d %x", pathFile, traceData.Timestamp, traceData.IfType, traceData.RawMsg)
|
||||
filePath = config.GetYamlConfig().OMC.FrontTraceDir + "/" + htmlFile
|
||||
command := fmt.Sprintf("ipdata2html -f %s -t %d -i N%d -d %x", filePath, traceData.Timestamp, traceData.IfType, traceData.RawMsg)
|
||||
out, err := run.ExecCmd(command, "/")
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
@@ -411,7 +412,18 @@ func ParseRawMsg2Html(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
traceData.DecMsg = pathFile
|
||||
exist, err := global.FilePathExists(filePath)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to stat:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
if !exist {
|
||||
err = errors.New(string(out))
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
traceData.DecMsg = filePath
|
||||
_, err = dborm.XormUpdateTraceData(id, traceData)
|
||||
if err != nil {
|
||||
log.Errorf("Faile to XormUpdateTraceData:", err)
|
||||
@@ -419,5 +431,5 @@ func ParseRawMsg2Html(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
services.ResponseHtmlContent(w, http.StatusOK, pathFile)
|
||||
services.ResponseHtmlContent(w, http.StatusOK, filePath)
|
||||
}
|
||||
|
||||
@@ -354,6 +354,18 @@ func PathExists(path string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// PathExists check path is exist or no
|
||||
func FilePathExists(filePath string) (bool, error) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err == nil { //文件或者目录存在
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
func GetDayDuration(d1, d2 string) int64 {
|
||||
a, _ := time.Parse("2006-01-02", d1)
|
||||
b, _ := time.Parse("2006-01-02", d2)
|
||||
|
||||
Reference in New Issue
Block a user