#944·scrutiny

Backend will add invalid data to the database if smartctl returns a json-formatted error

Author: kaysondCreated Feb 27, 2026Updated Feb 28, 2026
Labelscontributor friendlygo

smartctl will return a non-zero exit code under a number of conditions, defined in their source here.

If the collector gets a non-zero exit code for a smartctl --xall, it will still send the data to the backend:

https://github.com/AnalogJ/scrutiny/blob/9d1ce790d0cad95820f8148af272114f7f5c22a9/collector/pkg/collector/metrics.go#L136-L143

which will happily unmarshall it into our model and push it (with a bunch of uninitialized struct fields) into the database:

https://github.com/AnalogJ/scrutiny/blob/9d1ce790d0cad95820f8148af272114f7f5c22a9/webapp/backend/pkg/web/handler/upload_device_metrics.go#L45-L51

We should update the exit_status field in our model to match the bitmask from the smartctl source:

https://github.com/AnalogJ/scrutiny/blob/9d1ce790d0cad95820f8148af272114f7f5c22a9/webapp/backend/pkg/models/collector/smart.go#L1-L11

and in the backend handler shown above, skip pushing data if any of bits 2-0 are set.

Note that some error codes are shared! Smartctl exits 2 for a variety of reasons including a drive being in standby.