Skip to content

Commit

Permalink
allow to use envvar as custom fields
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <[email protected]>
  • Loading branch information
Issif authored and poiana committed Aug 5, 2022
1 parent f5d2426 commit 2976268
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ See **config_example.yaml** :
#listenaddress: "" # ip address to bind falcosidekick to (default: "" meaning all addresses)
#listenport: 2801 # port to listen for daemon (default: 2801)
debug: false # if true all outputs will print in stdout the payload they send (default: false)
customfields: # custom fields are added to falco events
customfields: # custom fields are added to falco events, if the value starts with % the relative env var is used
Akey: "AValue"
Bkey: "BValue"
Ckey: "CValue"
Expand Down Expand Up @@ -520,7 +520,7 @@ care of lower/uppercases**) : `yaml: a.b --> envvar: A_B` :
- **LISTENPORT** : port to listen for daemon (default: `2801`)
- **DEBUG** : if _true_ all outputs will print in stdout the payload they send
(default: false)
- **CUSTOMFIELDS** : a list of comma separated custom fields to add to falco
- **CUSTOMFIELDS** : a list of comma separated custom fields to add to falco, if the value starts with % the relative env var is used
events, syntax is "key:value,key:value"
**MUTUALTLSFILESPATH**: path which will be used to stored certs and key for mutual tls authentication (default: "/etc/certs")
- **SLACK_WEBHOOKURL** : Slack Webhook URL (ex:
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,15 @@ func getConfig() *types.Configuration {
for _, label := range customfields {
tagkeys := strings.Split(label, ":")
if len(tagkeys) == 2 {
c.Customfields[tagkeys[0]] = tagkeys[1]
if strings.HasPrefix(tagkeys[1], "%") {
if s := os.Getenv(tagkeys[1][1:]); s != "" {
c.Customfields[tagkeys[0]] = s
} else {
log.Printf("[ERROR] : Can't find env var %v for custom fields", tagkeys[1][1:])
}
} else {
c.Customfields[tagkeys[0]] = tagkeys[1]
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config_example.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#listenaddress: "" # ip address to bind falcosidekick to (default: "" meaning all addresses)
#listenport: 2801 # port to listen for daemon (default: 2801)
debug: false # if true all outputs will print in stdout the payload they send (default: false)
customfields: # custom fields are added to falco events and metrics
customfields: # custom fields are added to falco events and metrics, if the value starts with % the relative env var is used
Akey: "AValue"
Bkey: "BValue"
Ckey: "CValue"
Expand Down

0 comments on commit 2976268

Please sign in to comment.