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

Check the GitLab instance.

parent 9c361f7f
No related branches found
No related tags found
No related merge requests found
Pipeline #1305 passed
......@@ -2,6 +2,7 @@ locals {
function_name_prefix = local.Name
functions = [
"_dns",
"gitlab",
]
}
......
from utils import check_url, publish
def handler(event, context): # pylint: disable=unused-argument
"""Lambda event handler."""
checks = [
{"url": "http://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]},
]
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__":
handler("event", "context")
# pylint: disable=import-error
import os
import boto3
import requests
TOPIC_ARN = os.getenv("TOPIC_ARN")
......@@ -10,3 +11,14 @@ def publish(message):
"""Publish an SNS message."""
client = boto3.client("sns")
client.publish(TopicArn=TOPIC_ARN, Message=message)
def check_url(url, method="GET", valid_codes=(200)):
"""Checks URL for validity.
Allows specifying the HTTP method and a list of valid codes."""
try:
response = requests.request(method, url, allow_redirects=False)
return response.status_code in valid_codes
except Exception: # pylint: disable=broad-except
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment