forked from vjeantet/grok
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support to parse into nested map[string]interface{} maps when using parseTyped(). To better deal with special characters in field names hashing(md5) is used for aliases.
- Loading branch information
1 parent
53ca963
commit d2256f6
Showing
4 changed files
with
134 additions
and
9 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
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 |
---|---|---|
|
@@ -599,6 +599,32 @@ func TestParseTypedWithAlias(t *testing.T) { | |
} | ||
} | ||
|
||
func TestParseTypedWithNested(t *testing.T) { | ||
g,_ := NewWithConfig(&Config{NamedCapturesOnly: true}) | ||
if captures, err := g.ParseTyped("%{TIMESTAMP_ISO8601:time} %{USER:[user][name]}@%{HOSTNAME:[user][host]} %{WORD:action} %{POSINT:[net][bytes]:int} bytes from %{IP:[net][source][ip]}:%{POSINT:[net][source][port]:int}","2023-04-08T11:55:00+0200 [email protected] send 230 bytes from 198.51.100.65:2342"); err != nil { | ||
t.Fatalf("error can not capture : %s", err.Error()) | ||
} else { | ||
expected := map[string]interface{}{ | ||
"time": "2023-04-08T11:55:00+0200", | ||
"action": "send", | ||
"user": map[string]interface{}{ | ||
"name": "john.doe", | ||
"host": "example.com", | ||
}, | ||
"net": map[string]interface{}{ | ||
"bytes": 230, | ||
"source": map[string]interface{}{ | ||
"ip": "198.51.100.65", | ||
"port": 2342, | ||
}, | ||
}, | ||
} | ||
if fmt.Sprint(expected) != fmt.Sprint(captures) { | ||
t.Fatalf("Expected nested map: %s got %s", expected, captures) | ||
} | ||
} | ||
} | ||
|
||
var resultNew *Grok | ||
|
||
func BenchmarkNew(b *testing.B) { | ||
|