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
2 changes: 2 additions & 0 deletions app/Check/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @property SlackNotifyLock $locks {1:m SlackNotifyLock::$check, cascade=[persist, remove]}
* @property int $type {enum ICheck::TYPE_*}
* @property int $status {virtual}
* @property bool $awaitingRecovery
* @property \DateTime|NULL $lastCheck
* @property bool $paused {default TRUE}
* @property string|NULL $name
Expand Down Expand Up @@ -35,6 +36,7 @@ public function __construct()
parent::__construct();

$this->status = ICheck::STATUS_ERROR;
$this->awaitingRecovery = FALSE;
}


Expand Down
27 changes: 23 additions & 4 deletions app/Check/Commands/SlackCheckStatusesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Pd\Monitoring\Check\Commands;

use Pd\Monitoring\Check\ICheck;

class SlackCheckStatusesCommand extends \Symfony\Component\Console\Command\Command
{

Expand Down Expand Up @@ -90,6 +92,24 @@ protected function execute(
}
}

$url = $this->linkGenerator->link('DashBoard:Project:', [$check->project->id]);
$checkStatusMessage = $check->statusMessage;

if ($check->awaitingRecovery && $check->status === ICheck::STATUS_OK) {
$message = sprintf(
'Pro <%s|projekt %s> se kontrola vrátila do normálu: %s%s',
$url,
$check->project->name,
$check->fullName,
$checkStatusMessage ? ': ' . $checkStatusMessage : ''
);

$this->slackNotifier->notify($message, 'good');
$check->awaitingRecovery = FALSE;
$this->checksRepository->persistAndFlush($check);
continue;
}

$conditions = [
'check' => $check,
];
Expand All @@ -101,8 +121,6 @@ protected function execute(
continue;
}

$url = $this->linkGenerator->link('DashBoard:Project:', [$check->project->id]);

switch ($check->status) {
case \Pd\Monitoring\Check\ICheck::STATUS_ALERT:
$color = 'warning';
Expand All @@ -118,9 +136,10 @@ protected function execute(
$lock->locked = $this->dateTimeProvider->getDateTime();
$lock->status = $check->status;
$lock->check = $check;
$this->slackNotifyLocksRepository->persistAndFlush($lock);
$this->slackNotifyLocksRepository->persist($lock);

$checkStatusMessage = $check->statusMessage;
$check->awaitingRecovery = TRUE;
$this->checksRepository->persistAndFlush($check);

$message = sprintf(
'Pro <%s|projekt %s> je zaznamenán problém v kontrole %s%s',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `checks`
ADD `awaiting_recovery` tinyint NOT NULL DEFAULT 0;