-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
62 lines (51 loc) · 1.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"github.com/nitishm/engarde/pkg/parser"
)
var (
isIstioProxyLogs bool
limit int
)
func init() {
flag.BoolVar(&isIstioProxyLogs, "use-istio", false, "Enable to use istio-proxy format")
flag.IntVar(&limit, "limit", 0, "Limit number of lines parsed. Set to 0 for unlimited scroll")
}
func main() {
var p *parser.Parser
var enableLimits bool
flag.Parse()
log.Printf("Reading input from STDIN. Use the pipe \"|\" operator to redirect traffic to engarde")
if isIstioProxyLogs {
p = parser.New(parser.IstioProxyAccessLogsPattern)
} else {
p = parser.New(parser.EnvoyAccessLogsPattern)
}
if limit > 0 {
enableLimits = true
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
accessLog, err := p.Parse(line)
if err != nil {
accessLog.ParseError = err.Error()
}
bAccessLog, err := json.MarshalIndent(accessLog, "", " ")
if err != nil {
accessLog.ParseError = err.Error()
}
fmt.Fprintf(os.Stdout, string(bAccessLog))
if enableLimits {
limit = limit - 1
if limit == 0 {
os.Exit(0)
}
}
}
}