Code

collectd_unixsock.py: Fix infinite wait.
authorPeter Warasin <peter@endian.com>
Mon, 27 Jun 2011 18:10:51 +0000 (20:10 +0200)
committerFlorian Forster <octo@collectd.org>
Mon, 22 Aug 2011 16:51:57 +0000 (18:51 +0200)
raise a KeyError if getval() or getthreshold() unixsock returns replies an
error because of request of an unknown identifier

Signed-off-by: Florian Forster <octo@collectd.org>
contrib/collectd_unixsock.py

index ebe040d6a11846ab77fe446112668e29354f904f..1b8e6b174ed8d8ad1a7abc1237842e03d5908075 100644 (file)
@@ -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