Skip to content

Commit

Permalink
allow dashes in hostnames and tag values
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 Apr 27, 2023
1 parent 634a28b commit ee03de7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion internal/database/redis/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Issif/redisearch-go/redisearch"
"github.com/falcosecurity/falcosidekick-ui/internal/models"
"github.com/falcosecurity/falcosidekick-ui/internal/utils"
)

func CountKey(client *redisearch.Client, args *models.Arguments) (models.Results, error) {
Expand Down Expand Up @@ -49,7 +50,7 @@ func CountKeyBy(client *redisearch.Client, args *models.Arguments) (models.Resul
continue
}
for _, j := range strings.Split(key.(string), ",") {
ag[j] += count
ag[utils.UnEscape(j)] += count
all += count
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/database/redis/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func newQuery(args *models.Arguments) string {
var filter, priority, rule, source, hostname, tags, since string
if args.Filter != "" {
filter = args.Filter + "* "
filter = utils.Escape(args.Filter) + "* "
}
if args.Priority != "" {
p := strings.Split(args.Priority, ",")
Expand All @@ -36,14 +36,14 @@ func newQuery(args *models.Arguments) string {
source = fmt.Sprintf("(%v) ", strings.Join(r, " | "))
}
if args.Hostname != "" {
r := strings.Split(args.Hostname, ",")
r := strings.Split(utils.Escape(args.Hostname), ",")
for i, j := range r {
r[i] = fmt.Sprintf("@hostname:%v", j)
}
hostname = fmt.Sprintf("(%v) ", strings.Join(r, " | "))
}
if args.Tags != "" {
r := strings.Split(args.Tags, ",")
r := strings.Split(utils.Escape(args.Tags), ",")
for i, j := range r {
r[i] = fmt.Sprintf("@tags:%v", j)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/database/redis/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Issif/redisearch-go/redisearch"
"github.com/falcosecurity/falcosidekick-ui/configuration"
"github.com/falcosecurity/falcosidekick-ui/internal/models"
"github.com/falcosecurity/falcosidekick-ui/internal/utils"
)

func SetKey(client *redisearch.Client, event *models.Event) error {
Expand All @@ -21,12 +22,12 @@ func SetKey(client *redisearch.Client, event *models.Event) error {
Set("output", event.Output).
Set("source", event.Source).
Set("timestamp", event.Time.UnixNano()/1e3).
Set("tags", strings.Join(event.Tags, ",")).
Set("tags", utils.Escape(strings.Join(event.Tags, ","))).
Set("json", string(jsonString)).
Set("uuid", event.UUID).
SetTTL(c.TTL)
if event.Hostname != "" {
doc.Set("hostname", event.Hostname)
doc.Set("hostname", utils.Escape(event.Hostname))
}

err := client.Index([]redisearch.Document{doc}...)
Expand Down
9 changes: 9 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"sort"
"strconv"
"strings"

"github.com/falcosecurity/falcosidekick-ui/configuration"
)
Expand Down Expand Up @@ -142,3 +143,11 @@ func GetPriortiyInt(prio string) int {
return -1
}
}

func Escape(s string) string {
return strings.ReplaceAll(s, "-", `\-`)
}

func UnEscape(s string) string {
return strings.ReplaceAll(s, `\-`, "-")
}

0 comments on commit ee03de7

Please sign in to comment.