Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
alert-relay
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor 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
Demannu
alert-relay
Merge requests
!12
Add file and console output of incoming data
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add file and console output of incoming data
log-incoming-data
into
main
Overview
0
Commits
3
Pipelines
0
Changes
7
Merged
Demannu
requested to merge
log-incoming-data
into
main
2 years ago
Overview
0
Commits
3
Pipelines
0
Changes
7
Expand
0
0
Merge request reports
Compare
main
version 2
5cfb3faa
2 years ago
version 1
72e4f712
2 years ago
main (base)
and
latest version
latest version
d4fc7a88
3 commits,
2 years ago
version 2
5cfb3faa
2 commits,
2 years ago
version 1
72e4f712
1 commit,
2 years ago
7 files
+
51
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
alert_relay/main.py
+
13
−
1
Options
"""
Main package for alert_relay
"""
import
json
import
os
import
requests
import
uvicorn
from
fastapi
import
FastAPI
@@ -16,13 +17,23 @@ class AlertBody(BaseModel):
app
=
FastAPI
()
with
open
(
"
config.json
"
,
"
r
"
,
encoding
=
"
utf_8
"
)
as
file
:
with
open
(
"
/app/data/
config.json
"
,
"
r
"
,
encoding
=
"
utf_8
"
)
as
file
:
config
=
json
.
load
(
file
)
if
not
os
.
path
.
exists
(
"
logs/
"
):
os
.
mkdir
(
"
logs
"
)
@app.post
(
"
/alerts
"
)
async
def
alerts
(
alert
:
AlertBody
):
"""
Route for handling the relay
"""
# Open the logfile in "a"ppend mode, with the standard encoding
with
open
(
"
./logs/incoming-datto.log
"
,
"
a
"
,
encoding
=
"
utf8
"
)
as
log_file
:
log_file
.
write
(
str
(
alert
))
# Print the incoming data from data
print
(
alert
)
request
=
requests
.
post
(
f
"
https://api.telegram.org/
{
config
[
'
auth
'
]
}
/sendMessage
"
,
json
=
{
@@ -30,6 +41,7 @@ async def alerts(alert: AlertBody):
"
chat_id
"
:
alert
.
chat_id
,
"
text
"
:
alert
.
message
,
},
timeout
=
60
,
)
return
request
.
json
(),
request
.
status_code
Loading