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
fad2d856
Commit
fad2d856
authored
4 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Add SSH checks.
parent
45cd7f76
No related branches found
No related tags found
No related merge requests found
Pipeline
#1321
passed
4 years ago
Stage: test
Stage: build
Stage: plan
Stage: apply
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
functions.tf
+1
-0
1 addition, 0 deletions
functions.tf
src/ssh.py
+16
-0
16 additions, 0 deletions
src/ssh.py
src/utils.py
+13
-0
13 additions, 0 deletions
src/utils.py
with
30 additions
and
0 deletions
functions.tf
+
1
−
0
View file @
fad2d856
...
@@ -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
,
"_"
,
""
)}
"
]
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ssh.py
0 → 100644
+
16
−
0
View file @
fad2d856
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
"
)
This diff is collapsed.
Click to expand it.
src/utils.py
+
13
−
0
View file @
fad2d856
# 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
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