From 1ad8a859213fa3584047ef631adb970a8205db89 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sat, 1 May 2021 00:26:56 +0300
Subject: [PATCH] Small refactor.

---
 src/ssh.py   | 16 +++++++++++++++-
 src/utils.py | 13 -------------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/ssh.py b/src/ssh.py
index 17bc62c..9d72d5b 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 2abfb34..ca7e1e9 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
-- 
GitLab