https://github.com/abo/regen
A regexp generator of field for log analytics
https://github.com/abo/regen
Last synced: 11 months ago
JSON representation
A regexp generator of field for log analytics
- Host: GitHub
- URL: https://github.com/abo/regen
- Owner: abo
- Created: 2016-05-27T03:31:29.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T02:04:46.000Z (over 1 year ago)
- Last Synced: 2025-06-11T09:09:05.747Z (about 1 year ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
regen
=====
A regexp generator of field for log analytics
Tutorial
--------
```
package main
import (
"fmt"
"regexp"
"strings"
"github.com/abo/regen"
)
func main() {
mailsv := `Thu May 15 2015 00:15:05 mailsv1 sshd[2716]: Failed password for invalid user postgres from 86.212.199.60 port 4093 ssh2
Thu May 15 2015 00:15:05 mailsv1 sshd[2596]: Failed password for invalid user whois from 86.212.199.60 port 3311 ssh2
Thu May 15 2015 00:15:05 mailsv1 sshd[24947]: pam_unix(sshd:session): session opened for user djohnson by (uid=0)
Thu May 15 2015 00:15:05 mailsv1 sshd[3006]: Failed password for invalid user info from 86.212.199.60 port 4078 ssh2
Thu May 15 2015 00:15:05 mailsv1 sshd[5298]: Failed password for invalid user postgres from 86.212.199.60 port 1265 ssh2`
lines := strings.Split(mailsv, "\n")
pattern, _ := Generate(lines[0], "2716")
re := regexp.MustCompile(pattern)
pids := make([]string, len(lines))
for i, l := range lines {
matches := re.FindStringSubmatch(l)
pids[i] = matches[1]
}
fmt.Print(pids)
//Output: [2716 2596 24947 3006 5298]
}
```
Documentation
-------------
Source Code
----------
COMING SOON...