Added port probing service. (0.25.6)

This commit is contained in:
Johannes Findeisen 2023-08-22 19:16:13 +02:00
commit 3a0f555dd3
3 changed files with 21 additions and 15 deletions

View file

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

View file

@ -15,21 +15,28 @@ def create(configuration, environment, log):
class PortService(Service):
def execute(self, execution, **kwargs):
error_code = 0
msg = "Connection successful established"
def execute(self, identifier, monitor, service, **kwargs):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as err:
error_code = 2
msg = "Could not create socket"
sock.connect((monitor.get_host(), int(kwargs['port'])))
sock.close()
try:
sock.connect((execution.get_host_name(), self.port))
except socket.error as err:
error_code = 1
msg = "Could not establish connection"
self._log.info('Connection to host ' + monitor.get_host() + ' on port ' +
kwargs['port'] + ' successful')
return {'status': 'OK',
'message': 'Connection to host ' + monitor.get_host() + ' on port ' +
kwargs['port'] + ' successful', 'host': monitor.get_host(),
'service': service}
except Exception as err:
self._log.info('Connection to host ' + monitor.get_host() + ' on port ' +
kwargs['port'] + ' failed (' + str(err))
return {'status': 'ERROR',
'message': 'Connection to host ' + monitor.get_host() + ' on port ' +
kwargs['port'] + ' failed (' + str(err) +
')', 'host': monitor.get_host(),
'service': service}
sock.close()

View file

@ -37,7 +37,6 @@ class IsConnectedService(Service):
' status=' + ('OK' if fc.is_connected else 'ERROR'))
result = {"host": monitor.get_host(),
"message": "Uplink on host " + monitor.get_host() + " " +
('UP' if fc.is_connected else 'DOWN'),
"service": service,