Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
picomon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Heintz
picomon
Commits
1493903b
Commit
1493903b
authored
May 24, 2014
by
Colomban Wendling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to configure SMTP host and From address
parent
bce8206f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
config.py
config.py
+4
-0
lib/__init__.py
lib/__init__.py
+6
-0
lib/mails.py
lib/mails.py
+3
-6
No files found.
config.py
View file @
1493903b
...
...
@@ -8,6 +8,10 @@ config.base_tick = 60
# Email addresses to send to when an alert is triggered
config
.
emails
.
to
.
append
(
'john@localhost'
)
# The From: address
#config.emails.addr_from = 'Picomon <picomon@domain.tld>
# The SMTP host, with optional :port suffix
#config.emails.smtp_host = 'localhost:25'
# Subject template for state change email notifications
# available substitutions:
...
...
lib/__init__.py
View file @
1493903b
import
socket
from
.attrtree
import
AttrTree
from
.checks
import
Checks
...
...
@@ -13,6 +14,11 @@ config.install_attr('base_tick', 60)
# Email addresses to send to when an alert is triggered
config
.
install_attr
(
'emails.to'
,
[])
# The From: address
config
.
install_attr
(
'emails.addr_from'
,
'Picomon <picomon@%s>'
%
socket
.
getfqdn
())
# The SMTP host, with optional :port suffix
config
.
install_attr
(
'emails.smtp_host'
,
'localhost:25'
)
# Subject template for state change email notifications
# available substitutions:
...
...
lib/mails.py
View file @
1493903b
import
socket
import
smtplib
from
email.mime.text
import
MIMEText
from
collections
import
defaultdict
...
...
@@ -11,8 +10,6 @@ email.charset.add_charset('utf-8', email.charset.QP, email.charset.QP, 'utf-8')
def
send_email_for_check
(
check
):
from
.
import
config
addr_from
=
"Picomon <picomon@%s>"
%
socket
.
getfqdn
()
# ensure we do not traceback with unknown substitutions
subject
=
config
.
emails
.
subject_tpl
.
format_map
(
defaultdict
(
lambda
:
"<no substitution>"
,
...
...
@@ -29,13 +26,13 @@ def send_email_for_check(check):
# http://bugs.python.org/issue16948
msg
=
MIMEText
(
msg_text
.
encode
(
'utf-8'
).
decode
(
'latin1'
),
'plain'
,
'utf-8'
)
msg
[
'Subject'
]
=
subject
msg
[
'From'
]
=
addr_from
msg
[
'From'
]
=
config
.
emails
.
addr_from
msg
[
'To'
]
=
", "
.
join
(
config
.
emails
.
to
)
try
:
server
=
smtplib
.
SMTP
(
'localhost'
)
server
=
smtplib
.
SMTP
(
config
.
emails
.
smtp_host
)
# server.set_debuglevel(1)
server
.
sendmail
(
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
server
.
sendmail
(
config
.
emails
.
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
server
.
quit
()
except
Exception
as
e
:
print
(
"Couldn't send email: %s"
%
str
(
e
),
file
=
stderr
)
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