Commit 1ad8a859 authored by nimrod's avatar nimrod
Browse files

Small refactor.

parent afa6fb1b
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
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
+0 −13
Original line number Diff line number Diff line
# 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