Skip to content

Commit

Permalink
fix branch
Browse files Browse the repository at this point in the history
  • Loading branch information
he2ss committed Oct 23, 2024
1 parent 2cc5c4e commit 1784d54
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
24 changes: 18 additions & 6 deletions pkg/acquisition/modules/http/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpacquisition

import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Check warning on line 268 in pkg/acquisition/modules/http/http.go

View check run for this annotation

Codecov / codecov/patch

pkg/acquisition/modules/http/http.go#L267-L268

Added lines #L267 - L268 were not covered by tests

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()
}

Check warning on line 279 in pkg/acquisition/modules/http/http.go

View check run for this annotation

Codecov / codecov/patch

pkg/acquisition/modules/http/http.go#L278-L279

Added lines #L278 - L279 were not covered by tests

out <- evt
return nil
})
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions pkg/acquisition/modules/http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpacquisition

import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
29 changes: 15 additions & 14 deletions pkg/cwversion/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1784d54

Please sign in to comment.