Skip to content

Commit

Permalink
Health check
Browse files Browse the repository at this point in the history
  • Loading branch information
asmith030 committed May 1, 2020
1 parent 843573f commit fc487a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions charts/clamav/templates/clamav-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ spec:
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
path: /v1alpha/healthz
port: 8080
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 5
failureThreshold: 10
readinessProbe:
httpGet:
path: /healthz
path: /v1alpha/healthz
port: 8080
initialDelaySeconds: 10
timeoutSeconds: 5
Expand Down
4 changes: 4 additions & 0 deletions clamav-http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func RunHTTPListener(clamd_address string, port int, max_file_mem int64, logger
Max_file_mem: max_file_mem,
Logger: logger,
})
m.Handle("/v1alpha/healthz", &v1alpha.HealthHandler{
Address: clamd_address,
Logger: logger,
})
m.Handle("/v1alpha/scan", &v1alpha.ScanHandler{
Address: clamd_address,
Max_file_mem: max_file_mem,
Expand Down
39 changes: 39 additions & 0 deletions clamav-http/server/v1alpha/health_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v1alpha

import (
"net/http"
"strings"

"github.com/dutchcoders/go-clamd"
"github.com/sirupsen/logrus"
)

const eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"

type HealthHandler struct {
Address string
Logger *logrus.Logger
}

func (hh *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c := clamd.NewClamd(hh.Address)
response, err := c.ScanStream(strings.NewReader(eicar), make(chan bool))

if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("not okay"))
}

result := <-response
if result.Status == "FOUND" {
w.WriteHeader(http.StatusOK)
hh.Logger.Info("healthcheck: OK")
w.Write([]byte("healthcheck: OK\n"))
} else {
w.WriteHeader(http.StatusInternalServerError)
hh.Logger.Info("healthcheck: ERROR")
w.Write([]byte("healthcheck: ERROR\n"))
}

return
}

0 comments on commit fc487a9

Please sign in to comment.