Can't show inventory information on Hosted Mender

Hi there,

I’m experiencing very strange behavior with the inventory script below. (mycommand returns the following same JSON assigned to the vitals2 variable)


echo "vitals='${vitals}'"
echo "vitals='{\"\":{\"info\":{},\"last_status\":{\"free\":-1,\"usage\":-1}},\"cpu_info\":{\"info\":{},\"last_status\":{\"free\":77.29083251953125,\"usage\":22.709163665771484}},\"ext_comp_info\":{},\"firmware_info\":{\"info\":{\"version\":\"v2.0.1-rc13\"},\"last_status\":{}},\"hdd_info\":{\"info\":{\"brand\":\"M62704\",\"model\":\"none\",\"serial\":\"0x164db72c\"},\"last_status\":{\"free\":54.70341873168945,\"free_raw\":1955632,\"usage\":45.29658126831055,\"usage_raw\":1619340}},\"os_info\":{\"info\":{\"arch\":\"armv7l\",\"dist_info\":\"#1SMPPREEMPTTueJul222:57:18+032019\",\"endianness\":\"little\",\"kernel_version\":\"4.14.108-ti-r108\",\"machine_name\":\"centrisv2\"},\"last_status\":{}},\"ram_info\":{\"info\":{},\"last_status\":{\"free\":66.53024291992188,\"free_raw\":330980,\"usage\":33.46975326538086,\"usage_raw\":166508}},\"swap_info\":{\"info\":{},\"last_status\":{\"free\":null,\"free_raw\":0,\"usage\":null,\"usage_raw\":0}},\"thermal_info\":{\"info\":{},\"last_status\":{\"temperature\":0}},\"uptime_info\":{\"info\":{},\"last_status\":{\"currentEpoch\":1623409763653,\"deviceDate\":\"11.06.2021\",\"deviceTime\":\"14:09:23\",\"uptime\":\"2325739\"}}}'"

And here’s the script output and Mender screenshot.

So as you can see from the script, on the third line I get the command output and echo it, and on the next line, I copied the command output and assigned it to the vitals2 variable and echoed it as well. The script output is shown in the first image.

The issue is vitals variable shown empty on the Mender while vitals2 has the proper content.

Any ideas?

My best guess is that some kind of shell globbing, wildcarding, or other parsing is taking place resulting in odd behavior. I think there are bash options to turn those off which may help. But the first step I would take is to replace the complicated JSON string with just a simple “HELLOWORLD” string or some such and make sure everything works as expected, and then back into the JSON string to see if you can figure out which part of the string is causing the issue.

Have you checked that ‘mycommand’ is writing to stdout in case its actually outputting to stderr?

@drewmoseley thanks for the suggestion. Even disabling the globbing didn’t help at all. Also, it doesn’t matter if mycommand returns a simple JSON or the one in the example, it is not shown on the mender.

@dellgreen thanks for the comment. And yes I’m sure it writes to the stdout, not to the stderr.

What’s more interesting is, I encoded the JSON with base64 or base32 to prevent any special characters from bugging the system, but even in this case some of the content was missing on the mender. Sometimes half of the string arrives, and sometimes the last 4 or 5 characters.

Drives me mad.

can you share the version info for the client as server you are using, as its sounds like maybe something isn’t flushing its buffers correctly under certain conditions as its not content specific.

in the meantime you could play with the http api to test uploading inventory info as this would narrow the problem to whether its the client or server.

Mender client: fbed1ef runtime: go1.14.7
Mender host: v2.6.1

I’ll go through the http api :+1: