Skip to content

Commit

Permalink
Add an explicit variable for the converted field and double check if …
Browse files Browse the repository at this point in the history
…the cast is safe
  • Loading branch information
herrBez committed Jan 30, 2025
1 parent f766c51 commit e076caa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion metricbeat/module/windows/wmi/wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
conversionTable[fieldName] = convertFun
}
// Perform the conversion at this point it's safe to cast to string.
convertedValue, err := convertFun(fieldValue.(string))
fieldValueString, ok := fieldValue.(string)
if !ok {
m.Logger().Warn("Skipping addition of field %s: it's expected to be a string found %v", fieldName, fieldValue)
continue
}
convertedValue, err := convertFun(fieldValueString)
if err != nil {
m.Logger().Warn("Skipping addition of field %s. Cannot convert: %v", fieldName, err)
continue
Expand Down

0 comments on commit e076caa

Please sign in to comment.