From 7360ab1936f1b4efea92209709ec2928cd58f040 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 22 Feb 2023 16:55:06 +0100 Subject: [PATCH] Some small improvements and refactoring. --- bin/linspector | 2 +- etc/monitors/network1/gateway.conf | 2 +- etc/monitors/network2/gateway.conf | 2 +- .../services/net/fritzboxphonestatus.py | 23 ------------------- .../avm/is_connected.py} | 18 +++++++-------- 5 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 linspector/services/net/fritzboxphonestatus.py rename linspector/services/{net/fritzboxuplink.py => vendor/avm/is_connected.py} (81%) diff --git a/bin/linspector b/bin/linspector index cce908e..d5c6977 100755 --- a/bin/linspector +++ b/bin/linspector @@ -16,7 +16,7 @@ from linspector.core.linspector import Linspector from linspector.core.logger import Log from linspector.core.monitors import Monitors -__version__ = '0.20.1' +__version__ = '0.20.2' __author__ = 'Johannes Findeisen ' diff --git a/etc/monitors/network1/gateway.conf b/etc/monitors/network1/gateway.conf index ab89407..561913e 100644 --- a/etc/monitors/network1/gateway.conf +++ b/etc/monitors/network1/gateway.conf @@ -1,7 +1,7 @@ [monitor] title = Uplink Status description = Cable Provider Uplink Status -service = net.fritzboxuplink +service = vendor.avm.is_connected ; this is obsolete because the host will become part of the args but removing it now will break the code. linspector ; should be for checking local or remote stuff so a host is optional. hosts = 192.168.1.1 diff --git a/etc/monitors/network2/gateway.conf b/etc/monitors/network2/gateway.conf index e421bf7..4d58652 100644 --- a/etc/monitors/network2/gateway.conf +++ b/etc/monitors/network2/gateway.conf @@ -1,7 +1,7 @@ [monitor] title = Uplink Status description = DSL Provider Uplink Status -service = net.fritzboxuplink +service = vendor.avm.is_connected hosts = 192.168.2.1 [args] diff --git a/linspector/services/net/fritzboxphonestatus.py b/linspector/services/net/fritzboxphonestatus.py deleted file mode 100644 index 8c5b71c..0000000 --- a/linspector/services/net/fritzboxphonestatus.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. -See LICENSE.txt (MIT license). -""" - -from linspector.core.service import Service - - -def create(configuration, environment, log): - return FritzboxPhoneStatusService(configuration, environment, log) - - -class FritzboxPhoneStatusService(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): - self.__log.debug('FritzboxPhoneStatusService object ' + str(self)) - return diff --git a/linspector/services/net/fritzboxuplink.py b/linspector/services/vendor/avm/is_connected.py similarity index 81% rename from linspector/services/net/fritzboxuplink.py rename to linspector/services/vendor/avm/is_connected.py index 41b7cab..57ff4d7 100644 --- a/linspector/services/net/fritzboxuplink.py +++ b/linspector/services/vendor/avm/is_connected.py @@ -9,10 +9,10 @@ from linspector.core.service import Service def create(configuration, environment, log): - return FritzboxUplinkService(configuration, environment, log) + return IsConnectedService(configuration, environment, log) -class FritzboxUplinkService(Service): +class IsConnectedService(Service): def __init__(self, configuration, environment, log): super().__init__(configuration, environment, log) self.__configuration = configuration @@ -20,7 +20,6 @@ class FritzboxUplinkService(Service): self.__log = log def execute(self, identifier, service, **kwargs): - status = "NONE" self.__log.debug('identifier=' + identifier + 'service=' + service + ' object=' + str(self) + @@ -28,11 +27,6 @@ class FritzboxUplinkService(Service): try: fc = FritzStatus(address=kwargs['host'], password=kwargs['password']) - - if fc.is_connected: - status = "OK" - else: - status = "ERROR" except Exception: self.__log.error('identifier=' + identifier + ' host=' + str(kwargs['host']) + @@ -43,5 +37,9 @@ class FritzboxUplinkService(Service): self.__log.info('identifier=' + identifier + ' host=' + str(kwargs['host']) + ' service=' + service + - ' status=' + status) - return True + ' status=' + ('OK' if fc.is_connected else 'ERROR')) + + if fc.is_connected: + return True + else: + return False