Loading functions.tf +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ locals { "kodi", "transmission", "vouch", "ssh", ] function_names = [for name in local.functions : "${local.function_name_prefix}-${replace(name, "_", "")}"] } Loading src/ssh.py 0 → 100644 +16 −0 Original line number Diff line number Diff line from utils import check_ssh, publish def handler(event, context): # pylint: disable=unused-argument """Lambda event handler.""" for host in ["ns1.shore.co.il", "ns4.shore.co.il"]: if check_ssh(host): print(f"SSH on {host} is OK.") else: message = f"SSH on {host} failed." print(message) publish(message) if __name__ == "__main__": handler("event", "context") src/utils.py +13 −0 Original line number Diff line number Diff line # pylint: disable=import-error import os import socket import boto3 import requests Loading Loading @@ -36,3 +37,15 @@ 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 Loading
functions.tf +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ locals { "kodi", "transmission", "vouch", "ssh", ] function_names = [for name in local.functions : "${local.function_name_prefix}-${replace(name, "_", "")}"] } Loading
src/ssh.py 0 → 100644 +16 −0 Original line number Diff line number Diff line from utils import check_ssh, publish def handler(event, context): # pylint: disable=unused-argument """Lambda event handler.""" for host in ["ns1.shore.co.il", "ns4.shore.co.il"]: if check_ssh(host): print(f"SSH on {host} is OK.") else: message = f"SSH on {host} failed." print(message) publish(message) if __name__ == "__main__": handler("event", "context")
src/utils.py +13 −0 Original line number Diff line number Diff line # pylint: disable=import-error import os import socket import boto3 import requests Loading Loading @@ -36,3 +37,15 @@ 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