Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while fetching bios info in windows 10. #189

Closed
sandeep1-0 opened this issue May 18, 2020 · 23 comments
Closed

Issue while fetching bios info in windows 10. #189

sandeep1-0 opened this issue May 18, 2020 · 23 comments

Comments

@sandeep1-0
Copy link

Metricbeat failing to fetch bios info. Getting the following error while tried to fetch those.

020-05-18T20:53:53.604+0530 DEBUG [module] module/wrapper.go:154 Starting metricSetWrapper[module=system, name=asset, host=]

Error getting BIOS info: wmi: cannot load field "InstallDate" into a "string": unsupported type ()2020-05-18T20:53:53.946+0530 DEBUG [module] runtime/panic.go:969 Stopped metricSetWrapper[module=system, name=asset, host=]
2020-05-18T20:53:53.946+0530 ERROR runtime/signal_windows.go:246 recovered from panic while fetching 'system/asset' for host ''. Recovering, but please report this: runtime error: invalid memory address or nil pointer dereference. {"stack": "github.com/elastic/beats/libbeat/logp.Recover\n\tG:/go/src/github.com/elastic/beats/libbeat/logp/global.go:88\nruntime.gopanic\n\tc:/go/src/runtime/panic.go:969\nruntime.panicmem\n\tc:/go/src/runtime/panic.go:212\nruntime.sigpanic\n\tc:/go/src/runtime/signal_windows.go:246\ngithub.51.al/elastic/beats/metricbeat/module/system/asset.ProdInfo\n\tG:/go/src/github.com/elastic/beats/metricbeat/module/system/asset/asset_func.go:160\ngithub.51.al/elastic/beats/metricbeat/module/system/asset.(*MetricSet).Fetch\n\tG:/go/src/github.com/elastic/beats/metricbeat/module/system/asset/asset.go:62\ngithub.51.al/elastic/beats/metricbeat/mb/module.(*metricSetWrapper).multiEventFetch\n\tG:/go/src/github.com/elastic/beats/metricbeat/mb/module/wrapper.go:227\ngithub.51.al/elastic/beats/metricbeat/mb/module.(*metricSetWrapper).fetch\n\tG:/go/src/github.com/elastic/beats/metricbeat/mb/module/wrapper.go:207\ngithub.51.al/elastic/beats/metricbeat/mb/module.(*metricSetWrapper).startPeriodicFetching\n\tG:/go/src/github.com/elastic/beats/metricbeat/mb/module/wrapper.go:184\ngithub.51.al/elastic/beats/metricbeat/mb/module.(*metricSetWrapper).run\n\tG:/go/src/github.com/elastic/beats/metricbeat/mb/module/wrapper.go:171\ngithub.51.al/elastic/beats/metricbeat/mb/module.(*Wrapper).Start.func1\n\tG:/go/src/github.com/elastic/beats/metricbeat/mb/module/wrapper.go:112"}
2020-05-18T20:53:53.947+0530 DEBUG [module] module/wrapper.go:120 Stopped Wrapper[name=system, len(metricSetWrappers)=1]
2020-05-18T20:53:58.527+0530 DEBUG [service] service/service.go:33 Received sigterm/sigint, stopping
2020-05-18T20:53:58.527+0530 DEBUG [service] service/service.go:39 Received svc stop/shutdown request
2020-05-18T20:53:58.528+0530 INFO instance/beat.go:308 metricbeat stopped.
2020-05-18T20:53:58.667+0530 INFO [monitoring] log/log.go:132 Total non-zero metrics {"monitoring": {"metrics": {"beat":{"cpu":{"system":{"ticks":218,"time":218},"total":{"ticks":358,"time":358,"value":358},"user":{"ticks":140,"time":140}},"info":{"ephemeral_id":"30e22451-2f46-4833-9d41-64017cad3489","uptime":{"ms":8160}},"memstats":{"gc_next":4194304,"memory_alloc":2410544,"memory_total":4124872,"rss":24899584}},"libbeat":{"config":{"module":{"running":0}},"output":{"type":"file"},"pipeline":{"clients":0,"events":{"active":0}}},"system":{"cpu":{"cores":4}}}}}
2020-05-18T20:53:58.668+0530 INFO [monitoring] log/log.go:133 Uptime: 8.2992701s
2020-05-18T20:53:58.668+0530 INFO [monitoring] log/log.go:110 Stopping metrics logging.

