Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
neoppod
Commits
ef95d4fe
Commit
ef95d4fe
authored
Oct 17, 2019
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin: new --smtp-tls & --smtp-auth options
parent
caabe3c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
neo/admin/app.py
neo/admin/app.py
+18
-3
neo/tests/threaded/__init__.py
neo/tests/threaded/__init__.py
+6
-4
No files found.
neo/admin/app.py
View file @
ef95d4fe
...
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
getpass
,
os
,
smtplib
import
getpass
,
os
from
collections
import
Counter
from
email.mime.text
import
MIMEText
from
email.utils
import
formataddr
,
formatdate
...
...
@@ -100,6 +100,8 @@ class Backup(Monitor):
class
Application
(
BaseApplication
,
Monitor
):
"""The storage node application."""
from
smtplib
import
SMTP
@
classmethod
def
_buildOptionParser
(
cls
):
_
=
cls
.
option_parser
...
...
@@ -116,6 +118,10 @@ class Application(BaseApplication, Monitor):
help
=
'name of backup cluster to monitor'
+
hint
)
_
(
'smtp'
,
metavar
=
'HOST[:PORT]'
,
help
=
'SMTP for email notifications'
)
_
.
bool
(
'smtp-tls'
,
help
=
'use STARTTLS'
)
_
(
'smtp-auth'
,
metavar
=
'USER:PASS'
,
help
=
'SMTP credentials'
)
_
.
int
(
'i'
,
'nid'
,
help
=
"specify an NID to use for this process (testing purpose)"
)
...
...
@@ -135,8 +141,13 @@ class Application(BaseApplication, Monitor):
x
.
max_lag
=
max_lag
self
.
email_list
=
config
.
get
(
'monitor_email'
,
())
if
self
.
email_list
:
self
.
smtp
=
smtplib
.
SMTP
()
self
.
smtp_host
=
config
.
get
(
'smtp'
)
or
'localhost'
self
.
smtp_tls
=
config
.
get
(
'smtp_tls'
)
if
'smtp_auth'
in
config
:
user
,
pwd
=
config
[
'smtp_auth'
].
split
(
':'
,
1
)
self
.
smtp_login
=
user
,
pwd
else
:
self
.
smtp_login
=
None
email_from
=
os
.
getenv
(
'EMAIL'
)
if
not
email_from
:
try
:
...
...
@@ -321,9 +332,13 @@ class Application(BaseApplication, Monitor):
msg
[
'Subject'
]
=
'NEO monitoring: '
+
x
msg
[
'From'
]
=
self
.
email_from
msg
[
'To'
]
=
', '
.
join
(
email_list
)
s
=
self
.
smtp
s
=
self
.
SMTP
()
try
:
s
.
connect
(
self
.
smtp_host
)
if
self
.
smtp_tls
:
s
.
starttls
()
if
self
.
smtp_login
:
s
.
login
(
*
self
.
smtp_login
)
s
.
sendmail
(
None
,
email_list
,
msg
.
as_string
())
except
Exception
:
x
=
format_exc
()
...
...
neo/tests/threaded/__init__.py
View file @
ef95d4fe
...
...
@@ -431,10 +431,12 @@ class ServerNode(Node):
class
AdminApplication
(
ServerNode
,
neo
.
admin
.
app
.
Application
):
def
__setattr__
(
self
,
name
,
value
):
if
name
==
'smtp'
:
value
=
FakeSMTP
()
super
(
AdminApplication
,
self
).
__setattr__
(
name
,
value
)
def
SMTP
(
self
):
return
self
.
smtp
@
cached_property
def
smtp
(
self
):
return
FakeSMTP
()
class
MasterApplication
(
ServerNode
,
neo
.
master
.
app
.
Application
):
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment