mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 03:40:01 -06:00
add checks for antivirus
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user