Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
4c4babd9
Commit
4c4babd9
authored
Oct 22, 2015
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
experimentally scanning the mail log to see if we can infer a good time to take a backup
parent
53dc53bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
mail_log.py
management/mail_log.py
+15
-0
No files found.
management/mail_log.py
View file @
4c4babd9
#!/usr/bin/python3
from
collections
import
defaultdict
import
re
,
os
.
path
import
dateutil.parser
...
...
@@ -12,6 +13,7 @@ def scan_mail_log(logger, env):
"imap-logins"
:
{
},
"postgrey"
:
{
},
"rejected-mail"
:
{
},
"activity-by-hour"
:
{
"imap-logins"
:
defaultdict
(
int
),
"smtp-sends"
:
defaultdict
(
int
)
},
}
collector
[
"real_mail_addresses"
]
=
set
(
mailconfig
.
get_mail_users
(
env
))
|
set
(
alias
[
0
]
for
alias
in
mailconfig
.
get_mail_aliases
(
env
))
...
...
@@ -45,6 +47,10 @@ def scan_mail_log(logger, env):
for
date
,
sender
,
message
in
collector
[
"rejected-mail"
][
k
]:
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
sender
+
"
\t
"
+
message
)
logger
.
add_heading
(
"Activity by Hour"
)
for
h
in
range
(
24
):
logger
.
print_line
(
"
%
d
\t
%
d
\t
%
d"
%
(
h
,
collector
[
"activity-by-hour"
][
"imap-logins"
][
h
],
collector
[
"activity-by-hour"
][
"smtp-sends"
][
h
]
))
if
len
(
collector
[
"other-services"
])
>
0
:
logger
.
add_heading
(
"Other"
)
logger
.
print_block
(
"Unrecognized services in the log: "
+
", "
.
join
(
collector
[
"other-services"
]))
...
...
@@ -65,6 +71,9 @@ def scan_mail_log_line(line, collector):
elif
service
==
"postfix/smtpd"
:
scan_postfix_smtpd_line
(
date
,
log
,
collector
)
elif
service
==
"postfix/submission/smtpd"
:
scan_postfix_submission_line
(
date
,
log
,
collector
)
elif
service
in
(
"postfix/qmgr"
,
"postfix/pickup"
,
"postfix/cleanup"
,
"postfix/scache"
,
"spampd"
,
"postfix/anvil"
,
"postfix/master"
,
"opendkim"
,
"postfix/lmtp"
,
"postfix/tlsmgr"
):
...
...
@@ -80,6 +89,7 @@ def scan_dovecot_line(date, log, collector):
login
,
ip
=
m
.
group
(
1
),
m
.
group
(
2
)
if
ip
!=
"127.0.0.1"
:
# local login from webmail/zpush
collector
[
"imap-logins"
]
.
setdefault
(
login
,
{})[
ip
]
=
date
collector
[
"activity-by-hour"
][
"imap-logins"
][
date
.
hour
]
+=
1
def
scan_postgrey_line
(
date
,
log
,
collector
):
m
=
re
.
match
(
"action=(greylist|pass), reason=(.*?), (?:delay=
\
d+, )?client_name=(.*), client_address=(.*), sender=(.*), recipient=(.*)"
,
log
)
...
...
@@ -114,6 +124,11 @@ def scan_postfix_smtpd_line(date, log, collector):
collector
[
"rejected-mail"
]
.
setdefault
(
recipient
,
[])
.
append
(
(
date
,
sender
,
message
)
)
def
scan_postfix_submission_line
(
date
,
log
,
collector
):
m
=
re
.
match
(
"([A-Z0-9]+): client=(
\
S+), sasl_method=PLAIN, sasl_username=(
\
S+)"
,
log
)
if
m
:
procid
,
client
,
user
=
m
.
groups
()
collector
[
"activity-by-hour"
][
"smtp-sends"
][
date
.
hour
]
+=
1
if
__name__
==
"__main__"
:
from
status_checks
import
ConsoleOutput
...
...
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