From ba38290e921b4727c00d6f40924b4c586655622a Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Tue, 24 May 2011 10:24:04 +0200 Subject: [PATCH] net: device type determination, handle IOError - handle the situation, when checked /path does not exist (bz #707079) --- monitorplugins/net.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/monitorplugins/net.py b/monitorplugins/net.py index fcd1a78..81c2eb4 100644 --- a/monitorplugins/net.py +++ b/monitorplugins/net.py @@ -52,15 +52,14 @@ class NetMonitor: return len(card.supported_modes) > 1 and card.get_max_speed() >= 1000 def _device_type(self, name): - path = os.path.join("/sys/class/net", name) - path = os.path.join(os.path.dirname(path), os.readlink(path)) - path = os.path.normpath(path) - try: + path = os.path.join("/sys/class/net", name) + path = os.path.join(os.path.dirname(path), os.readlink(path)) + path = os.path.normpath(path) devtype = re.match(r"/sys/devices/([^/]+)/", path).group(1) - except AttributeError: + except (IOError, AttributeError): devtype = "unknown" - log.warn("Cannot determine type of '%s' (%s)." % (name, path)) + log.warn("Cannot determine type of '%s'." % name) log.debug("Found network device: %s (%s)" % (name, devtype)) return devtype