diff options
Diffstat (limited to 'api')
| -rw-r--r-- | api/api.go | 4 | ||||
| -rw-r--r-- | api/docker.go | 23 |
2 files changed, 25 insertions, 2 deletions
@@ -52,7 +52,7 @@ func respondOnline(w http.ResponseWriter, status ServerStatus) { } func VttOnline(w http.ResponseWriter, req *http.Request) { - status := remoteOnline(req.Context(), VTT_URL) + status := vttStatus(req.Context()) if !status.Online { Logger.DebugContext(req.Context(), "Foundry VTT is offline") @@ -89,7 +89,7 @@ func VttLogs(w http.ResponseWriter, req *http.Request) { if _, err = stdcopy.StdCopy(w, w, logReader); err != nil { Logger.Error("Error occured while writting logs to response", slog.Any("err", err), slog.Any("request", req)) http.Error(w, "Error occured while writting logs", http.StatusInternalServerError) - return + return } } diff --git a/api/docker.go b/api/docker.go index 5640b67..248880e 100644 --- a/api/docker.go +++ b/api/docker.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log/slog" + "time" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" @@ -56,3 +57,25 @@ func vttLogs(ctx context.Context, lines uint) (io.ReadCloser, error) { return r, nil } + +func vttStatus(ctx context.Context) ServerStatus { + status := ServerStatus{} + status.Site = VTT_URL + status.Timestamp = time.Now() + + apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + Logger.ErrorContext(ctx, "Failed to get docker api client", slog.Any("err", err)) + return status + } + + json, err := apiClient.ContainerInspect(ctx, vttContainerId) + if err != nil { + Logger.ErrorContext(ctx, "Error occured while geting foundry container stats", slog.Any("err", err)) + return status + } + + status.Online = json.State.Running + + return status +} |
