Commit fad2d856 authored by nimrod's avatar nimrod
Browse files

Add SSH checks.

parent 45cd7f76
Pipeline #1321 passed with stages
in 3 minutes and 29 seconds
......@@ -13,6 +13,7 @@ locals {
"kodi",
"transmission",
"vouch",
"ssh",
]
function_names = [for name in local.functions : "${local.function_name_prefix}-${replace(name, "_", "")}"]
}
......
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")
# pylint: disable=import-error
import os
import socket
import boto3
import requests
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment