Browse Source

fetchping: factorisation from_livestatus

Élie Bouttier 7 years ago
parent
commit
c2a8ae4ff6
1 changed files with 1 additions and 22 deletions
  1. 1 22
      services/management/commands/fetchping.py

+ 1 - 22
services/management/commands/fetchping.py

@@ -7,28 +7,7 @@ from collections import namedtuple
 from itertools import groupby
 
 from services.models import IPResource
-
-
-def from_livestatus(get, query=[], columns=[]):
-    query = ['GET %s' % get]
-    if columns:
-        query += ["Columns: " + ' '.join(columns)]
-    query = ''.join(map(lambda s: s + '\n', query))
-    if columns:
-        Line = namedtuple(get.capitalize(), 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')
-        for row in csv.reader(infile, delimiter=';'):
-            if not Line:
-                Line = namedtuple(get.capitalize(), row)
-                continue
-            lines.append(Line(*row))
-    return lines
+from djadhere.utils import from_livestatus
 
 
 class Command(BaseCommand):