1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2024-11-22 10:25:48 +01:00
rolens/internal/app/host_logs.go
Romein van Buren 24b0df95df
Add ability to see host logs (#54)
Squashed commit of the following:

commit 93b2d67cef
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 20:07:33 2023 +0200

    Add filter functionality

commit 30b65a198f
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 19:27:20 2023 +0200

    Renamed `form-row` class to `formrow`

commit 21afb01ea1
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 19:26:04 2023 +0200

    Hide object types in object grid

commit 037d5432a4
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 19:21:54 2023 +0200

    Make auto reload interval input smaller

commit 49d5022027
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 15:08:00 2023 +0200

    Implement logs autoreload

commit 1f8984766b
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 15:04:00 2023 +0200

    Return on error

commit 9c85259964
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 15:03:37 2023 +0200

    Add log error handling

commit 7a98a63866
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 14:46:39 2023 +0200

    Update log tab icon

commit f30827ae2e
Author: Romein van Buren <romein@vburen.nl>
Date:   Sat Jul 1 14:41:59 2023 +0200

    Add host log panel
2023-07-01 20:30:43 +02:00

47 lines
1008 B
Go

package app
import (
"github.com/wailsapp/wails/v2/pkg/runtime"
"go.mongodb.org/mongo-driver/bson"
)
type HostLogsResult struct {
Total int32 `json:"total"`
Logs []string `json:"logs"`
Error string `json:"error"`
}
func (a *App) HostLogs(hostKey, filter string) (result HostLogsResult) {
client, ctx, close, err := a.connectToHost(hostKey)
if err != nil {
result.Error = "Could not connect to host"
return
}
defer close()
var res bson.M
err = client.Database("admin").RunCommand(ctx, bson.M{"getLog": filter}).Decode(&res)
if err != nil {
runtime.LogWarningf(a.ctx, "Could not get %s logs for %s: %s", filter, hostKey, err.Error())
result.Error = err.Error()
return
}
if res["totalLinesWritten"] != nil {
result.Total = res["totalLinesWritten"].(int32)
} else {
result.Total = 0
}
result.Logs = make([]string, 0)
switch res["log"].(type) {
case bson.A:
for _, v := range res["log"].(bson.A) {
result.Logs = append(result.Logs, v.(string))
}
}
return
}