Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
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 @@
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
getpass
,
os
,
smtplib
import
getpass
,
os
from
collections
import
Counter
from
collections
import
Counter
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email.utils
import
formataddr
,
formatdate
from
email.utils
import
formataddr
,
formatdate
...
@@ -100,6 +100,8 @@ class Backup(Monitor):
...
@@ -100,6 +100,8 @@ class Backup(Monitor):
class
Application
(
BaseApplication
,
Monitor
):
class
Application
(
BaseApplication
,
Monitor
):
"""The storage node application."""
"""The storage node application."""
from
smtplib
import
SMTP
@
classmethod
@
classmethod
def
_buildOptionParser
(
cls
):
def
_buildOptionParser
(
cls
):
_
=
cls
.
option_parser
_
=
cls
.
option_parser
...
@@ -116,6 +118,10 @@ class Application(BaseApplication, Monitor):
...
@@ -116,6 +118,10 @@ class Application(BaseApplication, Monitor):
help
=
'name of backup cluster to monitor'
+
hint
)
help
=
'name of backup cluster to monitor'
+
hint
)
_
(
'smtp'
,
metavar
=
'HOST[:PORT]'
,
_
(
'smtp'
,
metavar
=
'HOST[:PORT]'
,
help
=
'SMTP for email notifications'
)
help
=
'SMTP for email notifications'
)
_
.
bool
(
'smtp-tls'
,
help
=
'use STARTTLS'
)
_
(
'smtp-auth'
,
metavar
=
'USER:PASS'
,
help
=
'SMTP credentials'
)
_
.
int
(
'i'
,
'nid'
,
_
.
int
(
'i'
,
'nid'
,
help
=
"specify an NID to use for this process (testing purpose)"
)
help
=
"specify an NID to use for this process (testing purpose)"
)
...
@@ -135,8 +141,13 @@ class Application(BaseApplication, Monitor):
...
@@ -135,8 +141,13 @@ class Application(BaseApplication, Monitor):
x
.
max_lag
=
max_lag
x
.
max_lag
=
max_lag
self
.
email_list
=
config
.
get
(
'monitor_email'
,
())
self
.
email_list
=
config
.
get
(
'monitor_email'
,
())
if
self
.
email_list
:
if
self
.
email_list
:
self
.
smtp
=
smtplib
.
SMTP
()
self
.
smtp_host
=
config
.
get
(
'smtp'
)
or
'localhost'
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'
)
email_from
=
os
.
getenv
(
'EMAIL'
)
if
not
email_from
:
if
not
email_from
:
try
:
try
:
...
@@ -321,9 +332,13 @@ class Application(BaseApplication, Monitor):
...
@@ -321,9 +332,13 @@ class Application(BaseApplication, Monitor):
msg
[
'Subject'
]
=
'NEO monitoring: '
+
x
msg
[
'Subject'
]
=
'NEO monitoring: '
+
x
msg
[
'From'
]
=
self
.
email_from
msg
[
'From'
]
=
self
.
email_from
msg
[
'To'
]
=
', '
.
join
(
email_list
)
msg
[
'To'
]
=
', '
.
join
(
email_list
)
s
=
self
.
smtp
s
=
self
.
SMTP
()
try
:
try
:
s
.
connect
(
self
.
smtp_host
)
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
())
s
.
sendmail
(
None
,
email_list
,
msg
.
as_string
())
except
Exception
:
except
Exception
:
x
=
format_exc
()
x
=
format_exc
()
...
...
neo/tests/threaded/__init__.py
View file @
ef95d4fe
...
@@ -431,10 +431,12 @@ class ServerNode(Node):
...
@@ -431,10 +431,12 @@ class ServerNode(Node):
class
AdminApplication
(
ServerNode
,
neo
.
admin
.
app
.
Application
):
class
AdminApplication
(
ServerNode
,
neo
.
admin
.
app
.
Application
):
def
__setattr__
(
self
,
name
,
value
):
def
SMTP
(
self
):
if
name
==
'smtp'
:
return
self
.
smtp
value
=
FakeSMTP
()
super
(
AdminApplication
,
self
).
__setattr__
(
name
,
value
)
@
cached_property
def
smtp
(
self
):
return
FakeSMTP
()
class
MasterApplication
(
ServerNode
,
neo
.
master
.
app
.
Application
):
class
MasterApplication
(
ServerNode
,
neo
.
master
.
app
.
Application
):
pass
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