Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Check/ChecksRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static function getEntityClassNames()
AliveCheck::class,
TermCheck::class,
DnsCheck::class,
DnsCnameCheck::class,
CertificateCheck::class,
FeedCheck::class,
RabbitConsumerCheck::class,
Expand All @@ -39,6 +40,8 @@ public function getEntityClassName(array $data)
return TermCheck::class;
case ICheck::TYPE_DNS:
return DnsCheck::class;
case ICheck::TYPE_DNS_CNAME:
return DnsCnameCheck::class;
case ICheck::TYPE_CERTIFICATE:
return CertificateCheck::class;
case ICheck::TYPE_FEED:
Expand Down
18 changes: 18 additions & 0 deletions app/Check/Commands/Publish/DnsCnameChecksCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\Check\Commands\Publish;

use Pd\Monitoring\Commands\TNamedCommand;

class DnsCnameChecksCommand extends PublishChecksCommand
{
use TNamedCommand;

protected function getConditions(): array
{
return [
'type' => \Pd\Monitoring\Check\ICheck::TYPE_DNS_CNAME,
];
}

}
31 changes: 31 additions & 0 deletions app/Check/Consumers/DnsCnameCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Pd\Monitoring\Check\Consumers;

class DnsCnameCheck extends Check
{

/**
* @param \Pd\Monitoring\Check\Check|\Pd\Monitoring\Check\DnsCnameCheck $check
* @return bool
*/
protected function doHardJob(\Pd\Monitoring\Check\Check $check): bool
{
$check->lastTarget = NULL;

$entries = dns_get_record($check->url, DNS_CNAME);
if (!$entries) {
return FALSE;
}

$entry = array_shift($entries);
$check->lastTarget = $entry['target'];
return TRUE;
}


protected function getCheckType(): int
{
return \Pd\Monitoring\Check\ICheck::TYPE_DNS_CNAME;
}
}
40 changes: 40 additions & 0 deletions app/Check/DnsCnameCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\Check;

/**
* @property string $url
* @property string $target
* @property string|NULL $lastTarget
*/
class DnsCnameCheck extends Check
{

public function __construct()
{
parent::__construct();
$this->type = ICheck::TYPE_DNS_CNAME;
}


protected function getStatus(): int
{
if ($this->lastTarget === $this->target) {
return ICheck::STATUS_OK;
} else {
return ICheck::STATUS_ERROR;
}
}


public function getTitle(): string
{
return 'Nastavení DNS CNAME';
}


public function getterStatusMessage(): string
{
return $this->lastTarget !== $this->target ? sprintf('Očekávaná CNAME adresa "%s" neodpovídá zjištěné "%s"', $this->target, $this->lastTarget) : '';
}
}
37 changes: 37 additions & 0 deletions app/DashBoard/Controls/AddEditCheck/DnsCnameCheckProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types = 1);

namespace Pd\Monitoring\DashBoard\Controls\AddEditCheck;

