diff --git a/pkg/acquisition/modules/http/http.go b/pkg/acquisition/modules/http/http.go index bd4b269edc6..87a73b5be20 100644 --- a/pkg/acquisition/modules/http/http.go +++ b/pkg/acquisition/modules/http/http.go @@ -1,6 +1,7 @@ package httpacquisition import ( + "context" "crypto/tls" "crypto/x509" "fmt" @@ -15,7 +16,7 @@ import ( "gopkg.in/tomb.v2" "gopkg.in/yaml.v2" - "github.com/crowdsecurity/go-cs-lib/pkg/trace" + "github.com/crowdsecurity/go-cs-lib/trace" "github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration" "github.com/crowdsecurity/crowdsec/pkg/types" @@ -61,9 +62,10 @@ type TLSConfig struct { } type HTTPSource struct { - Config HttpConfiguration - logger *log.Entry - Server *http.Server + metricsLevel int + Config HttpConfiguration + logger *log.Entry + Server *http.Server } func (h *HTTPSource) GetUuid() string { @@ -144,8 +146,9 @@ func (hc *HttpConfiguration) Validate() error { return nil } -func (h *HTTPSource) Configure(yamlConfig []byte, logger *log.Entry) error { +func (h *HTTPSource) Configure(yamlConfig []byte, logger *log.Entry, MetricsLevel int) error { h.logger = logger + h.metricsLevel = MetricsLevel err := h.UnmarshalConfig(yamlConfig) if err != nil { return err @@ -260,12 +263,21 @@ func (h *HTTPSource) processRequest(w http.ResponseWriter, r *http.Request, hc * Module: h.GetName(), } + if h.metricsLevel == configuration.METRICS_AGGREGATE { + line.Src = hc.Path + } + evt := types.Event{ Line: line, Process: true, Type: types.LOG, ExpectMode: types.LIVE, } + + if h.metricsLevel != configuration.METRICS_NONE { + linesRead.With(prometheus.Labels{"path": hc.Path}).Inc() + } + out <- evt return nil }) @@ -355,7 +367,7 @@ func (h *HTTPSource) RunServer(out chan types.Event, t *tomb.Tomb) error { } } -func (h *HTTPSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb) error { +func (h *HTTPSource) StreamingAcquisition(ctx context.Context, out chan types.Event, t *tomb.Tomb) error { h.logger.Debugf("start http server on port %d", h.Config.Port) t.Go(func() error { diff --git a/pkg/acquisition/modules/http/http_test.go b/pkg/acquisition/modules/http/http_test.go index 3752496aefc..84643834d70 100644 --- a/pkg/acquisition/modules/http/http_test.go +++ b/pkg/acquisition/modules/http/http_test.go @@ -1,6 +1,7 @@ package httpacquisition import ( + "context" "crypto/tls" "crypto/x509" "fmt" @@ -12,7 +13,7 @@ import ( "time" "github.com/crowdsecurity/crowdsec/pkg/types" - "github.com/crowdsecurity/go-cs-lib/pkg/cstest" + "github.com/crowdsecurity/go-cs-lib/cstest" log "github.com/sirupsen/logrus" "gopkg.in/tomb.v2" ) @@ -184,7 +185,7 @@ custom_status_code: 999`, for _, test := range tests { h := HTTPSource{} - err := h.Configure([]byte(test.config), subLogger) + err := h.Configure([]byte(test.config), subLogger, 0) cstest.AssertErrorContains(t, err, test.expectedErr) } } @@ -235,16 +236,17 @@ func TestGetName(t *testing.T) { } func SetupAndRunHTTPSource(t *testing.T, h *HTTPSource, config []byte) (chan types.Event, *tomb.Tomb) { + ctx := context.Background() subLogger := log.WithFields(log.Fields{ "type": "http", }) - err := h.Configure(config, subLogger) + err := h.Configure(config, subLogger, 0) if err != nil { t.Fatalf("unable to configure http source: %s", err) } tomb := tomb.Tomb{} out := make(chan types.Event) - err = h.StreamingAcquisition(out, &tomb) + err = h.StreamingAcquisition(ctx, out, &tomb) if err != nil { t.Fatalf("unable to start streaming acquisition: %s", err) } diff --git a/pkg/cwversion/component/component.go b/pkg/cwversion/component/component.go index 4036b63cf00..7ed596525e0 100644 --- a/pkg/cwversion/component/component.go +++ b/pkg/cwversion/component/component.go @@ -7,20 +7,21 @@ package component // Built is a map of all the known components, and whether they are built-in or not. // This is populated as soon as possible by the respective init() functions -var Built = map[string]bool { - "datasource_appsec": false, - "datasource_cloudwatch": false, - "datasource_docker": false, - "datasource_file": false, - "datasource_journalctl": false, - "datasource_k8s-audit": false, - "datasource_kafka": false, - "datasource_kinesis": false, - "datasource_loki": false, - "datasource_s3": false, - "datasource_syslog": false, - "datasource_wineventlog":false, - "cscli_setup": false, +var Built = map[string]bool{ + "datasource_appsec": false, + "datasource_cloudwatch": false, + "datasource_docker": false, + "datasource_file": false, + "datasource_journalctl": false, + "datasource_k8s-audit": false, + "datasource_kafka": false, + "datasource_kinesis": false, + "datasource_loki": false, + "datasource_s3": false, + "datasource_syslog": false, + "datasource_wineventlog": false, + "datasource_http": false, + "cscli_setup": false, } func Register(name string) {