@sandeep1-0
Copy link
Author

The code works fine when i run it seperate.

@jaypipes
Copy link
Owner

@sandeep1-0 I don't see that you are using the ghw library. The above stacktrace shows only metricbeat modules.

@sandeep1-0
Copy link
Author

Error getting BIOS info: wmi: cannot load field "InstallDate" into a "string": unsupported type ()2020-05-18T20:53:53.946+0530 DEBUG

It's returning null

@jaypipes
Copy link
Owner

@sandeep1-0 can you please post the code that you are running that is producing your error? Thanks!

@sandeep1-0
Copy link
Author

sandeep1-0 commented May 20, 2020

func ProdInfo() map[string]interface{} {
	var proddict map[string]interface{}
	product, err := ghw.Product()
	if err != nil {
		fmt.Printf("Error getting product info: %v", err)
	}
	proddict = make(map[string]interface{})
	prod_model := product.Family
	proddict["prod_model"] = prod_model
	return proddict
}

Error getting product info: wmi: cannot load field "SKUNumber" into a "string": unsupported type (<nil>)2020-05-20T08:21:00.769+0530

Now this is the error im getting. As i said when running individually it works fine.

@jaypipes
Copy link
Owner

@sandeep1-0 OK, thank you! I will push up a fix soon.

@sandeep1-0
Copy link
Author

Ok thanks @jaypipes

jaypipes added a commit that referenced this issue May 21, 2020
The github.com/StackExchange/wmi package is great, but handles nil
results from the WMI/WQL call *only* if the type in the receiving struct
is a pointer type:

https://github.com/StackExchange/wmi/blob/cbe66965904dbe8a6cd589e2298e5d8b986bd7dd/wmi.go#L420-L426

So, for various fields (all strings that I can gather so far) that on
*some* systems return nil type from WMI, I've made the fields in the
receiver structs *string instead of string. This should allow nil-types
to be properly handled and not run into the `unsupported type (<nil>)`
issue faced in Issue #189

Closes Issue #189
@jaypipes jaypipes added this to the v1.0.0 milestone May 21, 2020
jaypipes added a commit that referenced this issue May 21, 2020
The github.com/StackExchange/wmi package is great, but handles nil
results from the WMI/WQL call *only* if the type in the receiving struct
is a pointer type:

https://github.com/StackExchange/wmi/blob/cbe66965904dbe8a6cd589e2298e5d8b986bd7dd/wmi.go#L420-L426

So, for various fields (all strings that I can gather so far) that on
*some* systems return nil type from WMI, I've made the fields in the
receiver structs *string instead of string. This should allow nil-types
to be properly handled and not run into the `unsupported type (<nil>)`
issue faced in Issue #189

Closes Issue #189
@jaypipes
Copy link
Owner

@sandeep1-0 I've merged a fix for this issue. Would you mind pulling the latest code and checking to see if your issue is addressed?

@sandeep1-0
Copy link
Author

Error getting block storage info: wmi: cannot load field "DefaultBlockSize" into a "uint64": unsupported type ()2020-05-22T10:38:06.704+0530

Thanks for your concern but still I'm facing the issue.

@jaypipes
Copy link
Owner

jaypipes commented May 22, 2020

Hmm, looks like non-string receiver fields also need to be nil-safe... you'd think that WMI would not return a <nil> value for something like DefaultBlockSize... :( OK, will push another patch later today.

