Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Fixes panic issue when dealing with events (#85)
Browse files Browse the repository at this point in the history
* Fixed panic when parsing events for alerts

* Fix gofmt issues

* Fixed panic when parsing events for alerts (#84)

Co-authored-by: Leif Madsen <lmadsen@redhat.com>

Co-authored-by: Aneesh Puttur <aneeshputtur@gmail.com>
  • Loading branch information
leifmadsen and aneeshkp authored May 12, 2020
1 parent ac6bb96 commit 53c1f1d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/pkg/events/incoming/collectd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (evt *CollectdEvent) ParseEvent(data string) error {

//assimilateMap recursively saves content of the given map to destination map of strings
func assimilateMap(theMap map[string]interface{}, destination *map[string]string) {
defer func() { //recover from any panic
if r := recover(); r != nil {
log.Printf("Panic:recovered in assimilateMap %v\n", r)
}
}()
for key, val := range theMap {
switch value := val.(type) {
case map[string]interface{}:
Expand All @@ -102,6 +107,10 @@ func assimilateMap(theMap map[string]interface{}, destination *map[string]string
}
}
(*destination)[key] = strings.Join(aList, ",")
case float64, float32:
(*destination)[key] = fmt.Sprintf("%f", value)
case int:
(*destination)[key] = fmt.Sprintf("%d", value)
default:
// assimilate KV pair
(*destination)[key] = value.(string)
Expand Down

0 comments on commit 53c1f1d

Please sign in to comment.