diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 85136a94d..460bc390a 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -1,11 +1,16 @@ package debug import ( + "context" + "fmt" + "net" "net/http" + "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" + "github.com/owncloud/ocis/v2/services/antivirus/pkg/scanners" ) // Server initializes the debug service and server. @@ -14,7 +19,33 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger), + WithLogger(options.Logger). + WithCheck("nats reachability", func(ctx context.Context) error { + _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) + if err != nil { + return fmt.Errorf("could not connect to nats server: %v", err) + } + return nil + }). + WithCheck("antivirus reachability", func(ctx context.Context) error { + cfg := options.Config + switch cfg.Scanner.Type { + default: + // there is not av configured, return no error here + return nil + case "clamav": + _, err := net.Dial("tcp", cfg.Scanner.ClamAV.Socket) + if err != nil { + return fmt.Errorf("could not connect to clamav server: %v", err) + } + case "icap": + _, err := scanners.NewICAP(cfg.Scanner.ICAP.URL, cfg.Scanner.ICAP.Service, cfg.Scanner.ICAP.Timeout) + if err != nil { + return fmt.Errorf("could not connect to icap server: %v", err) + } + } + return nil + }), ) return debug.NewService(