github.com/GuanceCloud/cliutils@v1.1.21/pipeline/manager/msgstatus.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the MIT License. 3 // This product includes software developed at Guance Cloud (https://www.guance.com/). 4 // Copyright 2021-present Guance, Inc. 5 6 package manager 7 8 import ( 9 "strings" 10 11 "github.com/GuanceCloud/cliutils/pipeline/ptinput" 12 plast "github.com/GuanceCloud/platypus/pkg/ast" 13 ) 14 15 const ( 16 // pipeline关键字段. 17 FieldTime = "time" 18 FieldMessage = "message" 19 FieldStatus = "status" 20 PlLoggingSource = "source" 21 22 DefaultStatus = "unknown" 23 ) 24 25 var statusMap = map[string]string{ 26 "f": "emerg", 27 "emerg": "emerg", 28 "a": "alert", 29 "alert": "alert", 30 "c": "critical", 31 "critical": "critical", 32 "e": "error", 33 "error": "error", 34 "w": "warning", 35 "warn": "warning", 36 "warning": "warning", 37 "n": "notice", 38 "notice": "notice", 39 "i": "info", 40 "info": "info", 41 "d": "debug", 42 "trace": "debug", 43 "verbose": "debug", 44 "debug": "debug", 45 "o": "OK", 46 "s": "OK", 47 "ok": "OK", 48 } 49 50 func normalizeStatus(status string) string { 51 status = strings.ToLower(status) 52 53 if s, ok := statusMap[status]; ok { 54 status = s 55 } else if status == "" { 56 status = DefaultStatus 57 } 58 59 return status 60 } 61 62 func filterByStatus(stats string, filterRule []string) bool { 63 for _, v := range filterRule { 64 if strings.ToLower(v) == stats { 65 return true 66 } 67 } 68 return false 69 } 70 71 func ProcLoggingStatus(plpt ptinput.PlInputPt, disable bool, ignore []string) { 72 status := DefaultStatus 73 74 if s, _, err := plpt.Get(FieldStatus); err == nil { 75 if s, ok := s.(string); ok { 76 status = s 77 } 78 } 79 80 if !disable { 81 status = normalizeStatus(status) 82 _ = plpt.Set(FieldStatus, status, plast.String) 83 } 84 85 if filterByStatus(status, ignore) { 86 plpt.MarkDrop(true) 87 } 88 }