Added some stuff to the misc.dummy and misc.random service for testing. (0.21.4)

This commit is contained in:
Johannes Findeisen 2023-02-24 16:42:51 +01:00
commit 6a5fd9041c
4 changed files with 40 additions and 12 deletions

View file

@ -33,11 +33,14 @@ help:
# ------------------------------
# make daemon
daemon:
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VRESION)/site-packages/ bin/linspector -d ./etc
follow:
tail -F ./log/linspector.log
run:
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector ./etc
rundev:
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector ./etc.test.local
daemon:
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VRESION)/site-packages/ bin/linspector -d ./etc

View file

@ -18,7 +18,7 @@ from linspector.environment import Environment
from linspector.linspector import Linspector
from linspector.monitors import Monitors
__version__ = '0.21.3'
__version__ = '0.21.4'
__author__ = 'Johannes Findeisen <you@hanez.org>'

View file

@ -17,7 +17,9 @@ class DummyService(Service):
self.__environment = environment
self.__log = log
def execute(self, **kwargs):
self.__log.debug('DummyService object ' + str(self) + ' using kwargs: ' + str(kwargs))
# log('debug', 'dummy object @' + str(self) + str(self.__kwargs['foo']))
return
def execute(self, identifier, monitor, service, **kwargs):
self.__log.info('identifier=' + identifier +
' host=' + monitor.get_host() +
' service=' + service +
' status=' + 'OK')
return True

View file

@ -3,19 +3,42 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license).
"""
import hashlib
import random
from linspector.service import Service
def create(configuration, environment, log):
return RandomService(configuration, environment, log)
return DummyService(configuration, environment, log)
class RandomService(Service):
class DummyService(Service):
def __init__(self, configuration, environment, log):
super().__init__(configuration, environment, log)
self.__configuration = configuration
self.__environment = environment
self.__log = log
def execute(self, **kwargs):
return
def execute(self, identifier, monitor, service, **kwargs):
result = random.randint(0, 1)
rnd1 = random.randint(0, 99999999999999)
rnd2 = random.randint(0, 99999999999999)
rnd3 = random.randint(0, 99999999999999)
rnd4 = random.randint(0, 99999999999999)
rnd5 = random.randint(0, 99999999999999)
rnd6 = random.randint(0, 99999999999999)
rnd7 = random.randint(0, 99999999999999)
rnd8 = random.randint(0, 99999999999999)
sha512_1 = hashlib.sha512(str((str(rnd1) + str(rnd2) + str(rnd3) + str(rnd4) +
str(rnd5) + str(rnd6) + str(rnd7) + str(rnd8))).
encode('utf-8')).hexdigest()
sha512_2 = hashlib.sha512(str((str(rnd1) + str(rnd2) + str(rnd3) + str(rnd4) +
str(rnd5) + str(rnd6) + str(rnd7) + str(rnd8) + str(sha512_1))).
encode('utf-8')).hexdigest()
self.__log.info('identifier=' + identifier +
' host=' + monitor.get_host() +
' service=' + service +
' status=' + ('OK' if result == 0 else 'ERROR') + ' sha512=' +
sha512_2)
return True