Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FoD
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
Container 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schmitz
FoD
Commits
41bffbb8
Commit
41bffbb8
authored
Nov 2, 2023
by
David Schmitz
Browse files
Options
Downloads
Patches
Plain Diff
feature/improved-warning-mails: add helper function for handling external error admin messages
parent
cc739393
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
flowspec/helpers.py
+89
-1
89 additions, 1 deletion
flowspec/helpers.py
flowspec/tasks.py
+7
-0
7 additions, 0 deletions
flowspec/tasks.py
with
96 additions
and
1 deletion
flowspec/helpers.py
+
89
−
1
View file @
41bffbb8
from
django.core.mail.message
import
EmailMessage
from
django.core.mail.message
import
EmailMessage
from
django.conf
import
settings
from
django.conf
import
settings
import
os
import
os
import
datetime
import
flowspec.logging_utils
import
flowspec.logging_utils
logger
=
flowspec
.
logging_utils
.
logger_init_default
(
__name__
,
"
flowspec_accounts_view.log
"
,
False
)
logger
=
flowspec
.
logging_utils
.
logger_init_default
(
__name__
,
"
flowspec_accounts_view.log
"
,
False
)
#
def
send_new_mail
(
subject
,
message
,
from_email
,
recipient_list
,
bcc_list
):
def
send_new_mail
(
subject
,
message
,
from_email
,
recipient_list
,
bcc_list
):
try
:
try
:
logger
.
info
(
"
helpers::send_new_mail(): send mail: from_email=
"
+
str
(
from_email
)
+
"
, recipient_list=
"
+
str
(
recipient_list
)
+
"
, bcc_list=
"
+
str
(
bcc_list
))
logger
.
info
(
"
helpers::send_new_mail(): send mail: from_email=
"
+
str
(
from_email
)
+
"
, recipient_list=
"
+
str
(
recipient_list
)
+
"
, bcc_list=
"
+
str
(
bcc_list
))
...
@@ -33,3 +36,88 @@ def get_peer_techc_mails(user, peer):
...
@@ -33,3 +36,88 @@ def get_peer_techc_mails(user, peer):
logger
.
info
(
"
helpers::get_peer_techc_mails(): additional_mail=
"
+
str
(
additional_mail
))
logger
.
info
(
"
helpers::get_peer_techc_mails(): additional_mail=
"
+
str
(
additional_mail
))
logger
.
info
(
"
helpers::get_peer_techc_mails(): techmails_list=
"
+
str
(
techmails_list
))
logger
.
info
(
"
helpers::get_peer_techc_mails(): techmails_list=
"
+
str
(
techmails_list
))
return
mail
return
mail
#
admin_error_mail_entry__cache_list
=
[]
max_length_of_entry_message_text__in_digest_mail_text
=
1000
def
handle_admin_error_mail
(
subject
,
message
):
try
:
global
admin_error_mail_entry__cache_list
logger
.
info
(
"
helpers::handle_admin_error_mail(): subject=
'"
+
str
(
subject
)
+
"'
message=
'"
+
str
(
message
)
+
"'"
)
admin_mail_addres_list
=
""
if
settings
.
NOTIFY_ADMIN_MAILS
:
admin_mail_addres_list
=
settings
.
NOTIFY_ADMIN_MAILS
src_addr
=
settings
.
SERVER_EMAIL
logger
.
info
(
"
helpers::handle_admin_error_mail(): src_addr=
"
+
str
(
src_addr
))
logger
.
info
(
"
helpers::handle_admin_error_mail(): admin_mail_addres_list=
"
+
str
(
admin_mail_addres_list
))
if
admin_mail_addres_list
:
EmailMessage
(
subject
,
message
,
src_addr
,
admin_mail_addres_list
,
""
).
send
()
logger
.
info
(
"
helpers::handle_admin_error_mail(): after mail sending
"
)
nowtime
=
datetime
.
datetime
.
now
()
logger
.
info
(
"
helpers::handle_admin_error_mail(): nowtime=
"
+
str
(
nowtime
))
admin_error_mail_entry__cache_list
.
append
({
'
time
'
:
nowtime
,
'
subject
'
:
subject
,
'
message
'
:
message
})
logger
.
info
(
"
helpers::handle_admin_error_mail(): after list append
"
)
return
True
except
Exception
as
e
:
logger
.
error
(
"
helpers::handle_admin_error_mail() failed: exc=
"
+
str
(
e
))
return
False
def
send_cached_admin_error_entry_summary_ll
():
try
:
global
admin_error_mail_entry__cache_list
logger
.
info
(
"
helpers::send_cached_admin_error_entry_summary_ll(): called
"
)
admin_mail_addres_list
=
""
if
settings
.
NOTIFY_ADMIN_MAILS
:
admin_mail_addres_list
=
settings
.
NOTIFY_ADMIN_MAILS
#
if
len
(
admin_mail_addres_list
)
>
0
:
subject
=
'
FoD admin external error summary
'
mail_all_text
=
''
for
entry
in
admin_error_mail_entry__cache_list
:
nowtime
=
entry
[
'
time
'
]
subject
=
entry
[
'
subject
'
]
message
=
entry
[
'
message
'
]
nowstr
=
nowtime
.
isoformat
()
message_part
=
str
(
message
)
if
len
(
message
)
>
max_length_of_entry_message_text__in_digest_mail_text
:
message_part
=
substr
(
message
,
1
,
max_length_of_entry_message_text__in_digest_mail_text
-
4
)
+
'
...
'
mail_all_text
=
mail_all_text
+
'
\n\n
'
+
str
(
nowstr
)
+
'
'
+
str
(
subject
)
+
'
:
\n
'
+
str
(
message_part
)
#
logger
.
info
(
"
helpers::send_cached_admin_error_entry_summary_ll(): => mail_all_text=
'"
+
mail_all_text
+
"'"
)
if
admin_mail_addres_list
:
EmailMessage
(
subject
,
mail_all_text
,
settings
.
SERVER_EMAIL
,
admin_mail_addres_list
,
""
).
send
()
admin_mail_addres_list
=
[]
return
True
except
Exception
as
e
:
logger
.
error
(
"
helpers::send_cached_admin_error_entry_summary_ll(): failed: exc=
"
+
str
(
e
))
return
False
This diff is collapsed.
Click to expand it.
flowspec/tasks.py
+
7
−
0
View file @
41bffbb8
...
@@ -33,6 +33,7 @@ from sys import exit
...
@@ -33,6 +33,7 @@ from sys import exit
import
time
import
time
import
redis
import
redis
from
django.forms.models
import
model_to_dict
from
django.forms.models
import
model_to_dict
from
flowspec.helpers
import
send_cached_admin_error_entry_summary_ll
from
peers.models
import
*
from
peers.models
import
*
...
@@ -342,6 +343,12 @@ def notify_expired():
...
@@ -342,6 +343,12 @@ def notify_expired():
pass
pass
logger
.
info
(
'
Expiration notification process finished
'
)
logger
.
info
(
'
Expiration notification process finished
'
)
@shared_task
(
ignore_result
=
True
)
def
send_cached_admin_error_entry_summary
():
logger
.
info
(
'
send_cached_admin_error_entry_summary(): called
'
)
send_cached_admin_error_entry_summary_ll
()
logger
.
info
(
'
send_cached_admin_error_entry_summary(): done
'
)
##############################################################################
##############################################################################
##############################################################################
##############################################################################
# snmp task handling (including helper functions)
# snmp task handling (including helper functions)
...
...
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
sign in
to comment