2020-11-30 09:37:17 +00:00
|
|
|
package apiclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-01-13 15:46:16 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SignalService service
|
|
|
|
|
|
|
|
func (s *SignalService) Add(ctx context.Context, signals *models.AddSignalsRequest) (interface{}, *Response, error) {
|
|
|
|
var response interface{}
|
|
|
|
|
|
|
|
u := fmt.Sprintf("%s/signals", s.client.URLPrefix)
|
|
|
|
req, err := s.client.NewRequest("POST", u, &signals)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.Wrap(err, "while building request")
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.client.Do(ctx, req, &response)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, errors.Wrap(err, "while performing request")
|
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
if resp.Response.StatusCode != 200 {
|
|
|
|
log.Warnf("Signal push response : http %s", resp.Response.Status)
|
|
|
|
} else {
|
|
|
|
log.Debugf("Signal push response : http %s", resp.Response.Status)
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
return &response, resp, nil
|
|
|
|
}
|