-
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.
- Loading branch information
Showing
8 changed files
with
500 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,88 @@ Rust port of Elastic Grok processor, inspired by [grok-go][grok-go] and [grok][g | |
|
||
## Example | ||
|
||
### Only with default patterns | ||
|
||
```rust | ||
let grok = Grok::default(); | ||
let pattern = grok | ||
// USERNAME are defined in grok-patterns | ||
.compile("%{USERNAME}", false) | ||
.unwrap(); | ||
let result = pattern.parse("admin [email protected]").unwrap(); | ||
println!("{:#?}", result); | ||
``` | ||
|
||
the output is: | ||
|
||
```text | ||
{ | ||
"USERNAME": String( | ||
"admin", | ||
), | ||
} | ||
``` | ||
|
||
### With user-defined patterns | ||
|
||
```rust | ||
let mut grok = Grok::default(); | ||
grok.add_pattern("NAME", r"[A-z0-9._-]+"); | ||
let pattern = grok.compile("%{NAME}", false).unwrap(); | ||
let result = pattern.parse("admin").unwrap(); | ||
println!("{:#?}", result); | ||
``` | ||
|
||
the output is: | ||
|
||
```text | ||
{ | ||
"NAME": String( | ||
"admin", | ||
), | ||
} | ||
``` | ||
|
||
### With `named_capture_only` is true | ||
|
||
```rust | ||
let grok = Grok::default(); | ||
let pattern = grok | ||
.compile("%{USERNAME} %{EMAILADDRESS:email}", true) | ||
.unwrap(); | ||
let result = pattern.parse("admin [email protected]").unwrap(); | ||
println!("{:#?}", result); | ||
``` | ||
|
||
the output is: | ||
|
||
```text | ||
{ | ||
"email": String( | ||
"[email protected]", | ||
), | ||
} | ||
``` | ||
|
||
### With type | ||
|
||
```rust | ||
let mut grok = Grok::default(); | ||
grok.add_pattern("NUMBER", r"\d+"); | ||
|
||
let pattern = grok.compile("%{NUMBER:digit:int}", false).unwrap(); | ||
let result = pattern.parse("hello 123").unwrap(); | ||
println!("{:#?}", result); | ||
``` | ||
|
||
the output is: | ||
|
||
```text | ||
{ | ||
"digit": Int( | ||
123, | ||
), | ||
} | ||
``` | ||
|
||
## Elastic Grok compliance | ||
|
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,9 @@ | ||
use grok_rs::Grok; | ||
|
||
fn main() { | ||
let mut grok = Grok::default(); | ||
grok.add_pattern("NAME", r"[A-z0-9._-]+"); | ||
let pattern = grok.compile("%{NAME}", false).unwrap(); | ||
let result = pattern.parse("admin").unwrap(); | ||
println!("{:#?}", result); | ||
} |
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,12 @@ | ||
use grok_rs::Grok; | ||
|
||
fn main() { | ||
let grok = Grok::default(); | ||
let pattern = grok | ||
// USERNAME and EMAILADDRESS are defined in grok-patterns | ||
.compile("%{USERNAME}", false) | ||
.unwrap(); | ||
|
||
let result = pattern.parse("admin [email protected]").unwrap(); | ||
println!("{:#?}", result); | ||
} |
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,10 @@ | ||
use grok_rs::Grok; | ||
|
||
fn main() { | ||
let grok = Grok::default(); | ||
let pattern = grok | ||
.compile("%{USERNAME} %{EMAILADDRESS:email}", true) | ||
.unwrap(); | ||
let result = pattern.parse("admin [email protected]").unwrap(); | ||
println!("{:#?}", result); | ||
} |
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,10 @@ | ||
use grok_rs::Grok; | ||
|
||
fn main() { | ||
let mut grok = Grok::default(); | ||
grok.add_pattern("NUMBER", r"\d+"); | ||
|
||
let pattern = grok.compile("%{NUMBER:digit:int}", false).unwrap(); | ||
let result = pattern.parse("hello 123").unwrap(); | ||
println!("{:#?}", result); | ||
} |
Oops, something went wrong.