diff --git a/src/ssh.py b/src/ssh.py index 17bc62ce732ebb253f92c749bc655203fb52c640..9d72d5b8b552c6c0c6c175e7526d1eeb8f572674 100644 --- a/src/ssh.py +++ b/src/ssh.py @@ -1,4 +1,18 @@ -from utils import check_ssh, publish +import socket +from utils import publish + + +def check_ssh(host, port=22): + """Check that an SSH server is available on that host and port.""" + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + sock.connect((host, port)) + msg = sock.recv(1024) + sock.close() + return msg.startswith(b"SSH-2.0-OpenSSH") + except Exception as e: # pylint: disable=broad-except,invalid-name + print(str(e)) + return False def handler(event, context): # pylint: disable=unused-argument diff --git a/src/utils.py b/src/utils.py index 2abfb34495d9dc38ce40a2513f272a97b2274da5..ca7e1e9ec177ee2c6fe997c68cb33c8f84bec110 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,6 +1,5 @@ # pylint: disable=import-error import os -import socket import boto3 import requests @@ -37,15 +36,3 @@ def check_urls(checks): message = f"Failed check for {check['url']}." print(message) publish(message) - - -def check_ssh(host, port=22): - """Check that an SSH server is available on that host and port.""" - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - sock.connect((host, port)) - msg = sock.recv(1024) - return msg.startswith(b"SSH-2.0-OpenSSH") - except Exception as e: # pylint: disable=broad-except,invalid-name - print(str(e)) - return False