* tests: don't run crowdsec if not necessary * make listen_uri report the random port number when 0 is requested * move apiserver.getTLSAuthType() -> csconfig.TLSCfg.GetAuthType() * move apiserver.isEnrolled() -> apiclient.ApiClient.IsEnrolled() * extract function apiserver.recoverFromPanic() * simplify and move APIServer.GetTLSConfig() -> TLSCfg.GetTLSConfig() * moved TLSCfg type to csconfig/tls.go * APIServer.InitController(): early return / happy path * extract function apiserver.newGinLogger() * lapi tests * update unit test * lint (testify) * lint (whitespace, variable names) * update docker tests
30 lines
559 B
Go
30 lines
559 B
Go
package apiclient
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
)
|
|
|
|
type MetricsService service
|
|
|
|
func (s *MetricsService) Add(ctx context.Context, metrics *models.Metrics) (interface{}, *Response, error) {
|
|
var response interface{}
|
|
|
|
u := fmt.Sprintf("%s/metrics/", s.client.URLPrefix)
|
|
|
|
req, err := s.client.NewRequest(http.MethodPost, u, &metrics)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
resp, err := s.client.Do(ctx, req, &response)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return &response, resp, nil
|
|
}
|