Fail2ban + swag-f2bdiscord inside unRaid

Hello. I’m fairly new to unraid and containers and docker and all this, so excuse me if this is a dumb question. I’m running nginxproxymanager container from jlesage, fail2ban from you fine folks, and overseer-binhex.

I installed fail2ban from linuxserver/io via customer apps in unraid. I wanted to get discord messages when it blocked an IP, so luckily I found a fail2ban mod for just such a purpose. GitHub - linuxserver/docker-mods at swag-f2bdiscord

When I initially configured it like the readme I was getting errors about it not being able to import geoip2.database. OK I thought, I don’t really need a map in the discord message, so I removed the import and code for that from Fail2Ban.py, but then I got an error that it couldn’t import requests. The python script imports several modules, so at this point I figured maybe I could just install the modules at runtime, but evidently pip doesn’t come with the fail2ban container, so then I found the universal package install mod.

So now I have fail2ban with universal-package-install installing pip, which then installs the 3 modules that are needed for the discord mod to run.

https://imgur.com/a/qRfhOcZ

It worked. I was shocked. I was getting discord messages whenever fail2ban started or stopped the jails.

Today I was at work and decided I’d ban my own work IP just to test things out. I went to overseer over the internet, purposely failed 5 logins and bam, IP blocked. But no discord message.

In the logs I get the following, and now we’re getting way above my paygrade.

Should I switch to SWAG? I’ve got nginxproxymanager and duckdns working with a letsencrypt ssl cert already, so I’d rather not have to reconfigure all that, but if a different configuration would be better then I’m down to switch things up.

2023-10-30 13:54:37,091 1482500D2B38 NOTIC [overseerr-auth] Ban 123.123.123.123
 2023-10-30 13:54:37,280 1482500D2B38 ERROR 1482525ce4c0 -- exec: python3 /config/fail2ban/Fail2Ban.py -a ban -j overseerr-auth -i 123.123.123.123 -t 3600 -f 5
 2023-10-30 13:54:37,281 1482500D2B38 ERROR 1482525ce4c0 -- stderr: 'Traceback (most recent call last):'
 2023-10-30 13:54:37,282 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/config/fail2ban/Fail2Ban.py", line 95, in <module>'
 2023-10-30 13:54:37,283 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    data = Helpers(args.ip).data if "ban" in args.action else {}'
 2023-10-30 13:54:37,283 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '           ^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,284 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/config/fail2ban/Fail2Ban.py", line 64, in __init__'
 2023-10-30 13:54:37,284 1482500D2B38 ERROR 1482525ce4c0 -- stderr: "    self.reader = geoip2.database.Reader('/config/geoip2db/GeoLite2-City.mmdb')"
 2023-10-30 13:54:37,285 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,285 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/geoip2/database.py", line 85, in __init__'
 2023-10-30 13:54:37,286 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    self._db_reader = maxminddb.open_database(fileish, mode)'
 2023-10-30 13:54:37,286 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,287 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/maxminddb/__init__.py", line 69, in open_database'
 2023-10-30 13:54:37,287 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    return Reader(database, mode)'
 2023-10-30 13:54:37,288 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '           ^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,289 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/maxminddb/reader.py", line 57, in __init__'
 2023-10-30 13:54:37,289 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    with open(database, "rb") as db_file:  # type: ignore'
 2023-10-30 13:54:37,290 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '         ^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,290 1482500D2B38 ERROR 1482525ce4c0 -- stderr: "FileNotFoundError: [Errno 2] No such file or directory: '/config/geoip2db/GeoLite2-City.mmdb'"
 2023-10-30 13:54:37,291 1482500D2B38 ERROR 1482525ce4c0 -- returned 1
 2023-10-30 13:54:37,452 1482500D2B38 ERROR 1482525ce4c0 -- exec: python3 /config/fail2ban/Fail2Ban.py -a ban -j overseerr-auth -i 123.123.123.123 -t 3600 -f 5
 2023-10-30 13:54:37,453 1482500D2B38 ERROR 1482525ce4c0 -- stderr: 'Traceback (most recent call last):'
 2023-10-30 13:54:37,454 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/config/fail2ban/Fail2Ban.py", line 95, in <module>'
 2023-10-30 13:54:37,455 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    data = Helpers(args.ip).data if "ban" in args.action else {}'
 2023-10-30 13:54:37,455 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '           ^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,456 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/config/fail2ban/Fail2Ban.py", line 64, in __init__'
 2023-10-30 13:54:37,456 1482500D2B38 ERROR 1482525ce4c0 -- stderr: "    self.reader = geoip2.database.Reader('/config/geoip2db/GeoLite2-City.mmdb')"
 2023-10-30 13:54:37,457 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,457 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/geoip2/database.py", line 85, in __init__'
 2023-10-30 13:54:37,458 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    self._db_reader = maxminddb.open_database(fileish, mode)'
 2023-10-30 13:54:37,459 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,459 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/maxminddb/__init__.py", line 69, in open_database'
 2023-10-30 13:54:37,460 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    return Reader(database, mode)'
 2023-10-30 13:54:37,460 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '           ^^^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,461 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '  File "/usr/lib/python3.11/site-packages/maxminddb/reader.py", line 57, in __init__'
 2023-10-30 13:54:37,461 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '    with open(database, "rb") as db_file:  # type: ignore'
 2023-10-30 13:54:37,462 1482500D2B38 ERROR 1482525ce4c0 -- stderr: '         ^^^^^^^^^^^^^^^^^^^^'
 2023-10-30 13:54:37,462 1482500D2B38 ERROR 1482525ce4c0 -- stderr: "FileNotFoundError: [Errno 2] No such file or directory: '/config/geoip2db/GeoLite2-City.mmdb'"
 2023-10-30 13:54:37,463 1482500D2B38 ERROR 1482525ce4c0 -- returned 1
 2023-10-30 13:54:37,463 1482500D2B38 ERROR Failed to execute ban jail 'overseerr-auth' action 'discordEmbed' info 'ActionInfo({'ip': '123.123.123.123', 'family': 'inet4', 'fid': <function Actions.ActionInfo.<lambda> at 0x1482534e42c0>, 'failures': 5, 'bantime': 3600, 'raw-ticket': <function Actions.ActionInfo.<lambda> at 0x1482534e4a40>})': Error banning 123.123.123.123

Thank you for your time

I didn’t realize that Adding ban/unban notifications from Fail2Ban to Discord! - technicalramblings.com was already implemented in the base container with discord-webhook.conf. Not as fancy as the mod, but better than nothing. When I went with the more basic setup it worked fine.