feat: ajout notification Discord en prod + mail priority HIGH pour le rapport DNS
src/Command/CheckDnsCommand.php:
- Injection de HttpClientInterface et kernel.environment dans le constructeur
- Constante DISCORD_WEBHOOK avec l'URL du webhook Discord
- sendReport(): appel sendEmail avec priority=1 (HIGH) pour que le mail
soit marque comme urgent dans tous les clients mail
- sendDiscordNotification(): envoie un embed Discord avec:
- Titre "Esy-Infra : ALERTE DNS" (rouge), "DNS avertissements" (jaune)
ou "DNS Configuration OK" (vert)
- Description avec le nombre de succes/erreurs/warnings
- Les 5 premieres erreurs en citation markdown
- Footer "Esy-Infra - Monitoring DNS" avec timestamp
- La notification Discord est envoyee UNIQUEMENT en environnement prod
(condition sur kernel.environment == 'prod')
src/Service/MailerService.php:
- Ajout du parametre $priority (int, defaut 3 = normal) a sendEmail()
- Appel de ->priority($priority) sur l'objet Email Symfony
- Priority 1 = highest, 2 = high, 3 = normal, 4 = low, 5 = lowest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,8 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
#[AsCommand(
|
||||
@@ -28,6 +30,7 @@ class CheckDnsCommand extends Command
|
||||
];
|
||||
|
||||
private const MONITOR_EMAIL = 'monitor@siteconseil.fr';
|
||||
private const DISCORD_WEBHOOK = 'https://discord.com/api/webhooks/1419573620602044518/ikAdxWxsrrTqMTb5Gh_8ylcoJHlOnq7aJZvR5udoS_fCK56Jk3qpEnJHVKdD8fwuNJF3';
|
||||
|
||||
public function __construct(
|
||||
private DnsCheckService $dnsCheck,
|
||||
@@ -36,6 +39,8 @@ class CheckDnsCommand extends Command
|
||||
private MailcowService $mailcow,
|
||||
private MailerService $mailer,
|
||||
private Environment $twig,
|
||||
private HttpClientInterface $httpClient,
|
||||
#[Autowire('%kernel.environment%')] private string $appEnv,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -394,6 +399,65 @@ class CheckDnsCommand extends Command
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
1, // Priority HIGH
|
||||
);
|
||||
|
||||
// Notification Discord uniquement en prod
|
||||
if ('prod' === $this->appEnv) {
|
||||
$this->sendDiscordNotification($errors, $warnings, $successes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $errors
|
||||
* @param list<string> $warnings
|
||||
* @param list<string> $successes
|
||||
*/
|
||||
private function sendDiscordNotification(array $errors, array $warnings, array $successes): void
|
||||
{
|
||||
$hasErrors = [] !== $errors;
|
||||
$hasWarnings = [] !== $warnings;
|
||||
|
||||
if ($hasErrors) {
|
||||
$color = 0xDC2626; // rouge
|
||||
$title = 'ALERTE DNS - '.\count($errors).' erreur(s)';
|
||||
} elseif ($hasWarnings) {
|
||||
$color = 0xF59E0B; // jaune
|
||||
$title = 'DNS - '.\count($warnings).' avertissement(s)';
|
||||
} else {
|
||||
$color = 0x16A34A; // vert
|
||||
$title = 'DNS - Configuration OK';
|
||||
}
|
||||
|
||||
$description = "Domaines: **".implode(', ', self::DOMAINS)."**\n\n";
|
||||
$description .= "**".\count($successes)."** verification(s) OK\n";
|
||||
if ($hasErrors) {
|
||||
$description .= "**".\count($errors)."** erreur(s)\n";
|
||||
foreach (array_slice($errors, 0, 5) as $e) {
|
||||
$description .= "> $e\n";
|
||||
}
|
||||
if (\count($errors) > 5) {
|
||||
$description .= "> ... et ".(\count($errors) - 5)." autres\n";
|
||||
}
|
||||
}
|
||||
if ($hasWarnings) {
|
||||
$description .= "**".\count($warnings)."** avertissement(s)\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$this->httpClient->request('POST', self::DISCORD_WEBHOOK, [
|
||||
'json' => [
|
||||
'embeds' => [[
|
||||
'title' => 'Esy-Infra : '.$title,
|
||||
'description' => $description,
|
||||
'color' => $color,
|
||||
'footer' => ['text' => 'Esy-Infra - Monitoring DNS'],
|
||||
'timestamp' => (new \DateTimeImmutable())->format('c'),
|
||||
]],
|
||||
],
|
||||
]);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class MailerService
|
||||
/**
|
||||
* @param array<array{path: string, name?: string}>|null $attachments
|
||||
*/
|
||||
public function sendEmail(string $to, string $subject, string $content, ?string $from = null, ?string $replyTo = null, bool $withUnsubscribe = true, ?array $attachments = null): void
|
||||
public function sendEmail(string $to, string $subject, string $content, ?string $from = null, ?string $replyTo = null, bool $withUnsubscribe = true, ?array $attachments = null, int $priority = 3): void
|
||||
{
|
||||
$from ??= $this->getAdminFrom();
|
||||
$canUnsubscribe = $withUnsubscribe && !$this->isWhitelisted($to);
|
||||
@@ -71,7 +71,8 @@ class MailerService
|
||||
->from($from)
|
||||
->to($to)
|
||||
->subject($subject)
|
||||
->html($content);
|
||||
->html($content)
|
||||
->priority($priority);
|
||||
|
||||
if ($replyTo) {
|
||||
$email->replyTo($replyTo);
|
||||
|
||||
Reference in New Issue
Block a user