public inbox for collecty@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH] disk: Catch error for SMART devices w/o tmp sensors
@ 2016-10-19 20:55 Arne Fitzenreiter
  0 siblings, 0 replies; only message in thread
From: Arne Fitzenreiter @ 2016-10-19 20:55 UTC (permalink / raw)
  To: collecty

[-- Attachment #1: Type: text/plain, Size: 1295 bytes --]

Signed-off-by: Arne Fitzenreiter <arne_f(a)ipfire.org>
---
 src/_collecty/blockdev.c     | 8 +++++++-
 src/collecty/plugins/disk.py | 5 ++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

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():
-- 
2.6.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-19 20:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 20:55 [PATCH] disk: Catch error for SMART devices w/o tmp sensors Arne Fitzenreiter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox