Skip to content
Snippets Groups Projects
Commit fad2d856 authored by nimrod's avatar nimrod
Browse files

Add SSH checks.

parent 45cd7f76
No related branches found
No related tags found
No related merge requests found
Pipeline #1321 passed
...@@ -13,6 +13,7 @@ locals { ...@@ -13,6 +13,7 @@ locals {
"kodi", "kodi",
"transmission", "transmission",
"vouch", "vouch",
"ssh",
] ]
function_names = [for name in local.functions : "${local.function_name_prefix}-${replace(name, "_", "")}"] 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 # pylint: disable=import-error
import os import os
import socket
import boto3 import boto3
import requests import requests
...@@ -36,3 +37,15 @@ def check_urls(checks): ...@@ -36,3 +37,15 @@ def check_urls(checks):
message = f"Failed check for {check['url']}." message = f"Failed check for {check['url']}."
print(message) print(message)
publish(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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment