Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: parsing gelf levels to be human readable #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Expand Up @@ -20,6 +20,7 @@ type Config struct {
ValidateAllJSONTypes bool `config:"validate_all_json_types"`
JsonSchema map[string]string `config:"json_schema"`
Debug bool `config:"debug"`
ParseGelfLevels bool `config:"parse_gelf_levels"`
}

var DefaultConfig = Config{
Expand Down
28 changes: 24 additions & 4 deletions protolog/loglistener.go
Expand Up @@ -23,6 +23,17 @@ type LogListener struct {
logEntriesError chan bool
}

var gelfLevels = map[int32]string{
0: "emergency",
1: "alert",
2: "critical",
3: "error",
4: "warning",
5: "notice",
6: "info",
7: "debug",
}

func NewLogListener(cfg config.Config) *LogListener {
ll := &LogListener{
config: cfg,
Expand All @@ -46,10 +57,13 @@ func (ll *LogListener) Start(logEntriesRecieved chan common.MapStr, logEntriesEr

address := fmt.Sprintf("%s:%d", ll.config.Address, ll.config.Port)

if ll.config.Protocol == "tcp" {
ll.startTCP(ll.config.Protocol, address)
} else if ll.config.EnableGelf {
if ll.config.EnableGelf {
if ll.config.Protocol == "tcp" {
logp.Err("[protocol: tcp] has no affect together with enable_gelf, starting GELF listener")
}
ll.startGELF(address)
} else if ll.config.Protocol == "tcp" {
ll.startTCP(ll.config.Protocol, address)
} else {
ll.startUDP(ll.config.Protocol, address)
}
Expand Down Expand Up @@ -250,7 +264,13 @@ func (ll *LogListener) processGelfMessage(msg *gelf.Message) {
}
}

event["level"] = msg.Level
// Parse level to be human readable
if ll.config.ParseGelfLevels {
event["level"] = gelfLevels[msg.Level]
} else {
event["level"] = msg.Level
}

event["facility"] = msg.Facility
ll.logEntriesRecieved <- event

Expand Down
4 changes: 4 additions & 0 deletions protologbeat.full.yml
Expand Up @@ -10,6 +10,7 @@ protologbeat:
#port: 5000

# Protocol on which to listen
# This has no action if gelf is enabled
#protocol: udp

# Maxium message size in bytes
Expand All @@ -30,6 +31,9 @@ protologbeat:
# Set process to receive only GELF formated messages
#enable_gelf: false

# Parse gelf level to be human readable (6 => "info")
# parse_gelf_levels: false

# Enable json validation with schemas
#enable_json_validation: false

Expand Down