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

Registry checks.

parent 5b6126d1
No related branches found
No related tags found
No related merge requests found
from utils import check_url, publish from utils import check_urls
def handler(event, context): # pylint: disable=unused-argument def handler(event, context): # pylint: disable=unused-argument
...@@ -6,16 +6,9 @@ def handler(event, context): # pylint: disable=unused-argument ...@@ -6,16 +6,9 @@ def handler(event, context): # pylint: disable=unused-argument
checks = [ checks = [
{"url": "http://git.shore.co.il/", "codes": [301, 302]}, {"url": "http://git.shore.co.il/", "codes": [301, 302]},
{"url": "https://git.shore.co.il/", "codes": [301, 302]}, {"url": "https://git.shore.co.il/", "codes": [301, 302]},
{"url": "https://git.shore.co.il/explore/", "codes": [200]}, {"url": "https://git.shore.co.il/explore/"},
] ]
check_urls(checks)
for check in checks:
if not check_url(check["url"], valid_codes=check["codes"]):
message = f"Failed check for {check['url']}."
print(message)
publish(message)
else:
print(f"{check['url']} is OK.")
if __name__ == "__main__": if __name__ == "__main__":
......
from utils import check_urls
def handler(event, context): # pylint: disable=unused-argument
"""Lambda event handler."""
checks = [
{"url": "http://registry.shore.co.il/", "codes": [301, 302]},
{"url": "https://registry.shore.co.il/"},
{"url": "https://registry.shore.co.il/v2/_catalog"},
]
check_urls(checks)
if __name__ == "__main__":
handler("event", "context")
...@@ -14,7 +14,7 @@ def publish(message): ...@@ -14,7 +14,7 @@ def publish(message):
def check_url(url, method="GET", valid_codes=(200)): def check_url(url, method="GET", valid_codes=(200)):
"""Checks URL for validity. """Checks validaty of a URL.
Allows specifying the HTTP method and a list of valid codes.""" Allows specifying the HTTP method and a list of valid codes."""
try: try:
...@@ -22,3 +22,16 @@ def check_url(url, method="GET", valid_codes=(200)): ...@@ -22,3 +22,16 @@ def check_url(url, method="GET", valid_codes=(200)):
return response.status_code in valid_codes return response.status_code in valid_codes
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
return False return False
def check_urls(checks):
"""Check a list of URLs."""
for check in checks:
if check_url(
check["url"], check.get("method", "GET"), check.get("codes", [200])
):
print(f"{check['url']} is OK.")
else:
message = f"Failed check for {check['url']}."
print(message)
publish(message)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment