From 24b0df95dfe8d41f8d8304291df390e7966e8ee2 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sat, 1 Jul 2023 20:30:43 +0200 Subject: [PATCH] Add ability to see host logs (#54) Squashed commit of the following: commit 93b2d67cef77d89df728ffbf831e5ce79904673e Author: Romein van Buren Date: Sat Jul 1 20:07:33 2023 +0200 Add filter functionality commit 30b65a198fc8d494fe660babd409e42a85c85d14 Author: Romein van Buren Date: Sat Jul 1 19:27:20 2023 +0200 Renamed `form-row` class to `formrow` commit 21afb01ea191c6d5b597884fae637ae1b8f49a7a Author: Romein van Buren Date: Sat Jul 1 19:26:04 2023 +0200 Hide object types in object grid commit 037d5432a454720ad58f3c201bc60980759cc44f Author: Romein van Buren Date: Sat Jul 1 19:21:54 2023 +0200 Make auto reload interval input smaller commit 49d50220272d87c34cd84678baf01557d4c24051 Author: Romein van Buren Date: Sat Jul 1 15:08:00 2023 +0200 Implement logs autoreload commit 1f8984766bbd8a1f6ce232daa40b8c49bf079d9f Author: Romein van Buren Date: Sat Jul 1 15:04:00 2023 +0200 Return on error commit 9c8525996494f023634ac3ea64370fc2778e717c Author: Romein van Buren Date: Sat Jul 1 15:03:37 2023 +0200 Add log error handling commit 7a98a63866b6fbfe3be5897feddbacf3fafd7dbf Author: Romein van Buren Date: Sat Jul 1 14:46:39 2023 +0200 Update log tab icon commit f30827ae2ec1c6254e0aab451de6763556c90ac5 Author: Romein van Buren Date: Sat Jul 1 14:41:59 2023 +0200 Add host log panel --- frontend/src/components/icon.svelte | 2 + frontend/src/components/modal.svelte | 5 +- frontend/src/components/objecteditor.svelte | 2 + frontend/src/components/objectgrid.svelte | 13 +- frontend/src/components/objectviewer.svelte | 3 +- frontend/src/lib/mongo/index.js | 4 +- frontend/src/lib/mongo/log-components.json | 36 ++++ frontend/src/lib/mongo/loglevels.json | 7 + frontend/src/lib/stores/hosttree.js | 21 +- .../connection/collection/find.svelte | 14 +- .../connection/collection/stats.svelte | 1 + .../connection/database/stats.svelte | 1 + .../organisms/connection/host/index.svelte | 16 +- .../src/organisms/connection/host/logs.svelte | 194 ++++++++++++++++++ .../organisms/connection/host/status.svelte | 1 + .../connection/host/systeminfo.svelte | 1 + frontend/src/styles/style.css | 2 +- frontend/wailsjs/go/app/App.d.ts | 2 + frontend/wailsjs/go/app/App.js | 4 + internal/app/host_logs.go | 46 +++++ 20 files changed, 343 insertions(+), 32 deletions(-) create mode 100644 frontend/src/lib/mongo/log-components.json create mode 100644 frontend/src/lib/mongo/loglevels.json create mode 100644 frontend/src/organisms/connection/host/logs.svelte create mode 100644 internal/app/host_logs.go diff --git a/frontend/src/components/icon.svelte b/frontend/src/components/icon.svelte index 4f9f6d0..645a996 100644 --- a/frontend/src/components/icon.svelte +++ b/frontend/src/components/icon.svelte @@ -147,5 +147,7 @@ {:else if name === 'loading'} + {:else if name === 'doc'} + {/if} diff --git a/frontend/src/components/modal.svelte b/frontend/src/components/modal.svelte index a7c9e7d..e1ae1df 100644 --- a/frontend/src/components/modal.svelte +++ b/frontend/src/components/modal.svelte @@ -5,7 +5,6 @@ + +
+
+ + + +
+ +
+ + + +
+ +
+ +
+ +
+ + + + + {#if total} +
+ Total: {total} +
+ {/if} +
+
+ +{#if objectViewerData} + +{/if} + + + {#each autoReloadIntervals as value} + + + diff --git a/frontend/src/organisms/connection/host/status.svelte b/frontend/src/organisms/connection/host/status.svelte index b63e270..be235ab 100644 --- a/frontend/src/organisms/connection/host/status.svelte +++ b/frontend/src/organisms/connection/host/status.svelte @@ -20,6 +20,7 @@
textarea, .field > select { flex: 1; - padding: 0.5rem; + padding: 0 0.5rem; border: 1px solid #ccc; background-color: #fff; appearance: none; diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index 9e3dd2c..ecd015c 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -24,6 +24,8 @@ export function FindItems(arg1:string,arg2:string,arg3:string,arg4:string):Promi export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise; +export function HostLogs(arg1:string,arg2:string):Promise; + export function Hosts():Promise; export function InsertItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 5552e87..a2548f1 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -38,6 +38,10 @@ export function GetIndexes(arg1, arg2, arg3) { return window['go']['app']['App']['GetIndexes'](arg1, arg2, arg3); } +export function HostLogs(arg1, arg2) { + return window['go']['app']['App']['HostLogs'](arg1, arg2); +} + export function Hosts() { return window['go']['app']['App']['Hosts'](); } diff --git a/internal/app/host_logs.go b/internal/app/host_logs.go new file mode 100644 index 0000000..32073ea --- /dev/null +++ b/internal/app/host_logs.go @@ -0,0 +1,46 @@ +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 +}