Browse Source

robustesse erreur de connection check_mk

Élie Bouttier 7 years ago
parent
commit
78eb5bc644
1 changed files with 14 additions and 10 deletions
  1. 14 10
      djadhere/utils.py

+ 14 - 10
djadhere/utils.py

@@ -101,14 +101,18 @@ def from_livestatus(get, query=[], columns=[]):
     else:
         Line = None
     lines = []
-    with socket.create_connection(("nucnagios.tetaneutral.net", "8622")) as sock:
-        sock.send(query.encode('utf-8'))
-        sock.shutdown(socket.SHUT_WR)
-        infile = sock.makefile(encoding='utf-8')
-        data = json.load(infile)
-    for entry in data:
-        if not Line:
-            Line = namedtuple(get.capitalize(), entry)
-            continue
-        lines.append(Line(*entry))
+    try:
+        with socket.create_connection(("nucnagios.tetaneutral.net", "8622")) as sock:
+            sock.send(query.encode('utf-8'))
+            sock.shutdown(socket.SHUT_WR)
+            infile = sock.makefile(encoding='utf-8')
+            data = json.load(infile)
+    except ConnectionResetError:
+        pass
+    else:
+        for entry in data:
+            if not Line:
+                Line = namedtuple(get.capitalize(), entry)
+                continue
+            lines.append(Line(*entry))
     return lines