-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quickwit_output): implement the quickwit output
Signed-off-by: Idriss Neumann <idriss.neumann@comwork.io>
- Loading branch information
1 parent
49be6d4
commit 05932ae
Showing
11 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Quickwit | ||
|
||
- **Category**: Logs | ||
- **Website**: https://quickwit.io/ | ||
|
||
## Table of content | ||
|
||
- [Quickwit](#quickwit) | ||
- [Table of content](#table-of-content) | ||
- [Configuration](#configuration) | ||
- [Example of config.yaml](#example-of-configyaml) | ||
- [Screenshots](#screenshots) | ||
|
||
## Configuration | ||
|
||
| Setting | Env var | Default value | Description | | ||
| ------------------------------- | ------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `quickwit.hosport` | `QUICKWIT_HOSTPORT` | | http://{domain or ip}:{port}, if not empty, Quickwit output is **enabled** | | ||
| `quickwit.apiendpoint` | `QUICKWIT_APIENDPOINT` | `api/v1` | API endpoint (containing the API version, overideable in case of quickwit behind a reverse proxy with URL rewriting) | | ||
| `quickwit.index` | `QUICKWIT_INDEX` | `falco` | Index | | ||
| `quickwit.version` | `QUICKWIT_VERSION` | `0.7` | Version of quickwit | | ||
| `quickwit.autocreateindex` | `QUICKWIT_AUTOCREATEINDEX` | `false` | Autocreate a `falco` index mapping if it doesn't exists | | ||
| `quickwit.customheaders` | `QUICKWIT_CUSTOMHEADERS` | | Custom headers to add in POST, useful for Authentication | | ||
| `quickwit.mutualtls` | `QUICKWIT_MUTUALTLS` | `false` | Authenticate to the output with TLS, if true, checkcert flag will be ignored (server cert will always be checked) | | ||
| `quickwit.checkcert` | `QUICKWIT_CHECKCERT` | `true` | Check if ssl certificate of the output is valid | | ||
| `quickwit.minimumpriority` | `QUICKWIT_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 | ||
quickwit: | ||
# hostport: "" | ||
# apiendpoint: "/api/v1" | ||
# index: "falco" | ||
# version: "0.7" | ||
# autocreateindex: false | ||
# customHeaders: | ||
# key: value | ||
# mutualtls: false | ||
# checkcert: true | ||
# minimumpriority: "" | ||
``` | ||
|
||
## Screenshots | ||
|
||
With Grafana: | ||
![Grafana example](images/grafana_quickwit.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2023 The Falco Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package outputs | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/falcosecurity/falcosidekick/types" | ||
) | ||
|
||
type QuickwitDynamicMapping struct { | ||
Description string `json:"description"` | ||
Fast bool `json:"fast"` | ||
ExpendDots bool `json:"expand_dots"` | ||
Indexed bool `json:"indexed"` | ||
Record string `json:"record"` | ||
Stored bool `json:"stored"` | ||
Tokenizer string `json:"tokenizer"` | ||
} | ||
|
||
type QuickwitFieldMapping struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Fast bool `json:"fast"` | ||
} | ||
|
||
type QuickwitSearchSettings struct { | ||
DefaultSearchFields []string `json:"default_search_fields"` | ||
} | ||
|
||
type QuickwitDocMapping struct { | ||
DynamicMapping QuickwitDynamicMapping `json:"dynamic_mapping"` | ||
FieldMappings []QuickwitFieldMapping `json:"field_mappings"` | ||
Mode string `json:"mode"` | ||
StoreSource bool `json:"store_source"` | ||
TimestampField string `json:"timestamp_field"` | ||
} | ||
|
||
type QuickwitMappingPayload struct { | ||
Id string `json:"index_id"` | ||
Version string `json:"version"` | ||
SearchSettings QuickwitSearchSettings `json:"search_settings"` | ||
DocMapping QuickwitDocMapping `json:"doc_mapping"` | ||
} | ||
|
||
func (c *Client) checkQuickwitIndexAlreadyExists(args types.InitClientArgs) bool { | ||
config := args.Config.Quickwit | ||
|
||
endpointUrl := fmt.Sprintf("%s/%s/indexes/%s/describe", config.HostPort, config.ApiEndpoint, config.Index) | ||
quickwitCheckClient, err := InitClient("QuickwitCheckAlreadyExists", endpointUrl, config.MutualTLS, config.CheckCert, args) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if nil != quickwitCheckClient.sendRequest("GET", "") { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (c *Client) AutoCreateQuickwitIndex(args types.InitClientArgs) error { | ||
config := args.Config.Quickwit | ||
|
||
if c.checkQuickwitIndexAlreadyExists(args) { | ||
return nil | ||
} | ||
|
||
endpointUrl := fmt.Sprintf("%s/%s/indexes", config.HostPort, config.ApiEndpoint) | ||
quickwitInitClient, err := InitClient("QuickwitInit", endpointUrl, config.MutualTLS, config.CheckCert, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mapping := &QuickwitMappingPayload{ | ||
Id: config.Index, | ||
Version: config.Version, | ||
DocMapping: QuickwitDocMapping{ | ||
Mode: "dynamic", | ||
StoreSource: true, | ||
TimestampField: "time", | ||
DynamicMapping: QuickwitDynamicMapping{ | ||
Description: "Falco", | ||
Fast: true, | ||
ExpendDots: true, | ||
Indexed: true, | ||
Stored: true, | ||
Record: "basic", | ||
Tokenizer: "raw", | ||
}, | ||
FieldMappings: []QuickwitFieldMapping{ | ||
{ | ||
Name: "time", | ||
Type: "datetime", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "uuid", | ||
Type: "text", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "hostname", | ||
Type: "text", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "priority", | ||
Type: "text", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "source", | ||
Type: "text", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "output", | ||
Type: "text", | ||
}, | ||
{ | ||
Name: "rule", | ||
Type: "text", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "tags", | ||
Type: "array<text>", | ||
Fast: true, | ||
}, | ||
{ | ||
Name: "output_fields", | ||
Type: "json", | ||
Fast: true, | ||
}, | ||
}, | ||
}, | ||
SearchSettings: QuickwitSearchSettings{ | ||
DefaultSearchFields: []string{"rule", "source", "output", "priority", "hostname", "tags"}, | ||
}, | ||
} | ||
|
||
if args.Config.Debug { | ||
log.Printf("[DEBUG] : Quickwit - mapping: %#v\n", mapping) | ||
} | ||
|
||
err = quickwitInitClient.Post(mapping) | ||
|
||
// This error means it's an http 400 (meaning the index already exists, so no need to throw an error) | ||
if err != nil && err.Error() == "header missing" { | ||
return nil | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *Client) QuickwitPost(falcopayload types.FalcoPayload) { | ||
c.Stats.Quickwit.Add(Total, 1) | ||
|
||
if len(c.Config.Quickwit.CustomHeaders) != 0 { | ||
c.httpClientLock.Lock() | ||
defer c.httpClientLock.Unlock() | ||
for i, j := range c.Config.Quickwit.CustomHeaders { | ||
c.AddHeader(i, j) | ||
} | ||
} | ||
|
||
if c.Config.Debug { | ||
log.Printf("[DEBUG] : Quickwit - ingesting payload: %v\n", falcopayload) | ||
} | ||
|
||
err := c.Post(falcopayload) | ||
|
||
if err != nil { | ||
go c.CountMetric(Outputs, 1, []string{"output:quickwit", "status:error"}) | ||
c.Stats.Quickwit.Add(Error, 1) | ||
c.PromStats.Outputs.With(map[string]string{"destination": "quickwit", "status": Error}).Inc() | ||
log.Printf("[ERROR] : Quickwit - %v\n", err.Error()) | ||
return | ||
} | ||
|
||
// Setting the success status | ||
go c.CountMetric(Outputs, 1, []string{"output:quickwit", "status:ok"}) | ||
c.Stats.Quickwit.Add(OK, 1) | ||
c.PromStats.Outputs.With(map[string]string{"destination": "quickwit", "status": OK}).Inc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.