Add SpamAssassin filtering for Postfix mail nodes #74

Merged
parkel merged 2 commits from feature/mail-spam-filtering into main 2026-11-21 21:39:49 +01:00
2 changed files with 38 additions and 2 deletions
Showing only changes of commit 7d380f093d - Show all commits

No files matched your search

@@ -1,6 +1,7 @@
import json import json
import subprocess import subprocess
from datetime import timedelta from datetime import timedelta
from io import StringIO
from unittest.mock import patch from unittest.mock import patch
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@@ -16,6 +17,7 @@ from coulobre.service_health import (
check_remote, check_remote,
check_unit, check_unit,
load_health_targets, load_health_targets,
main,
) )
from .models import Customer, Reseller, ServiceHealth from .models import Customer, Reseller, ServiceHealth
@@ -99,6 +101,37 @@ class ServiceHealthProbeTests(SimpleTestCase):
self.assertIn("StrictHostKeyChecking=yes", command) self.assertIn("StrictHostKeyChecking=yes", command)
self.assertEqual(command[-2:], ("--", "mail-02")) self.assertEqual(command[-2:], ("--", "mail-02"))
def test_spam_filter_units_can_be_checked_locally_and_remotely(self):
filters = ("spamd", "spamass-milter")
self.assertEqual(
load_health_targets(
'{"panel":{"local":["spamd","spamass-milter"]},'
'"mail":{"ssh":["spamd","spamass-milter"]}}'
),
(
HealthTarget("panel", "local", filters),
HealthTarget("mail", "ssh", filters),
),
)
output = StringIO()
with (
patch("sys.stdout", output),
patch(
"coulobre.service_health.subprocess.run",
return_value=subprocess.CompletedProcess(
(), 0, b"LoadState=loaded\nActiveState=active\n"
),
) as run,
):
self.assertEqual(main(), 0)
units = {call.args[0][-1] for call in run.call_args_list}
self.assertTrue({"spamd.service", "spamass-milter.service"} <= units)
report = json.loads(output.getvalue())
self.assertEqual(
{name: report["services"][name] for name in filters},
dict.fromkeys(filters, "active"),
)
@override_settings(SERVICE_HEALTH_TARGETS=TARGETS) @override_settings(SERVICE_HEALTH_TARGETS=TARGETS)
class ServiceHealthPanelTests(TestCase): class ServiceHealthPanelTests(TestCase):
+5 -2
View File
@@ -15,8 +15,10 @@ SERVICES = {
"bind9": ("BIND9", "named.service"), "bind9": ("BIND9", "named.service"),
"postfix": ("Postfix", "postfix.service"), "postfix": ("Postfix", "postfix.service"),
"dovecot": ("Dovecot", "dovecot.service"), "dovecot": ("Dovecot", "dovecot.service"),
"spamd": ("SpamAssassin", "spamd.service"),
"spamass-milter": ("SpamAssassin milter", "spamass-milter.service"),
} }
REMOTE_SERVICES = ("bind9", "postfix", "dovecot") REMOTE_SERVICES = ("bind9", "postfix", "dovecot", "spamd", "spamass-milter")
REMOTE_VERSION = 1 REMOTE_VERSION = 1
SSH_CONFIG = "/etc/coulobre-health/ssh_config" SSH_CONFIG = "/etc/coulobre-health/ssh_config"
NODE_NAME = re.compile(r"[a-z][a-z0-9-]{0,62}") NODE_NAME = re.compile(r"[a-z][a-z0-9-]{0,62}")
@@ -172,7 +174,8 @@ def check_remote(target):
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
timeout=15, # Allow for SSH setup and sequential unit checks.
timeout=22,
check=True, check=True,
) )
except (OSError, subprocess.SubprocessError): except (OSError, subprocess.SubprocessError):