Add OVAL HTTP health check

This commit is contained in:
Kota Kanbe
2017-06-16 16:40:33 +09:00
committed by kota kanbe
parent f7aa85746d
commit c442a433b0
7 changed files with 100 additions and 54 deletions

View File

@@ -17,9 +17,40 @@ import (
// Client is the interface of OVAL client.
type Client interface {
CheckHealth() error
FillWithOval(r *models.ScanResult) error
}
// Base is a base struct
type Base struct{}
// CheckHealth do health check
func (b Base) CheckHealth() error {
if !b.isFetchViaHTTP() {
return nil
}
url := fmt.Sprintf("%s/health", config.Conf.OvalDBURL)
var errs []error
var resp *http.Response
resp, _, errs = gorequest.New().Get(url).End()
// resp, _, errs = gorequest.New().SetDebug(config.Conf.Debug).Get(url).End()
// resp, _, errs = gorequest.New().Proxy(api.httpProxy).Get(url).End()
if 0 < len(errs) || resp == nil || resp.StatusCode != 200 {
return fmt.Errorf("Failed to request to OVAL server. url: %s, errs: %v",
url, errs)
}
return nil
}
func (b Base) isFetchViaHTTP() bool {
// Default value of OvalDBType is sqlite3
if config.Conf.OvalDBURL != "" && config.Conf.OvalDBType == "sqlite3" {
return true
}
return false
}
type request struct {
pack models.Package
}
@@ -33,7 +64,6 @@ type response struct {
func getDefsByPackNameViaHTTP(r *models.ScanResult) (
relatedDefs []ovalmodels.Definition, err error) {
//TODO Health Check
reqChan := make(chan request, len(r.Packages))
resChan := make(chan response, len(r.Packages))
errChan := make(chan error, len(r.Packages))