-
Notifications
You must be signed in to change notification settings - Fork 487
/
fields.go
58 lines (52 loc) · 2.39 KB
/
fields.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
package cloudflaretarget
// This code is copied from Promtail. The cloudflaretarget package is used to
// configure and run a target that can read from the Cloudflare Logpull API and
// forward entries to other loki components.
import (
"fmt"
)
// FieldsType defines the set of fields to fetch alongside logs.
type FieldsType string
// Valid FieldsType values.
const (
FieldsTypeDefault FieldsType = "default"
FieldsTypeMinimal FieldsType = "minimal"
FieldsTypeExtended FieldsType = "extended"
FieldsTypeAll FieldsType = "all"
)
var (
defaultFields = []string{
"ClientIP", "ClientRequestHost", "ClientRequestMethod", "ClientRequestURI", "EdgeEndTimestamp", "EdgeResponseBytes",
"EdgeRequestHost", "EdgeResponseStatus", "EdgeStartTimestamp", "RayID",
}
minimalFields = append(defaultFields, []string{
"ZoneID", "ClientSSLProtocol", "ClientRequestProtocol", "ClientRequestPath", "ClientRequestUserAgent", "ClientRequestReferer",
"EdgeColoCode", "ClientCountry", "CacheCacheStatus", "CacheResponseStatus", "EdgeResponseContentType", "SecurityLevel",
"WAFAction", "WAFProfile", "WAFRuleID", "WAFRuleMessage", "EdgeRateLimitID", "EdgeRateLimitAction",
}...)
extendedFields = append(minimalFields, []string{
"ClientSSLCipher", "ClientASN", "ClientIPClass", "CacheResponseBytes", "EdgePathingOp", "EdgePathingSrc", "EdgePathingStatus", "ParentRayID",
"WorkerCPUTime", "WorkerStatus", "WorkerSubrequest", "WorkerSubrequestCount", "OriginIP", "OriginResponseStatus", "OriginSSLProtocol",
"OriginResponseHTTPExpires", "OriginResponseHTTPLastModified",
}...)
allFields = append(extendedFields, []string{
"BotScore", "BotScoreSrc", "ClientRequestBytes", "ClientSrcPort", "ClientXRequestedWith", "CacheTieredFill", "EdgeResponseCompressionRatio", "EdgeServerIP", "FirewallMatchesSources",
"FirewallMatchesActions", "FirewallMatchesRuleIDs", "OriginResponseBytes", "OriginResponseTime", "ClientDeviceType", "WAFFlags", "WAFMatchedVar", "EdgeColoID",
"RequestHeaders", "ResponseHeaders",
}...)
)
// Fields returns the mapping of FieldsType to the set of fields it represents.
func Fields(t FieldsType) ([]string, error) {
switch t {
case FieldsTypeDefault:
return defaultFields, nil
case FieldsTypeMinimal:
return minimalFields, nil
case FieldsTypeExtended:
return extendedFields, nil
case FieldsTypeAll:
return allFields, nil
default:
return nil, fmt.Errorf("unknown fields type: %s", t)
}
}