* Reformat Log Output for SysAdmin UI

* Restore old code

* Update

* Backend first pass

* PR feedback

* Set helpers to private

* Lint fix

* Fix mocks

* Fix another mock

* Fix lint again

* Fix i18n

* Update app/admin.go

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

* PR feedback

* FIx lint issue

---------

Co-authored-by: Daniel Schalla <daniel@schalla.me>
Co-authored-by: Nevyana Angelova <nevyangelova@Nevyanas-MacBook-Pro.local>
Co-authored-by: Devin Binnie <devin.binnie@mattermost.com>
Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
na
2023-02-14 12:39:10 +02:00
коммит произвёл GitHub
родитель 5a075e01a5
Коммит 7275887d14
12 изменённых файлов: 268 добавлений и 24 удалений

Просмотреть файл

@@ -48,6 +48,7 @@ func (api *API) InitSystem() {
api.BaseRoutes.APIRoot.Handle("/caches/invalidate", api.APISessionRequired(invalidateCaches)).Methods("POST")
api.BaseRoutes.APIRoot.Handle("/logs", api.APISessionRequired(getLogs)).Methods("GET")
api.BaseRoutes.APIRoot.Handle("/logs/query", api.APISessionRequired(queryLogs)).Methods("POST")
api.BaseRoutes.APIRoot.Handle("/logs", api.APIHandler(postLog)).Methods("POST")
api.BaseRoutes.APIRoot.Handle("/analytics/old", api.APISessionRequired(getAnalytics)).Methods("GET")
@@ -326,6 +327,52 @@ func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}
func queryLogs(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("queryLogs", audit.Fail)
defer c.LogAuditRec(auditRec)
if *c.App.Config().ExperimentalSettings.RestrictSystemAdmin {
c.Err = model.NewAppError("queryLogs", "api.restricted_system_admin", nil, "", http.StatusForbidden)
return
}
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionGetLogs) {
c.SetPermissionError(model.PermissionGetLogs)
return
}
var logFilter *model.LogFilter
err := json.NewDecoder(r.Body).Decode(&logFilter)
if err != nil {
c.Err = model.NewAppError("queryLogs", "api.system.logs.invalidFilter", nil, "", http.StatusInternalServerError)
return
}
logs, logerr := c.App.QueryLogs(c.Params.Page, c.Params.LogsPerPage, logFilter)
if logerr != nil {
c.Err = logerr
return
}
logsJSON := make(map[string][]interface{})
var result interface{}
for node, logLines := range logs {
for _, log := range logLines {
err2 := json.Unmarshal([]byte(log), &result)
if err2 == nil {
logsJSON[node] = append(logsJSON[node], result)
} else {
mlog.Warn("Error parsing log line in Server Logs")
}
}
}
auditRec.AddMeta("page", c.Params.Page)
auditRec.AddMeta("logs_per_page", c.Params.LogsPerPage)
w.Write(model.ToJSON(logsJSON))
}
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec := c.MakeAuditRecord("getLogs", audit.Fail)
defer c.LogAuditRec(auditRec)