Initialize event vars before using them

This commit is contained in:
Blerim Sheqa 2017-10-18 09:41:03 +02:00
parent 5b6e720df5
commit 33d384bca8
2 changed files with 5 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/icinga/icingabeat/config"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
@ -47,6 +48,7 @@ func BuildEventstreamEvent(e []byte) beat.Event {
}
event.Timestamp = time.Now()
event.Fields = common.MapStr{}
for key, value := range icingaEvent {
event.Fields.Put(key, value)

View File

@ -11,6 +11,7 @@ import (
"github.com/icinga/icingabeat/config"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
@ -45,6 +46,8 @@ func BuildStatusEvents(body []byte) []beat.Event {
for _, status := range result.([]interface{}) {
var event beat.Event
event.Fields = common.MapStr{}
event.Timestamp = time.Now()
for key, value := range status.(map[string]interface{}) {
switch key {
@ -53,7 +56,6 @@ func BuildStatusEvents(body []byte) []beat.Event {
switch statusvalue.(type) {
case map[string]interface{}:
if len(statusvalue.(map[string]interface{})) > 0 {
event.Fields.Put(key, value)
}
@ -88,7 +90,6 @@ func BuildStatusEvents(body []byte) []beat.Event {
}
if statusAvailable, _ := event.Fields.HasKey("status"); statusAvailable == true {
event.Timestamp = time.Now()
statusEvents = append(statusEvents, event)
}
}