|
@@ -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):
|