From 10f561d1ca417bf14c396d7cd169f4f40ec49b81 Mon Sep 17 00:00:00 2001 From: Peter Warasin Date: Mon, 27 Jun 2011 20:10:51 +0200 Subject: [PATCH] collectd_unixsock.py: Fix infinite wait. raise a KeyError if getval() or getthreshold() unixsock returns replies an error because of request of an unknown identifier Signed-off-by: Florian Forster --- contrib/collectd_unixsock.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/collectd_unixsock.py b/contrib/collectd_unixsock.py index ebe040d6..1b8e6b17 100644 --- a/contrib/collectd_unixsock.py +++ b/contrib/collectd_unixsock.py @@ -68,8 +68,9 @@ class Collectd(): """ numvalues = self._cmd('GETTHRESHOLD "%s"' % identifier) lines = [] - if numvalues: - lines = self._readlines(numvalues) + if not numvalues or numvalues < 0: + raise KeyError("Identifier '%s' not found" % identifier) + lines = self._readlines(numvalues) return lines def getval(self, identifier, flush_after=True): @@ -83,8 +84,9 @@ class Collectd(): """ numvalues = self._cmd('GETVAL "%s"' % identifier) lines = [] - if numvalues: - lines = self._readlines(numvalues) + if not numvalues or numvalues < 0: + raise KeyError("Identifier '%s' not found" % identifier) + lines = self._readlines(numvalues) if flush_after: self.flush(identifiers=[identifier]) return lines -- 2.11.0