Some small improvements and refactoring.

This commit is contained in:
Johannes Findeisen 2023-02-22 16:55:06 +01:00
commit 7360ab1936
5 changed files with 11 additions and 36 deletions

View file

@ -0,0 +1,45 @@
"""
This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE.txt (MIT license).
"""
from fritzconnection.lib.fritzstatus import FritzStatus
from linspector.core.service import Service
def create(configuration, environment, log):
return IsConnectedService(configuration, environment, log)
class IsConnectedService(Service):
def __init__(self, configuration, environment, log):
super().__init__(configuration, environment, log)
self.__configuration = configuration
self.__environment = environment
self.__log = log
def execute(self, identifier, service, **kwargs):
self.__log.debug('identifier=' + identifier +
'service=' + service +
' object=' + str(self) +
' kwargs=' + str(kwargs))
try:
fc = FritzStatus(address=kwargs['host'],
password=kwargs['password'])
except Exception:
self.__log.error('identifier=' + identifier +
' host=' + str(kwargs['host']) +
' service=' + service +
' failed ')
return False
self.__log.info('identifier=' + identifier +
' host=' + str(kwargs['host']) +
' service=' + service +
' status=' + ('OK' if fc.is_connected else 'ERROR'))
if fc.is_connected:
return True
else:
return False