disk: Catch error for SMART devices w/o tmp sensors
authorArne Fitzenreiter <arne_f@ipfire.org>
Wed, 19 Oct 2016 20:55:23 +0000 (20:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2016 21:51:37 +0000 (22:51 +0100)
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_collecty/blockdev.c
src/collecty/plugins/disk.py

index 2c715b9..09d3994 100644 (file)
@@ -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);
index 1b12c5c..a822eb2 100644 (file)
@@ -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():