From 802ad69781167c3eab5e61dd62a303a0336f9e9a Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 22 Aug 2023 00:31:44 +0200 Subject: [PATCH] Added more fields to MySQL module. (0.25.1) --- bin/linspector | 2 +- linspector/databases/mysql.py | 14 +++++++++----- linspector/monitor.py | 4 +++- linspector/services/vendor/avm/is_connected.py | 7 +++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/linspector b/bin/linspector index c53966c..78b1673 100755 --- a/bin/linspector +++ b/bin/linspector @@ -19,7 +19,7 @@ from linspector.environment import Environment from linspector.linspector import Linspector from linspector.monitors import Monitors -__version__ = '0.25.0' +__version__ = '0.25.1' __author__ = 'Johannes Findeisen ' diff --git a/linspector/databases/mysql.py b/linspector/databases/mysql.py index 1797be3..64b8649 100644 --- a/linspector/databases/mysql.py +++ b/linspector/databases/mysql.py @@ -47,7 +47,7 @@ class MySQLDatabase(Database): except Exception as err: log.warning('database configuration error: {0}'.format(err)) - def insert(self, identifier, json, message, status, timestamp): + def insert(self, host, identifier, json, message, service, status, timestamp): try: self._connection = pymysql.connect(cursorclass=pymysql.cursors.DictCursor, database=self._database, @@ -62,16 +62,20 @@ class MySQLDatabase(Database): with (self._connection): with self._connection.cursor() as cursor: sql = 'INSERT INTO ' + self._table + ' (' \ + 'host, ' \ 'identifier, ' \ 'json, ' \ 'message, ' \ + 'service, ' \ 'status, ' \ 'timestamp ' \ ') VALUES (\"' + \ - str(identifier) + '\",\"' + \ - str(json) + '\",\"' + \ - str(message) + '\",\"' + \ - str(status) + '\",\"' + \ + str((host if host else "None")) + '\",\"' + \ + str((identifier if identifier else "None")) + '\",\"' + \ + str((json if json else "None")) + '\",\"' + \ + str((message if message else "None")) + '\",\"' + \ + str((service if service else "None")) + '\",\"' + \ + str((status if status else "None")) + '\",\"' + \ str(timestamp) + '\")' self._log.debug(sql) cursor.execute(sql) diff --git a/linspector/monitor.py b/linspector/monitor.py index 2830e76..4630714 100644 --- a/linspector/monitor.py +++ b/linspector/monitor.py @@ -125,9 +125,11 @@ class Monitor: self._log.debug(self._databases) for database in self._databases: - self._databases[database].insert(self._identifier, + self._databases[database].insert(self._result['host'], + self._identifier, self._result, self._result['message'], + self._result['service'], self._result['status'], int(time.time())) diff --git a/linspector/services/vendor/avm/is_connected.py b/linspector/services/vendor/avm/is_connected.py index d8bc191..269c9d9 100644 --- a/linspector/services/vendor/avm/is_connected.py +++ b/linspector/services/vendor/avm/is_connected.py @@ -35,8 +35,11 @@ class IsConnectedService(Service): ' service=' + service + ' status=' + ('OK' if fc.is_connected else 'ERROR')) - result = {"status": ('OK' if fc.is_connected else 'ERROR'), + result = {"host": monitor.get_host(), + "message": "Uplink on host " + monitor.get_host() + " " + - ('UP' if fc.is_connected else 'DOWN')} + ('UP' if fc.is_connected else 'DOWN'), + "service": service, + "status": ('OK' if fc.is_connected else 'ERROR')} return result