mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: start of InfluxDB implementation
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Notifier;
|
||||
|
||||
use App\Config\WebhookScheme;
|
||||
use App\Entity\Domain;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mime\Address;
|
||||
@@ -24,8 +23,6 @@ class DomainOrderErrorNotification extends DomainWatchdogNotification
|
||||
|
||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||
{
|
||||
$webhookScheme = WebhookScheme::from($transport);
|
||||
|
||||
$ldhName = $this->domain->getLdhName();
|
||||
$this->subject("Error: Domain Order $ldhName")
|
||||
->content("Domain name $ldhName tried to be purchased. The attempt failed.")
|
||||
|
||||
51
src/Service/InfluxdbService.php
Normal file
51
src/Service/InfluxdbService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use App\Entity\RdapServer;
|
||||
use InfluxDB2\Client;
|
||||
use InfluxDB2\Model\WritePrecision;
|
||||
use InfluxDB2\Point;
|
||||
use InfluxDB2\WriteType;
|
||||
|
||||
readonly class InfluxdbService
|
||||
{
|
||||
private Client $client;
|
||||
|
||||
public function __construct(
|
||||
private string $influxdbUrl = 'http://influxdb:8086',
|
||||
private string $influxdbToken = '',
|
||||
private string $influxdbBucket = 'domainwatchdog',
|
||||
private string $influxdbOrg = 'domainwatchdog',
|
||||
) {
|
||||
$this->client = new Client([
|
||||
'url' => $this->influxdbUrl,
|
||||
'token' => $this->influxdbToken,
|
||||
'bucket' => $this->influxdbBucket,
|
||||
'org' => $this->influxdbOrg,
|
||||
'precision' => WritePrecision::MS,
|
||||
]);
|
||||
}
|
||||
|
||||
public function addRdapRequest(RdapServer $rdapServer, Domain $domain, bool $success): void
|
||||
{
|
||||
$this->writePoints(new Point('rdap_request', [
|
||||
'domain' => $domain->getLdhName(),
|
||||
'tld' => $domain->getTld()->getTld(),
|
||||
'rdap_server' => $rdapServer->getUrl(),
|
||||
], [
|
||||
'success' => $success,
|
||||
]));
|
||||
}
|
||||
|
||||
public function writePoints(Point ...$points): void
|
||||
{
|
||||
$writeApi = $this->client->createWriteApi(['writeType' => WriteType::BATCHING, 'batchSize' => count($points)]);
|
||||
foreach ($points as $point) {
|
||||
$writeApi->write($point);
|
||||
}
|
||||
|
||||
$writeApi->close();
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,8 @@ readonly class RDAPService
|
||||
private EntityManagerInterface $em,
|
||||
private LoggerInterface $logger,
|
||||
private StatService $statService,
|
||||
private InfluxdbService $influxService,
|
||||
private bool $influxdbEnable = false,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -156,6 +158,10 @@ readonly class RDAPService
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
if ($this->influxdbEnable) {
|
||||
$this->influxService->addRdapRequest($rdapServer, $domain, false);
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The domain name is not present in the WHOIS database.');
|
||||
}
|
||||
|
||||
@@ -348,6 +354,10 @@ readonly class RDAPService
|
||||
$this->em->persist($domain);
|
||||
$this->em->flush();
|
||||
|
||||
if ($this->influxdbEnable) {
|
||||
$this->influxService->addRdapRequest($rdapServer, $domain, true);
|
||||
}
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user