I am trying to send e-mail to me and user that someone tried to login to their ssh and failed - the IP got banned. But I don't understand how can I use the variable in the e-mail I am trying to send.
Sendmail is set up correctly as the e-mails are being sent without problem.
Here is my jail.local config
[sshd]
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
action = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
%(mta)s-whois-lines-ssh[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
And here is my action.d/sendmail-whois-lines-ssh.conf
[INCLUDES]
before = sendmail-common.conf
helpers-common.conf
[Definition]
norestored = 1
actionban = ( printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from <fq-hostname>
Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
From: <sendername> <<sender>>
To: <dest>, <F-USER>@mydomain.cz\n
Hi,\n
The IP <ip> has just been banned by Fail2Ban after
<failures> attempts against <name>.\n\n
Here is more information about <ip> :\n
`/usr/bin/whois <ip> || echo missing whois program`\n\n
Lines containing failures of <ip>\n";
%(_grep_logs)s;
printf %%b "\n
Regards,\n
Fail2Ban" ) | /usr/sbin/sendmail -f <sender>.mydomain.cz <dest> <F-USER>@mydomain.cz
[Init]
name = default
logpath = /dev/null
The e-mail sent to me is fine, because is taken correctly from configuration, but <F-USER> has no value so it is being sent to @mydomain.cz
How can I get the value so I am able to send the e-mail to user ?
EDIT
The regex getting hit on SSH is this one:
^pam_unix\(sshd:auth\):\s+authentication failure;\s*logname=\S*\s*uid=\d*\s*euid=\d*\s*tty=\S*\s*ruser=<F-USER>\S*</F-USER>\s*rhost=<HOST>\s.*%(__suff)s$