From: Arne Fitzenreiter Date: Wed, 19 Oct 2016 20:55:23 +0000 (+0000) Subject: disk: Catch error for SMART devices w/o tmp sensors X-Git-Url: http://git.ipfire.org/?p=collecty.git;a=commitdiff_plain;h=60b179c1c176f4e9efcf8db988b2b79d0fe206da disk: Catch error for SMART devices w/o tmp sensors Signed-off-by: Arne Fitzenreiter Signed-off-by: Michael Tremer --- diff --git a/src/_collecty/blockdev.c b/src/_collecty/blockdev.c index 2c715b9..09d3994 100644 --- a/src/_collecty/blockdev.c +++ b/src/_collecty/blockdev.c @@ -296,8 +296,14 @@ PyObject* BlockDevice_get_temperature(PyObject* self) { uint64_t mkelvin; int r = sk_disk_smart_get_temperature(device->disk, &mkelvin); - if (r) + if (r) { + // Temperature not available but SMART is supported + if (errno == ENOENT) { + PyErr_Format(PyExc_OSError, "Device does not have a temperature"); + } + return NULL; + } // Convert the temperature to Kelvin return PyFloat_FromDouble((double)mkelvin / 1000.0); diff --git a/src/collecty/plugins/disk.py b/src/collecty/plugins/disk.py index 1b12c5c..a822eb2 100644 --- a/src/collecty/plugins/disk.py +++ b/src/collecty/plugins/disk.py @@ -267,7 +267,10 @@ class DiskObject(base.Object): if not self.is_smart_supported(): return "NaN" - return self.device.get_temperature() + try: + return self.device.get_temperature() + except OSError: + return "NaN" def get_bad_sectors(self): if not self.is_smart_supported():