2022-09-25 00:39:51 +02:00
|
|
|
"""
|
|
|
|
|
This file is part of Linspector (https://linspector.org/)
|
2023-08-22 02:53:50 +02:00
|
|
|
Copyright (c) 2013-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
|
|
|
|
See LICENSE.
|
2022-09-25 00:39:51 +02:00
|
|
|
"""
|
2023-08-22 02:53:50 +02:00
|
|
|
|
2023-02-22 15:25:58 +01:00
|
|
|
from fritzconnection.lib.fritzstatus import FritzStatus
|
2022-09-25 00:39:51 +02:00
|
|
|
|
2023-02-23 10:26:44 +01:00
|
|
|
from linspector.service import Service
|
2022-09-28 02:04:50 +02:00
|
|
|
|
2022-09-25 00:39:51 +02:00
|
|
|
|
2022-10-06 02:42:15 +02:00
|
|
|
def create(configuration, environment, log):
|
2023-02-22 16:55:06 +01:00
|
|
|
return IsConnectedService(configuration, environment, log)
|
2022-09-27 21:18:47 +02:00
|
|
|
|
|
|
|
|
|
2023-02-22 16:55:06 +01:00
|
|
|
class IsConnectedService(Service):
|
2022-09-27 06:07:55 +02:00
|
|
|
|
2023-02-22 22:39:51 +01:00
|
|
|
def execute(self, identifier, monitor, service, **kwargs):
|
2023-08-20 22:51:39 +02:00
|
|
|
|
2023-02-22 15:25:58 +01:00
|
|
|
try:
|
2023-02-22 22:39:51 +01:00
|
|
|
fc = FritzStatus(address=monitor.get_host(),
|
2023-08-31 22:58:37 +02:00
|
|
|
user=kwargs['user'],
|
|
|
|
|
password=kwargs['password'],
|
|
|
|
|
timeout=10)
|
2023-08-22 21:38:33 +02:00
|
|
|
error = 'None'
|
|
|
|
|
if fc.is_connected:
|
|
|
|
|
status = 'OK'
|
|
|
|
|
else:
|
|
|
|
|
status = 'ERROR'
|
2023-02-22 22:39:51 +01:00
|
|
|
except Exception as err:
|
2023-08-22 21:38:33 +02:00
|
|
|
error = str(err)
|
|
|
|
|
status = 'ERROR'
|
2023-02-22 15:25:58 +01:00
|
|
|
|
2023-08-31 22:58:37 +02:00
|
|
|
result = {'error': error.replace('\'', ''),
|
2023-08-22 21:38:33 +02:00
|
|
|
'host': monitor.get_host(),
|
2023-08-23 20:23:49 +02:00
|
|
|
'log': self.get_str(identifier, monitor.get_host(), service, status),
|
2023-08-22 21:38:33 +02:00
|
|
|
'service': service,
|
|
|
|
|
'status': status}
|
2023-08-20 22:51:39 +02:00
|
|
|
|
|
|
|
|
return result
|