StackExchange / wmi

WMI for Go
http://godoc.org/github.com/StackExchange/wmi
MIT License
433 stars 173 forks source link

add support for []uint8 slices #30

Closed martinlindhe closed 6 years ago

martinlindhe commented 7 years ago

Hello and thanks for a very useful lib! We have used it extensively in https://github.com/martinlindhe/wmi_exporter

I am currently implementing support for exporting SMART hdd data (disk health info), and they live in a byte array, so I have implemented support for parsing it in this pr.

I looked everywhere for another WMI class that had a byte array in order to provide a test, but I couldn't find any.

I have tested this on MSStorageDriver_ATAPISmartData, which needs admin rights to access, making testing even more troublesome.

Anyway, here's the code I used

type MSStorageDriver_ATAPISmartData struct {
    InstanceName    string
    Active          bool
    SelfTestStatus  uint64
    TotalTime       uint64
    SmartCapability uint64
    VendorSpecific  []uint8
}

func () grab() {
    var dst []MSStorageDriver_ATAPISmartData
    if err := wmi.QueryNamespace(wmi.CreateQuery(&dst, ""), &dst, `root\wmi`); err != nil {
        return nil, err
    }
}
chrisgraf commented 6 years ago

Hi, is there a reason why this pull request was not yet accepted? It would be great if someone could comment on this...

mnewswanger commented 6 years ago

I'm looking into this and should have some feedback later this week / early next

martinlindhe commented 6 years ago

Thank you, Mike!

mnewswanger commented 6 years ago

I'm building and deploying this into out infrastructure this week to do some canary testing for memory leaks (I don't see anything that looks concerning, but we want to make sure our users aren't negatively affected as best we can), and provided things look good there, I'll merge this into master and pull it into scollector as well.

mnewswanger commented 6 years ago

Thanks for the contribution @martinlindhe. This is merged into master and Bosun's scollector.