Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a SumoLogic Output #656

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Follow the links to get the configuration of each output.
- [**Syslog**](https://github.com/falcosecurity/falcosidekick/blob/master/docs/outputs/syslog.md)
- [**Zincsearch**](https://github.com/falcosecurity/falcosidekick/blob/master/docs/outputs//zincsearch.md)
- [**OpenObserve**](https://github.com/falcosecurity/falcosidekick/blob/master/docs/outputs/openobserve.md)
- [**SumoLogic**](https://github.com/falcosecurity/falcosidekick/blob/master/docs/outputs/sumologic.md)

### Object Storage

Expand Down
8 changes: 8 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func getConfig() *types.Configuration {
v.SetDefault("Loki.Endpoint", "/loki/api/v1/push")
v.SetDefault("Loki.ExtraLabels", "")

v.SetDefault("SumoLogic.MinimumPriority", "")
v.SetDefault("SumoLogic.ReceiverURL", "")
v.SetDefault("SumoLogic.SourceCategory", "")
v.SetDefault("SumoLogic.SourceHost", "")
v.SetDefault("SumoLogic.Name", "")
v.SetDefault("SumoLogic.CheckCert", true)
mencarellic marked this conversation as resolved.
Show resolved Hide resolved

v.SetDefault("AWS.AccessKeyID", "")
v.SetDefault("AWS.SecretAccessKey", "")
v.SetDefault("AWS.Region", "")
Expand Down Expand Up @@ -691,6 +698,7 @@ func getConfig() *types.Configuration {
c.Elasticsearch.MinimumPriority = checkPriority(c.Elasticsearch.MinimumPriority)
c.Influxdb.MinimumPriority = checkPriority(c.Influxdb.MinimumPriority)
c.Loki.MinimumPriority = checkPriority(c.Loki.MinimumPriority)
c.SumoLogic.MinimumPriority = checkPriority(c.SumoLogic.MinimumPriority)
c.Nats.MinimumPriority = checkPriority(c.Nats.MinimumPriority)
c.Stan.MinimumPriority = checkPriority(c.Stan.MinimumPriority)
c.AWS.Lambda.MinimumPriority = checkPriority(c.AWS.Lambda.MinimumPriority)
Expand Down
10 changes: 9 additions & 1 deletion config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ tekton:
# eventListener: "" # EventListener address, if not empty, Tekton output is enabled
# minimumpriority: "" # minimum priority of event for using this output, order is emergency|alert|critical|error|warning|notice|informational|debug or "" (default)
# checkcert: true # check if ssl certificate of the output is valid (default: true)

spyderbat:
# orguid: "" # Organization to send output to, if not empty, Spyderbat output is enabled
# apikey: "" # Spyderbat API key with access to the organization
Expand Down Expand Up @@ -483,3 +483,11 @@ dynatrace:
apiurl: "" # Dynatrace API url, use https://ENVIRONMENTID.live.dynatrace.com/api for Dynatrace SaaS and https://YOURDOMAIN/e/ENVIRONMENTID/api for Dynatrace Managed, more info : https://dt-url.net/ej43qge
# minimumpriority: "" # minimum priority of event for using this output, order is emergency|alert|critical|error|warning|notice|informational|debug or "" (default)
# checkcert: true # check if ssl certificate of the output is valid (default: true)

sumologic:
ReceiverURL: "" # Sumologic HTTP Source URL, if not empty, Sumologic output is enabled
# SourceCategory: "" # Override the default Sumologic Source Category
# SourceHost: "" # Override the default Sumologic Source Host
# Name: "" # Override the default Sumologic Source Name
mencarellic marked this conversation as resolved.
Show resolved Hide resolved
# minimumpriority: "" # minimum priority of event for using this output, order is emergency|alert|critical|error|warning|notice|informational|debug or "" (default)
# checkcert: true # check if ssl certificate of the output is valid (default: true)
Binary file added docs/outputs/images/sumologic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions docs/outputs/sumologic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SumoLogic


- **Category**: Logs
- **Website**: https://www.sumologic.com/

## Table of content

- [SumoLogic](#sumologic)
- [Table of content](#table-of-content)
- [Configuration](#configuration)
- [Example of config.yaml](#example-of-configyaml)
- [Screenshots](#screenshots)

## Configuration

| Setting | Env var | Default value | Description |
| ---------------------- | ---------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `sumologic.receiverurl` | `SUMOLOGIC_RECEIVERURL` | | https://[SumoEndpoint]/receiver/v1/http/[UniqueHTTPCollectorCode], if not empty, SumoLogic output is **enabled** |
| `sumologic.sourcecategory` | `SUMOLOGIC_SOURCECATEGORY` | | Override the default Source Category for the collector |
| `sumologic.sourcehost` | `SUMOLOGIC_SOURCEHOST` | | Override the default Source Host for the collector |
| `sumologic.name` | `SUMOLOGIC_NAME` | | Override the default Name for the collector |
| `sumologic.checkcert` | `SUMOLOGIC_CHECKCERT` | | Check if ssl certificate of the output is valid |
| `sumologic.minimumpriority` | `SUMOLOGIC_MINIMUMPRIORITY` | `""` (= `debug`) | Minimum priority of event for using this output, order is `emergency,alert,critical,error,warning,notice,informational,debug or ""` |


> **Note**
The Env var values override the settings from yaml file.

## Example of config.yaml

```yaml
sumologic:
ReceiverURL: "" # Sumologic HTTP Source URL, if not empty, Sumologic output is enabled
# SourceCategory: "" # Override the default Sumologic Source Category
# SourceHost: "" # Override the default Sumologic Source Host
# Name: "" # Override the default Sumologic Source Name
mencarellic marked this conversation as resolved.
Show resolved Hide resolved
# minimumpriority: "" # minimum priority of event for using this output, order is emergency|alert|critical|error|warning|notice|informational|debug or "" (default)
# checkcert: true # check if ssl certificate of the output is valid (default: true)
```

## Screenshots

With SumoLogic

![sumologic example](images/sumologic.png)
4 changes: 4 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func forwardEvent(falcopayload types.FalcoPayload) {
go lokiClient.LokiPost(falcopayload)
}

if config.SumoLogic.ReceiverURL != "" && (falcopayload.Priority >= types.Priority(config.SumoLogic.MinimumPriority) || falcopayload.Rule == testRule) {
go sumologicClient.SumoLogicPost(falcopayload)
}

if config.Nats.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Nats.MinimumPriority) || falcopayload.Rule == testRule) {
go natsClient.NatsPublish(falcopayload)
}
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
elasticsearchClient *outputs.Client
influxdbClient *outputs.Client
lokiClient *outputs.Client
sumologicClient *outputs.Client
natsClient *outputs.Client
stanClient *outputs.Client
awsClient *outputs.Client
Expand Down Expand Up @@ -227,6 +228,16 @@ func init() {
}
}

if config.SumoLogic.ReceiverURL != "" {
var err error
sumologicClient, err = outputs.NewClient("SumoLogic", config.SumoLogic.ReceiverURL, false, config.SumoLogic.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.SumoLogic.ReceiverURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "SumoLogic")
}
}

if config.Nats.HostPort != "" {
var err error
natsClient, err = outputs.NewClient("NATS", config.Nats.HostPort, config.Nats.MutualTLS, config.Nats.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
Expand Down
53 changes: 53 additions & 0 deletions outputs/sumologic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package outputs

import (
"log"
"net/url"

"github.com/falcosecurity/falcosidekick/types"
)

// SumoLogicPost posts event to SumoLogic
func (c *Client) SumoLogicPost(falcopayload types.FalcoPayload) {
c.Stats.SumoLogic.Add(Total, 1)

endpointURL, err := url.Parse(c.Config.SumoLogic.ReceiverURL)
if err != nil {
c.setSumoLogicErrorMetrics()
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
return
}

c.EndpointURL = endpointURL

if c.Config.SumoLogic.SourceCategory != "" {
c.AddHeader("X-Sumo-Category", c.Config.SumoLogic.SourceCategory)
}

if c.Config.SumoLogic.SourceHost != "" {
c.AddHeader("X-Sumo-Host", c.Config.SumoLogic.SourceHost)
}

if c.Config.SumoLogic.Name != "" {
c.AddHeader("X-Sumo-Name", c.Config.SumoLogic.Name)
}

err = c.Post(falcopayload)
if err != nil {
c.setSumoLogicErrorMetrics()
log.Printf("[ERROR] : SumoLogic - %v\n", err)
mencarellic marked this conversation as resolved.
Show resolved Hide resolved
return
}

// Setting the success status
go c.CountMetric(Outputs, 1, []string{"output:sumologic", "status:ok"})
c.Stats.SumoLogic.Add(OK, 1)
c.PromStats.Outputs.With(map[string]string{"destination": "sumologic", "status": OK}).Inc()
}

// setSumoLogicErrorMetrics set the error stats
func (c *Client) setSumoLogicErrorMetrics() {
go c.CountMetric(Outputs, 1, []string{"output:sumologic", "status:error"})
c.Stats.SumoLogic.Add(Error, 1)
c.PromStats.Outputs.With(map[string]string{"destination": "sumologic", "status": Error}).Inc()
}
1 change: 1 addition & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func getInitStats() *types.Statistics {
Alertmanager: getOutputNewMap("alertmanager"),
Elasticsearch: getOutputNewMap("elasticsearch"),
Loki: getOutputNewMap("loki"),
SumoLogic: getOutputNewMap("sumologic"),
Nats: getOutputNewMap("nats"),
Stan: getOutputNewMap("stan"),
Influxdb: getOutputNewMap("influxdb"),
Expand Down
12 changes: 12 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Configuration struct {
Elasticsearch ElasticsearchOutputConfig
Influxdb influxdbOutputConfig
Loki LokiOutputConfig
SumoLogic SumoLogicOutputConfig
Nats natsOutputConfig
Stan stanOutputConfig
AWS awsOutputConfig
Expand Down Expand Up @@ -286,6 +287,16 @@ type LokiOutputConfig struct {
CustomHeaders map[string]string
}

type SumoLogicOutputConfig struct {
MinimumPriority string
ReceiverURL string
SourceCategory string
SourceHost string
Name string
CheckCert bool
MutualTLS bool
}

type prometheusOutputConfig struct {
ExtraLabels string
ExtraLabelsList []string
Expand Down Expand Up @@ -750,6 +761,7 @@ type Statistics struct {
Alertmanager *expvar.Map
Elasticsearch *expvar.Map
Loki *expvar.Map
SumoLogic *expvar.Map
Nats *expvar.Map
Stan *expvar.Map
Influxdb *expvar.Map
Expand Down