Skip to content

Commit

Permalink
use customfields in prometheus
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Mill <jeremymill@gmail.com>
  • Loading branch information
LivingInSyn committed Apr 15, 2022
1 parent dbfafd7 commit 3ded9f0
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 27 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ customfields: # custom fields are added to falco events
Ckey: "CValue"
mutualtlsfilespath: "/etc/certs" # folder which will used to store client.crt, client.key and ca.crt files for mutual tls (default: "/etc/certs")
customprometheus: # custom labels to add to prometheus
Akey: "AValue"
Bkey: "BValue"
Ckey: "CValue"
slack:
webhookurl: "" # Slack WebhookURL (ex: https://hooks.slack.com/services/XXXX/YYYY/ZZZZ), if not empty, Slack output is enabled
#footer: "" # Slack footer
Expand Down
18 changes: 3 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (

func getConfig() *types.Configuration {
c := &types.Configuration{
Customfields: make(map[string]string),
CustomPrometheus: make(map[string]string),
Webhook: types.WebhookOutputConfig{CustomHeaders: make(map[string]string)},
CloudEvents: types.CloudEventsOutputConfig{Extensions: make(map[string]string)},
Customfields: make(map[string]string),
Webhook: types.WebhookOutputConfig{CustomHeaders: make(map[string]string)},
CloudEvents: types.CloudEventsOutputConfig{Extensions: make(map[string]string)},
}

configFile := kingpin.Flag("config-file", "config file").Short('c').ExistingFile()
Expand Down Expand Up @@ -328,7 +327,6 @@ func getConfig() *types.Configuration {
}

v.GetStringMapString("customfields")
v.GetStringMapString("customprometheus")
v.GetStringMapString("Webhook.CustomHeaders")
v.GetStringMapString("CloudEvents.Extensions")
if err := v.Unmarshal(c); err != nil {
Expand All @@ -345,16 +343,6 @@ func getConfig() *types.Configuration {
}
}

if value, present := os.LookupEnv("CUSTOMPROMETHEUS"); present {
customprometheus := strings.Split(value, ",")
for _, label := range customprometheus {
tagkeys := strings.Split(label, ":")
if len(tagkeys) == 2 {
c.CustomPrometheus[tagkeys[0]] = tagkeys[1]
}
}
}

if value, present := os.LookupEnv("WEBHOOK_CUSTOMHEADERS"); present {
customfields := strings.Split(value, ",")
for _, label := range customfields {
Expand Down
4 changes: 0 additions & 4 deletions config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ customfields: # custom fields are added to falco events
Akey: "AValue"
Bkey: "BValue"
Ckey: "CValue"
customprometheus: # custom labels to add to prometheus
Akey: "AValue"
Bkey: "BValue"
Ckey: "CValue"
mutualtlsfilespath: "/etc/certs" # folder which will used to store client.crt, client.key and ca.crt files for mutual tls (default: "/etc/certs")

slack:
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newFalcoPayload(payload io.Reader) (types.FalcoPayload, error) {
nullClient.CountMetric("falco.accepted", 1, []string{"priority:" + falcopayload.Priority.String()})
stats.Falco.Add(strings.ToLower(falcopayload.Priority.String()), 1)
promLabels := map[string]string{"rule": falcopayload.Rule, "priority": falcopayload.Priority.String(), "k8s_ns_name": kn, "k8s_pod_name": kp}
for key, value := range config.CustomPrometheus {
for key, value := range config.Customfields {
promLabels[key] = value
}
promStats.Falco.With(promLabels).Inc()
Expand Down
2 changes: 1 addition & 1 deletion stats_prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getFalcoNewCounterVec(config *types.Configuration) *prometheus.CounterVec {
"k8s_ns_name",
"k8s_pod_name",
}
for key := range config.CustomPrometheus {
for key := range config.Customfields {
labelnames = append(labelnames, key)
}
return promauto.NewCounterVec(
Expand Down
1 change: 0 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Configuration struct {
ListenAddress string
ListenPort int
Customfields map[string]string
CustomPrometheus map[string]string
Slack SlackOutputConfig
Cliq CliqOutputConfig
Mattermost MattermostOutputConfig
Expand Down

0 comments on commit 3ded9f0

Please sign in to comment.