Added error count to database and more logging. (0.28.3)

This commit is contained in:
Johannes Findeisen 2023-09-03 06:51:04 +02:00
commit 4936bc68a7
4 changed files with 10 additions and 5 deletions

View file

@ -20,7 +20,7 @@ from linspector.environment import Environment
from linspector.linspector import Linspector
from linspector.monitors import Monitors
__version__ = '0.28.2'
__version__ = '0.28.3'
__author__ = 'Johannes Findeisen <you@hanez.org>'
sys.stderr = open('/dev/null', 'w')

View file

@ -143,7 +143,7 @@ class Linspector:
monitor_count += 1
print('Number of monitors scheduled: ' + str(monitor_count))
print('Number of scheduled monitors: ' + str(monitor_count))
if configuration.get_option('linspector', 'start_scheduler') == 'true':
self._scheduler['linspector'].start()

View file

@ -114,7 +114,8 @@ class Monitor:
def execute(self):
self._log.debug('identifier=' + self._identifier + ' object=' + str(self))
self._log.debug('identifier=' + self._identifier + ' message=handle call to service')
self._log.debug('identifier=' + self._identifier + ' kwargs=' + str(self._args) +
' message=handle call to service')
if self._enabled:
try:
@ -124,10 +125,12 @@ class Monitor:
if self._result['status'] == 'ERROR':
self._error_count += 1
self._log.debug('error count: ' + str(self._error_count))
self._log.debug(self._result)
self._log.debug(self._tasks)
for task in self._tasks:
self._tasks[task].execute(self._result['host'],
self._tasks[task].execute(self._error_count,
self._result['host'],
self._identifier,
self._result,
self._result['log'],

View file

@ -48,7 +48,7 @@ class MySQLTask(Task):
except Exception as err:
log.error('task mysql configuration error: {0}'.format(err))
def execute(self, host, identifier, json, log, service, status, timestamp):
def execute(self, error_count, host, identifier, json, log, service, status, timestamp):
try:
self._connection = pymysql.connect(cursorclass=pymysql.cursors.DictCursor,
database=self._database,
@ -63,6 +63,7 @@ class MySQLTask(Task):
with (self._connection):
with self._connection.cursor() as cursor:
sql = 'INSERT INTO ' + self._table + ' (' \
'error_count, ' \
'host, ' \
'identifier, ' \
'json, ' \
@ -71,6 +72,7 @@ class MySQLTask(Task):
'status, ' \
'timestamp ' \
') VALUES (\"' + \
str((error_count if error_count else '0')) + '\",\"' + \
str((host if host else 'None')) + '\",\"' + \
str((identifier if identifier else 'None')) + '\",\"' + \
str((json if json else 'None')) + '\",\"' + \