mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-25 10:26:35 +00:00
fix: misc logging improvements
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
v1 "github.com/garethgeorge/backrest/gen/go/v1"
|
||||
"github.com/garethgeorge/backrest/internal/hook/hookutil"
|
||||
"github.com/garethgeorge/backrest/internal/orchestrator/tasks"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type discordHandler struct{}
|
||||
@@ -24,9 +25,9 @@ func (discordHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
return fmt.Errorf("template rendering: %w", err)
|
||||
}
|
||||
|
||||
writer := runner.RawLogWriter(ctx)
|
||||
fmt.Fprintf(writer, "Sending discord message to %s\n", h.GetActionDiscord().GetWebhookUrl())
|
||||
fmt.Fprintf(writer, "---- payload ----\n%s\n", payload)
|
||||
l := runner.Logger(ctx)
|
||||
l.Sugar().Infof("Sending discord message to %s", h.GetActionDiscord().GetWebhookUrl())
|
||||
l.Debug("Sending discord message", zap.String("payload", payload))
|
||||
|
||||
type Message struct {
|
||||
Content string `json:"content"`
|
||||
@@ -37,8 +38,12 @@ func (discordHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
}
|
||||
|
||||
requestBytes, _ := json.Marshal(request)
|
||||
_, err = hookutil.PostRequest(h.GetActionDiscord().GetWebhookUrl(), "application/json", bytes.NewReader(requestBytes))
|
||||
return err
|
||||
body, err := hookutil.PostRequest(h.GetActionDiscord().GetWebhookUrl(), "application/json", bytes.NewReader(requestBytes))
|
||||
if err != nil {
|
||||
return fmt.Errorf("sending discord message to %q: %w", h.GetActionDiscord().GetWebhookUrl(), err)
|
||||
}
|
||||
zap.S().Debug("Discord response", zap.String("body", body))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (discordHandler) ActionType() reflect.Type {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
v1 "github.com/garethgeorge/backrest/gen/go/v1"
|
||||
"github.com/garethgeorge/backrest/internal/hook/hookutil"
|
||||
"github.com/garethgeorge/backrest/internal/orchestrator/tasks"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type gotifyHandler struct{}
|
||||
@@ -33,7 +34,7 @@ func (gotifyHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
return fmt.Errorf("title template rendering: %w", err)
|
||||
}
|
||||
|
||||
output := runner.RawLogWriter(ctx)
|
||||
l := runner.Logger(ctx)
|
||||
|
||||
message := struct {
|
||||
Message string `json:"message"`
|
||||
@@ -45,6 +46,9 @@ func (gotifyHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
Message: payload,
|
||||
}
|
||||
|
||||
l.Sugar().Infof("Sending gotify message to %s", g.GetBaseUrl())
|
||||
l.Debug("Sending gotify message", zap.Any("message", message))
|
||||
|
||||
b, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return fmt.Errorf("json marshal: %w", err)
|
||||
@@ -57,19 +61,13 @@ func (gotifyHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
baseUrl,
|
||||
url.QueryEscape(g.GetToken()))
|
||||
|
||||
fmt.Fprintf(output, "Sending gotify message to %s\n", postUrl)
|
||||
fmt.Fprintf(output, "---- payload ----\n")
|
||||
output.Write(b)
|
||||
|
||||
body, err := hookutil.PostRequest(postUrl, "application/json", bytes.NewReader(b))
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("send gotify message: %w", err)
|
||||
}
|
||||
|
||||
if body != "" {
|
||||
output.Write([]byte(body))
|
||||
}
|
||||
l.Sugar().Debugf("Gotify response: %s", body)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
v1 "github.com/garethgeorge/backrest/gen/go/v1"
|
||||
"github.com/garethgeorge/backrest/internal/hook/hookutil"
|
||||
"github.com/garethgeorge/backrest/internal/orchestrator/tasks"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type shoutrrrHandler struct{}
|
||||
@@ -23,9 +24,10 @@ func (shoutrrrHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{}
|
||||
return fmt.Errorf("template rendering: %w", err)
|
||||
}
|
||||
|
||||
writer := runner.RawLogWriter(ctx)
|
||||
fmt.Fprintf(writer, "Sending shoutrrr message to %s\n", h.GetActionShoutrrr().GetShoutrrrUrl())
|
||||
fmt.Fprintf(writer, "---- payload ----\n%s\n", payload)
|
||||
l := runner.Logger(ctx)
|
||||
|
||||
l.Sugar().Infof("Sending shoutrrr message to %s", h.GetActionShoutrrr().GetShoutrrrUrl())
|
||||
l.Debug("Sending shoutrrr message", zap.String("payload", payload))
|
||||
|
||||
if err := shoutrrr.Send(h.GetActionShoutrrr().GetShoutrrrUrl(), payload); err != nil {
|
||||
return fmt.Errorf("sending shoutrrr message to %q: %w", h.GetActionShoutrrr().GetShoutrrrUrl(), err)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
v1 "github.com/garethgeorge/backrest/gen/go/v1"
|
||||
"github.com/garethgeorge/backrest/internal/hook/hookutil"
|
||||
"github.com/garethgeorge/backrest/internal/orchestrator/tasks"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type slackHandler struct{}
|
||||
@@ -24,9 +25,9 @@ func (slackHandler) Execute(ctx context.Context, cmd *v1.Hook, vars interface{},
|
||||
return fmt.Errorf("template rendering: %w", err)
|
||||
}
|
||||
|
||||
writer := runner.RawLogWriter(ctx)
|
||||
fmt.Fprintf(writer, "Sending slack message to %s\n", cmd.GetActionSlack().GetWebhookUrl())
|
||||
fmt.Fprintf(writer, "---- payload ----\n%s\n", payload)
|
||||
l := runner.Logger(ctx)
|
||||
l.Sugar().Infof("Sending slack message to %s", cmd.GetActionSlack().GetWebhookUrl())
|
||||
l.Debug("Sending slack message", zap.String("payload", payload))
|
||||
|
||||
type Message struct {
|
||||
Text string `json:"text"`
|
||||
@@ -38,8 +39,13 @@ func (slackHandler) Execute(ctx context.Context, cmd *v1.Hook, vars interface{},
|
||||
|
||||
requestBytes, _ := json.Marshal(request)
|
||||
|
||||
_, err = hookutil.PostRequest(cmd.GetActionSlack().GetWebhookUrl(), "application/json", bytes.NewReader(requestBytes))
|
||||
return err
|
||||
body, err := hookutil.PostRequest(cmd.GetActionSlack().GetWebhookUrl(), "application/json", bytes.NewReader(requestBytes))
|
||||
if err != nil {
|
||||
return fmt.Errorf("sending slack message to %q: %w", cmd.GetActionSlack().GetWebhookUrl(), err)
|
||||
}
|
||||
|
||||
l.Debug("Slack response", zap.String("body", body))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (slackHandler) ActionType() reflect.Type {
|
||||
|
||||
Reference in New Issue
Block a user