diff --git a/winlogbeat/sys/wineventlog/publisher_metadata.go b/winlogbeat/sys/wineventlog/publisher_metadata.go index 2e5ed2411c5..50b574ca5cf 100644 --- a/winlogbeat/sys/wineventlog/publisher_metadata.go +++ b/winlogbeat/sys/wineventlog/publisher_metadata.go @@ -198,11 +198,10 @@ func NewMetadataKeyword(publisherMetadataHandle EvtHandle, arrayHandle EvtObject if err != nil { return nil, err } - messageID := v.(uint32) - - // The value is -1 if the keyword did not specify a message attribute. + messageID, ok := v.(uint32) var message string - if int32(messageID) != -1 { + // The value is -1 if the keyword did not specify a message attribute. + if ok { message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId) if err != nil { return nil, err @@ -271,11 +270,10 @@ func NewMetadataOpcode(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectA if err != nil { return nil, err } - messageID := v.(uint32) - + messageID, ok := v.(uint32) // The value is -1 if the opcode did not specify a message attribute. var message string - if int32(messageID) != -1 { + if ok { message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId) if err != nil { return nil, err @@ -344,11 +342,10 @@ func NewMetadataLevel(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectAr if err != nil { return nil, err } - messageID := v.(uint32) - + messageID, ok := v.(uint32) // The value is -1 if the level did not specify a message attribute. var message string - if int32(messageID) != -1 { + if ok { message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId) if err != nil { return nil, err @@ -418,11 +415,10 @@ func NewMetadataTask(publisherMetadataHandle EvtHandle, arrayHandle EvtObjectArr if err != nil { return nil, err } - messageID := v.(uint32) - + messageID, ok := v.(uint32) // The value is -1 if the task did not specify a message attribute. var message string - if int32(messageID) != -1 { + if ok { message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId) if err != nil { return nil, err @@ -499,11 +495,10 @@ func NewMetadataChannel(publisherMetadataHandle EvtHandle, arrayHandle EvtObject if err != nil { return nil, err } - messageID := v.(uint32) - - // The value is -1 if the task did not specify a message attribute. + messageID, ok := v.(uint32) + // The value is -1 if the channel did not specify a message attribute. var message string - if int32(messageID) != -1 { + if ok { message, err = evtFormatMessage(publisherMetadataHandle, NilHandle, messageID, nil, EvtFormatMessageId) if err != nil { return nil, err