exporter new api, get event log by eventID

This commit is contained in:
凡羊羊 2019-08-22 19:51:46 +08:00
parent abe522b0a5
commit f30b520ada
4 changed files with 27 additions and 10 deletions

View File

@ -19,6 +19,7 @@
package controller
import (
"bufio"
"encoding/json"
"io/ioutil"
"net/http"
@ -296,12 +297,21 @@ func (e *EventLogStruct) EventLogByEventID(w http.ResponseWriter, r *http.Reques
httputil.ReturnError(r, w, 400, "eventID is request")
return
}
ses, err := handler.GetEventHandler().GetEventLog(eventID)
file, err := handler.GetEventHandler().GetEventLog(eventID)
if err != nil {
logrus.Errorf("get event log error, %v", err)
httputil.ReturnError(r, w, 500, "get log error")
return
}
httputil.ReturnSuccess(r, w, ses)
reader := bufio.NewReader(file)
bs, err := ioutil.ReadAll(reader)
if err != nil {
logrus.Errorf("get event log error, %v", err)
httputil.ReturnError(r, w, 500, "read event log file error: "+err.Error())
return
}
httputil.ReturnSuccess(r, w, string(bs))
return
}

View File

@ -19,6 +19,8 @@
package handler
import (
"os"
api_model "github.com/goodrain/rainbond/api/model"
)
@ -30,5 +32,5 @@ type EventHandler interface {
GetLevelLog(eventID string, level string) (*api_model.DataLog, error)
GetLogFile(serviceAlias, fileName string) (string, string, error)
GetTargetEvents(target, targetID string) (api_model.EventsList, error)
GetEventLog(eventID string) (string, error)
GetEventLog(eventID string) (*os.File, error)
}

View File

@ -71,10 +71,10 @@ func (l *LogAction) GetTargetEvents(target, targetID string) (api_model.EventsLi
}
// GetEventLog get target logs
func (l *LogAction) GetEventLog(eventID string) (string, error) {
func (l *LogAction) GetEventLog(eventID string) (*os.File, error) {
result, err := db.GetManager().ServiceEventDao().GetEventByEventID(eventID)
if err != nil {
return "", err
return nil, err
}
if result != nil {
downLoadDIR := "/grdata/downloads/log/eventlog"
@ -82,11 +82,16 @@ func (l *LogAction) GetEventLog(eventID string) (string, error) {
_, err := os.Stat(fullPath)
fmt.Println(err)
if os.IsNotExist(err) {
return "", err
return nil, err
}
return fullPath, nil
file, err := os.OpenFile(fullPath, os.O_RDONLY, 0644)
if err != nil {
return nil, err
}
return "", nil
return file, nil
}
return nil, fmt.Errorf("do not ound event log file by eventID")
}
//GetLogList get log list

View File

@ -28,10 +28,10 @@ type ServiceEvent struct {
ServiceID string `gorm:"column:service_id;size:40"`
Target string `gorm:"column:target;size:40"`
TargetID string `gorm:"column:target_id;size:40"`
RequestBody string `gorm:"column:request_body;255"`
RequestBody string `gorm:"column:request_body;1024"`
UserName string `gorm:"column:user_name;size:40"`
StartTime string `gorm:"column:start_time;size:40"`
EndTime string `gorm:"column:end_time;size:1024"`
EndTime string `gorm:"column:end_time;size:40"`
OptType string `gorm:"column:opt_type;size:40"`
SynType int `gorm:"column:syn_type;size:1"`
Status string `gorm:"column:status;size:40"`