jaypipes added a commit that referenced this issue May 23, 2020
Apparently WMI will return `<nil>` type even for integer fields like
DefaultBlockSize :(

Issue #189
jaypipes added a commit that referenced this issue May 23, 2020
Apparently WMI will return `<nil>` type even for integer fields like
DefaultBlockSize :(

Issue #189
@jaypipes
Copy link
Owner

@sandeep1-0 OK, please check the latest version. I changed the WMI receiver field types to all pointers. This should fix you.

@sandeep1-0
Copy link
Author

Still the same.
Error getting block storage info: wmi: cannot load field "DefaultBlockSize" into a "uint64": unsupported type (<nil>)2020-05-25T09:34:49.104+0530

@jaypipes
Copy link
Owner

@sandeep1-0 please ensure you are pulling the v0.6.1 release in your go.mod:

https://github.com/jaypipes/ghw/releases/tag/v0.6.1

@jaypipes jaypipes removed this from the v1.0.0 milestone May 26, 2020
@sandeep1-0
Copy link
Author

Yes i downloaded that source code and put it in the library still same error i'm getting. Will this work if we pass some default values for all.

@jaypipes
Copy link
Owner

@sandeep1-0 I don't know what you mean by "pass some default values for all". Could you elaborate? The default values for pointer types is 0.

Maybe you could post the exact code that you are running and some more details about the environment you are running it in? What version of Golang? What version of Windows? If you run the ghwc command line client, what is the output?

@sandeep1-0
Copy link
Author

go version : go version go1.14.2 windows/amd64
windows : Windows 10 Enterprise

I have created a new module for metricbeat which fetches all the system data like hard-disk details, system details etc. If you have metricbeat available i have attached the code.
asset.zip

@jaypipes
Copy link
Owner

@sandeep1-0 it's working perfectly fine for me.

Here's what I did:

  1. Downloaded your code
  2. Moved asset_func.go to C:\Users\jaypip\go\src\github.com/\jaypipes\test189\asset_func.go
  3. Changed the package name from asset to main and added the following to the asset_func.go file:
func main() {                                                                                                                                                                                                                                                                          
    fmt.Printf("%+v\n", HDInfo())                                                                                                                                                                                                                                        }   

I then executed it and everything worked fine:

PS C:\Users\jaypi\go\src\github.com\jaypipes\test189> vim .\asset_func.go
PS C:\Users\jaypi\go\src\github.com\jaypipes\test189> go run .\asset_func.go
go: finding github.com/jaypipes/ghw v0.6.1
go: downloading github.com/jaypipes/ghw v0.6.1
go: extracting github.com/jaypipes/ghw v0.6.1
map[hardisk1 controller:SCSI hardisk1 is_removable:false hardisk1 model:Samsung SSD 970 EVO 250GB hardisk1 name:\\.\PHYSICALDRIVE1 hardisk1 serial_number:0025_385B_81B2_2158. hardisk1 size:250056737280 hardisk1 type:SSD hardisk1 vendor:(Standard disk drives) hardisk2 controller:IDE hardisk2 is_removable:false hardisk2 model:Samsung SSD 860 EVO 1TB hardisk2 name:\\.\PHYSICALDRIVE0 hardisk2 serial_number:S3Z6NB0KC05827V hardisk2 size:1000202273280 hardisk2 type:SSD hardisk2 vendor:(Standard disk drives)]

I suspect you are caching an old version of the ghw library because you are not using a pinned go mod to at the v0.6.1 release tag.

@sandeep1-0
Copy link
Author

Yeah it worked that way. Can you help me understand what could be the problem there.

@jaypipes
Copy link
Owner

Hey again, @sandeep1-0. Sorry for the delayed response. Did you get your code working? I suspect all you needed to do was ensure that you were building your metricbeat plugin with a go.mod that referenced a version of the ghw library at tag v1.6.0. Is that right?

@sandeep1-0
Copy link
Author

Yes. I have moved the code like you mentioned earlier it's works perfectly fine. I don't understand the go.mod what you have mentioned. So where should I change those inorder to make my code works as it was before?

@sandeep1-0
Copy link
Author

Sorry for that I am new to go and I have only basic ideas to solve the problem. Thanks for your library and help it made my work so much easier.

@jaypipes
Copy link
Owner

Sorry for that I am new to go and I have only basic ideas to solve the problem. Thanks for your library and help it made my work so much easier.

No need to apologize, Sandeep :) So, when you use code from a Go library (like ghw), on modern Go platforms much of the tooling for managing Go module versions and dependencies is done using the go.mod file. You can specify a particular version of a library dependency in your own code by using the go mod edit command from your code's root source directory once you've initialized go module support with the go mod init command:

go mod init <NAME OF YOUR PACKAGE>

if you then do a go mod download:

go mod download

you will see Go pull down the latest versions of any libraries referenced in your own code.

After some time, you might need to bring in an updated version of once of your library dependencies. An example would be ghw which you needed to bring in the version v0.6.1 in order to address the <nil> WMI type thing...

You would do that by:

go mod edit -require github.com/jaypipes/ghw@v0.6.1

Best,
-jay

@sandeep1-0
Copy link
Author

Thank you jay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants