SSR alert mail recipients maintainable in the site settings
New site setting vitec.ssr.alertEmails (Site Management, Settings, VITEC; one address per entry). vitec:ssr-health reads the recipients from there, invalid entries are skipped and logged, SSR_ALERT_EMAIL in the env file stays as fallback. The cockpit shows the recipients in the live band. Pre-filled with the address that was in the env file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
994f9f2a1b
commit
90cb2faaf9
6 files changed
+81
-6
No files matched your search
@@ -7,6 +7,8 @@ namespace Evomedien\Vitec\Service;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\Http\RequestFactory;
|
||||
use TYPO3\CMS\Core\Site\SiteFinder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Talks to the SSR node's POST /__purge endpoint (contract 0054-FE) and
|
||||
@@ -24,6 +26,7 @@ final class SsrPurgeService
|
||||
public function __construct(
|
||||
private readonly RequestFactory $requestFactory,
|
||||
private readonly ConnectionPool $connectionPool,
|
||||
private readonly SiteFinder $siteFinder,
|
||||
) {}
|
||||
|
||||
public static function getConfigPath(): string
|
||||
@@ -66,6 +69,50 @@ final class SsrPurgeService
|
||||
return trim($this->getConfig()['SSR_ALERT_EMAIL'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Who gets the vitec:ssr-health alert mails. Maintained by editors in
|
||||
* Site Management › Settings › VITEC (vitec.ssr.alertEmails, one
|
||||
* address per entry); the first site with at least one valid address
|
||||
* wins. Without such a list, SSR_ALERT_EMAIL from the env file is the
|
||||
* fallback. Invalid entries are skipped and reported back.
|
||||
*
|
||||
* @return array{recipients: list<string>, source: string, invalid: list<string>}
|
||||
*/
|
||||
public function getAlertRecipients(): array
|
||||
{
|
||||
$invalid = [];
|
||||
try {
|
||||
foreach ($this->siteFinder->getAllSites() as $site) {
|
||||
$list = $site->getSettings()->get('vitec.ssr.alertEmails', []);
|
||||
if (is_string($list)) {
|
||||
$list = GeneralUtility::trimExplode(',', $list, true);
|
||||
}
|
||||
$valid = [];
|
||||
foreach ((array)$list as $address) {
|
||||
$address = trim((string)$address);
|
||||
if ($address === '') {
|
||||
continue;
|
||||
}
|
||||
if (GeneralUtility::validEmail($address)) {
|
||||
$valid[] = $address;
|
||||
} else {
|
||||
$invalid[] = $address;
|
||||
}
|
||||
}
|
||||
if ($valid !== []) {
|
||||
return ['recipients' => array_values(array_unique($valid)), 'source' => 'site settings', 'invalid' => $invalid];
|
||||
}
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
// No site configuration readable (e.g. broken YAML): use the env fallback.
|
||||
}
|
||||
$env = array_values(array_filter(
|
||||
GeneralUtility::trimExplode(',', $this->getAlertEmail(), true),
|
||||
static fn(string $a): bool => GeneralUtility::validEmail($a)
|
||||
));
|
||||
return ['recipients' => $env, 'source' => $env !== [] ? 'var/vitec-ssr-purge.env' : '', 'invalid' => $invalid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Consecutive DOWN samples after which vitec:ssr-health fails over to
|
||||
* the SPA (SSR_FAILOVER_AFTER, default 2 = ~10 minutes at the 5-minute
|
||||
|
||||
Reference in new issue
Block a user