github.com/crowdsecurity/crowdsec@v1.6.1/pkg/acquisition/modules/loki/entry.go (about) 1 package loki 2 3 import ( 4 "encoding/json" 5 "strconv" 6 "time" 7 ) 8 9 type Entry struct { 10 Timestamp time.Time 11 Line string 12 } 13 14 func (e *Entry) UnmarshalJSON(b []byte) error { 15 var values []string 16 err := json.Unmarshal(b, &values) 17 if err != nil { 18 return err 19 } 20 t, err := strconv.Atoi(values[0]) 21 if err != nil { 22 return err 23 } 24 e.Timestamp = time.Unix(int64(t), 0) 25 e.Line = values[1] 26 return nil 27 } 28 29 type Stream struct { 30 Stream map[string]string `json:"stream"` 31 Entries []Entry `json:"values"` 32 } 33 34 type DroppedEntry struct { 35 Labels map[string]string `json:"labels"` 36 Timestamp time.Time `json:"timestamp"` 37 } 38 39 type Tail struct { 40 Streams []Stream `json:"streams"` 41 DroppedEntries []DroppedEntry `json:"dropped_entries"` 42 } 43 44 // LokiQuery GET response. 45 // See https://grafana.com/docs/loki/latest/api/#get-lokiapiv1query 46 type LokiQuery struct { 47 Status string `json:"status"` 48 Data Data `json:"data"` 49 } 50 51 type Data struct { 52 ResultType string `json:"resultType"` 53 Result []StreamResult `json:"result"` // Warning, just stream value is handled 54 Stats interface{} `json:"stats"` // Stats is boring, just ignore it 55 } 56 57 type StreamResult struct { 58 Stream map[string]string `json:"stream"` 59 Values []Entry `json:"values"` 60 }