diff --git a/cmd/csaf_downloader/forwarder.go b/cmd/csaf_downloader/forwarder.go index 689f0d5f..6efdfbe2 100644 --- a/cmd/csaf_downloader/forwarder.go +++ b/cmd/csaf_downloader/forwarder.go @@ -50,6 +50,9 @@ type forwarder struct { cfg *config cmds chan func(*forwarder) client util.Client + + failed int + succeeded int } // newForwarder creates a new forwarder. @@ -75,6 +78,15 @@ func (f *forwarder) close() { close(f.cmds) } +// log logs the current statistics. +func (f *forwarder) log() { + f.cmds <- func(f *forwarder) { + slog.Info("Forward statistics", + "succeeded", f.succeeded, + "failed", f.failed) + } +} + // httpClient returns a cached HTTP client used for uploading // the advisories to the configured HTTP endpoint. func (f *forwarder) httpClient() util.Client { @@ -204,6 +216,7 @@ func (f *forwarder) storeFailedAdvisory(filename, doc, sha256, sha512 string) er // storeFailed is a logging wrapper around storeFailedAdvisory. func (f *forwarder) storeFailed(filename, doc, sha256, sha512 string) { + f.failed++ if err := f.storeFailedAdvisory(filename, doc, sha256, sha512); err != nil { slog.Error("Storing advisory failed forwarding failed", "error", err) @@ -248,6 +261,7 @@ func (f *forwarder) forward( "status_code", res.StatusCode) f.storeFailed(filename, doc, sha256, sha512) } else { + f.succeeded++ slog.Debug( "forwarding succeeded", "filename", filename) diff --git a/cmd/csaf_downloader/main.go b/cmd/csaf_downloader/main.go index 8e4b1781..5840791c 100644 --- a/cmd/csaf_downloader/main.go +++ b/cmd/csaf_downloader/main.go @@ -33,7 +33,10 @@ func run(cfg *config, domains []string) error { if cfg.ForwardURL != "" { f := newForwarder(cfg) go f.run() - defer f.close() + defer func() { + f.log() + f.close() + }() d.forwarder = f }