forked from mingrammer/flog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
156 lines (142 loc) · 4.42 KB
/
log.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"fmt"
"math/rand"
"strings"
"time"
"github.com/brianvoe/gofakeit"
)
const (
// ApacheCommonLog : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes}
ApacheCommonLog = "%s - %s [%s] \"%s %s %s\" %d %d"
// ApacheCombinedLog : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes} "{referrer}" "{agent}"
ApacheCombinedLog = "%s - %s [%s] \"%s %s %s\" %d %d \"%s\" \"%s\""
// ApacheErrorLog : [{timestamp}] [{module}:{severity}] [pid {pid}:tid {thread-id}] [client %{client}:{port}] %{message}
ApacheErrorLog = "[%s] [%s:%s] [pid %d:tid %d] [client %s:%d] %s"
// RFC3164Log : <priority>{timestamp} {hostname} {application}[{pid}]: {message}
RFC3164Log = "<%d>%s %s %s[%d]: %s"
// RFC5424Log : <priority>{version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message}
RFC5424Log = "<%d>%d %s %s %s %d ID%d %s %s"
// CommonLogFormat : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes}
CommonLogFormat = "%s - %s [%s] \"%s %s %s\" %d %d"
// NetappEMSLog : <priority>{timestamp} [{cluster}-{node}:{ems_ident}:{severity}]: {message}
NetappEMSLog = "<%d>%s [%s-0%d:%s:%s]: %s"
// NetappAuditLog : {timestamp} [{ems_ident}:{severity}:{pid} {session-d} :: {cluster}:{protocol} :: {cluster}-{nodename}:{user} :: {message}
NetappAuditLog = "%s [%s:%s:%d] %d :: %s:%s :: %s-0%d:%s :: %s"
)
// NewApacheCommonLog creates a log string with apache common log format
func NewApacheCommonLog(t time.Time) string {
return fmt.Sprintf(
ApacheCommonLog,
gofakeit.IPv4Address(),
RandAuthUserID(),
t.Format(Apache),
gofakeit.HTTPMethod(),
RandResourceURI(),
RandHTTPVersion(),
gofakeit.StatusCode(),
gofakeit.Number(0, 30000),
)
}
// NewApacheCombinedLog creates a log string with apache combined log format
func NewApacheCombinedLog(t time.Time) string {
return fmt.Sprintf(
ApacheCombinedLog,
gofakeit.IPv4Address(),
RandAuthUserID(),
t.Format(Apache),
gofakeit.HTTPMethod(),
RandResourceURI(),
RandHTTPVersion(),
gofakeit.StatusCode(),
gofakeit.Number(30, 100000),
gofakeit.URL(),
gofakeit.UserAgent(),
)
}
// NewApacheErrorLog creates a log string with apache error log format
func NewApacheErrorLog(t time.Time) string {
return fmt.Sprintf(
ApacheErrorLog,
t.Format(ApacheError),
gofakeit.Word(),
gofakeit.LogLevel("apache"),
gofakeit.Number(1, 10000),
gofakeit.Number(1, 10000),
gofakeit.IPv4Address(),
gofakeit.Number(1, 65535),
gofakeit.HackerPhrase(),
)
}
// NewRFC3164Log creates a log string with syslog (RFC3164) format
func NewRFC3164Log(t time.Time) string {
return fmt.Sprintf(
RFC3164Log,
gofakeit.Number(0, 191),
t.Format(RFC3164),
strings.ToLower(gofakeit.Username()),
gofakeit.Word(),
gofakeit.Number(1, 10000),
gofakeit.HackerPhrase(),
)
}
// NewRFC5424Log creates a log string with syslog (RFC5424) format
func NewRFC5424Log(t time.Time) string {
return fmt.Sprintf(
RFC5424Log,
gofakeit.Number(0, 191),
gofakeit.Number(1, 3),
t.Format(RFC5424),
gofakeit.DomainName(),
gofakeit.Word(),
gofakeit.Number(1, 10000),
gofakeit.Number(1, 1000),
"-", // TODO: structured data
gofakeit.HackerPhrase(),
)
}
// NewCommonLogFormat creates a log string with common log format
func NewCommonLogFormat(t time.Time) string {
return fmt.Sprintf(
CommonLogFormat,
gofakeit.IPv4Address(),
RandAuthUserID(),
t.Format(CommonLog),
gofakeit.HTTPMethod(),
RandResourceURI(),
RandHTTPVersion(),
gofakeit.StatusCode(),
gofakeit.Number(0, 30000),
)
}
func NewNetappEMSLog(t time.Time) string {
return fmt.Sprintf(
NetappEMSLog,
gofakeit.Number(0, 191),
t.Format(RFC3164),
strings.ToLower(gofakeit.Word()),
gofakeit.Number(1, 4),
gofakeit.Word()+"."+gofakeit.Word()+"."+gofakeit.Word(),
gofakeit.LogLevel("syslog"),
gofakeit.HackerPhrase(),
)
}
func NewNetappAuditLog(t time.Time) string {
clustername := strings.ToUpper(gofakeit.Word())
available_protocols := []string{"ontapi", "http", "ssh", "snmp"}
protocol := available_protocols[rand.Intn(len(available_protocols))]
return fmt.Sprintf(
NetappAuditLog,
t.Format(NetappAudit),
"kern_audit",
gofakeit.LogLevel("syslog"),
gofakeit.Number(1000, 9999),
gofakeit.Uint64(),
clustername,
protocol,
clustername,
gofakeit.Number(1, 4),
gofakeit.Username(),
gofakeit.HackerPhrase(),
)
}