class DnsCnameCheckProcessor implements ICheckControlProcessor
{

public function processEntity(\Pd\Monitoring\Check\Check $check, array $data)
{
$check->url = $data['url'];
$check->target = $data['target'];
}


public function getCheck(): \Pd\Monitoring\Check\Check
{
return new \Pd\Monitoring\Check\DnsCnameCheck();
}


public function createForm(\Pd\Monitoring\Check\Check $check, \Nette\Application\UI\Form $form)
{
$form->addGroup($check->getTitle());
$form
->addText('url', 'Adresa')
->setRequired(TRUE)
;
$form
->addText('target', 'Cíl')
->setRequired(TRUE)
->addFilter(function($value) {
return rtrim($value, '.');
});
;
}

}
4 changes: 4 additions & 0 deletions app/DashBoard/Controls/AddEditCheck/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function create(\Pd\Monitoring\Project\Project $project, int $type, \Pd\M
$control = new Control($project, $check, new DnsCheckProcessor(), $this->formFactory, $this->checksRepository);
break;

case \Pd\Monitoring\Check\ICheck::TYPE_DNS_CNAME:
$control = new Control($project, $check, new DnsCnameCheckProcessor(), $this->formFactory, $this->checksRepository);
break;

case \Pd\Monitoring\Check\ICheck::TYPE_CERTIFICATE:
$control = new Control($project, $check, new CertificateCheckProcessor(), $this->formFactory, $this->checksRepository);
break;
Expand Down
5 changes: 5 additions & 0 deletions app/DashBoard/Controls/Check/Control.latte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<p>Očekávaná IP: {$check->ip}</p>
<p>Zjištěná IP: {if $check->lastIp}{$check->lastIp}{else}<span class="text-muted">není</span>{/if}</p>
<p>Poslední kontrola: {if $check->lastCheck}{$check->lastCheck|dateTime}{else}<span class="text-muted">neproběhla</span>{/if}</p>
{elseif $check instanceof Pd\Monitoring\Check\DnsCnameCheck}
<p>Testovaná adresa: <a href="{$check->url}">{$check->url}</a></p>
<p>Očekávaný cíl: {$check->target}</p>
<p>Zjištěný cíl: {if $check->lastTarget}{$check->lastTarget}{else}<span class="text-muted">není</span>{/if}</p>
<p>Poslední kontrola: {if $check->lastCheck}{$check->lastCheck|dateTime}{else}<span class="text-muted">neproběhla</span>{/if}</p>
{elseif $check instanceof Pd\Monitoring\Check\CertificateCheck}
<p>Testovaná adresa: <a href="{$check->url}">{$check->url}</a></p>
<p>Varování předem: {$check->daysBeforeWarning} dní</p>
Expand Down
1 change: 1 addition & 0 deletions app/DashBoard/Presenters/ProjectPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function renderDefault()
new \Pd\Monitoring\Check\AliveCheck(),
new \Pd\Monitoring\Check\TermCheck(),
new \Pd\Monitoring\Check\DnsCheck(),
new \Pd\Monitoring\Check\DnsCnameCheck(),
new \Pd\Monitoring\Check\CertificateCheck(),
new \Pd\Monitoring\Check\FeedCheck(),
new \Pd\Monitoring\Check\RabbitConsumerCheck(),
Expand Down
17 changes: 17 additions & 0 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ rabbitmq:
dnsCheck:
exchange: {name: 'dnsCheck', type: direct}
contentType: text/plain
dnsCnameCheck:
exchange: {name: 'dnsCnameCheck', type: direct}
contentType: text/plain
certificateCheck:
exchange: {name: 'certificateCheck', type: direct}
contentType: text/plain
Expand All @@ -91,6 +94,10 @@ rabbitmq:
exchange: {name: 'dnsCheck', type: direct}
queue: {name: 'dnsCheck'}
callback: [@Pd\Monitoring\Check\Consumers\DnsCheck, process]
dnsCnameCheck:
exchange: {name: 'dnsCnameCheck', type: direct}
queue: {name: 'dnsCnameCheck'}
callback: [@Pd\Monitoring\Check\Consumers\DnsCnameCheck, process]
certificateCheck:
exchange: {name: 'certificateCheck', type: direct}
queue: {name: 'certificateCheck'}
Expand Down Expand Up @@ -134,6 +141,9 @@ services:
-
class: Pd\Monitoring\Check\Consumers\DnsCheck

-
class: Pd\Monitoring\Check\Consumers\DnsCnameCheck

-
class: Pd\Monitoring\Check\Consumers\CertificateCheck

Expand Down Expand Up @@ -168,6 +178,13 @@ services:
arguments:
- @Kdyby\RabbitMq\Connection::getProducer('dnsCheck')

-
class: Pd\Monitoring\Check\Commands\Publish\DnsCnameChecksCommand
tags:
- kdyby.console.command
arguments:
- @Kdyby\RabbitMq\Connection::getProducer('dnsCnameCheck')

-
class: Pd\Monitoring\Check\Commands\Publish\CertificateChecksCommand
tags:
Expand Down
2 changes: 2 additions & 0 deletions migrations/structures/2017-04-13-174952-dns-cname-check.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `checks` ADD `target` VARCHAR(250) NULL DEFAULT NULL;
ALTER TABLE `checks` ADD `last_target` VARCHAR(250) NULL DEFAULT NULL AFTER `target`;