Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Am I live
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shore
Am I live
Commits
5453dadf
Commit
5453dadf
authored
4 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Check the GitLab instance.
parent
9c361f7f
No related branches found
No related tags found
No related merge requests found
Pipeline
#1305
passed
4 years ago
Stage: test
Stage: build
Stage: plan
Stage: apply
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
functions.tf
+1
-0
1 addition, 0 deletions
functions.tf
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
src/gitlab.py
+22
-0
22 additions, 0 deletions
src/gitlab.py
src/utils.py
+12
-0
12 additions, 0 deletions
src/utils.py
with
36 additions
and
0 deletions
functions.tf
+
1
−
0
View file @
5453dadf
...
...
@@ -2,6 +2,7 @@ locals {
function_name_prefix
=
local
.
Name
functions
=
[
"_dns"
,
"gitlab"
,
]
}
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
5453dadf
dnspython
requests
This diff is collapsed.
Click to expand it.
src/gitlab.py
0 → 100644
+
22
−
0
View file @
5453dadf
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
"
)
This diff is collapsed.
Click to expand it.
src/utils.py
+
12
−
0
View file @
5453dadf
# 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment