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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor
/app/config/config.local.neon
/.vagrant
/node_modules

!.gitignore
!.htaccess
44 changes: 44 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

var gulp = require('gulp');
var gutil = require('gulp-util');
var plugins = require('gulp-load-plugins')();
var bower = require('gulp-bower');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');

var config = {
assetsPath : 'assets',
cssPath : 'www/css',
jsPath : 'www/js',
bowerPath : 'temp/bower'
};

var jsFiles = [
config.bowerPath + '/stomp-websocket/lib/stomp.js',
config.assetsPath + '/js/main.js',
config.assetsPath + '/js/nette.ajax.js',
config.assetsPath + '/js/stomp.js',
config.assetsPath + '/js/websocket.js'
];

gulp.task('bower', function () {
return bower('temp/bower');
});

gulp.task('js', ['bower'], function () {
gulp
.src(jsFiles)
.pipe(gulp.dest(config.jsPath));
});


// Úlohy

gulp.task('watch', function () {
});


gulp.task('build', ['js']);
gulp.task('default', ['build']);
19 changes: 16 additions & 3 deletions app/Check/Consumers/Check.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);

namespace Pd\Monitoring\Check\Consumers;

Expand All @@ -20,21 +20,28 @@ abstract class Check implements \Kdyby\RabbitMq\IConsumer
*/
private $orm;

/**
* @var \Pd\Monitoring\Check\IOnCheckChangeDispatcher
*/
private $onCheckChangeDispatcher;


public function __construct(
\Pd\Monitoring\Check\ChecksRepository $checksRepository,
\Kdyby\Clock\IDateTimeProvider $dateTimeProvider,
\Pd\Monitoring\Orm\Orm $orm
\Pd\Monitoring\Orm\Orm $orm,
\Pd\Monitoring\Check\IOnCheckChangeDispatcher $onCheckChangeDispatcher
) {
$this->checksRepository = $checksRepository;
$this->dateTimeProvider = $dateTimeProvider;
$this->orm = $orm;
$this->onCheckChangeDispatcher = $onCheckChangeDispatcher;
}


public function process(\PhpAmqpLib\Message\AMQPMessage $message): int
{
$checkId = $message->getBody();
$checkId = (int) $message->getBody();

$this->orm->clearIdentityMapAndCaches(\Nextras\Orm\Model\IModel::I_KNOW_WHAT_I_AM_DOING);

Expand All @@ -48,12 +55,18 @@ public function process(\PhpAmqpLib\Message\AMQPMessage $message): int
$maxAttempts = $this->getMaxAttempts();
$attempts = 0;

$oldStatus = $check->status;

do {
$check->lastCheck = $this->dateTimeProvider->getDateTime();

$result = $this->doHardJob($check);
} while ( ! $result && ++$attempts < $maxAttempts && sleep(3) === 0);

if ($oldStatus !== $check->status) {
$this->onCheckChangeDispatcher->change($check);
}

$this->checksRepository->persistAndFlush($check);

return self::MSG_ACK;
Expand Down
10 changes: 10 additions & 0 deletions app/Check/IOnCheckChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Pd\Monitoring\Check;

interface IOnCheckChange
{

public function onCheckChange(Check $check): void;

}
13 changes: 13 additions & 0 deletions app/Check/IOnCheckChangeDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Pd\Monitoring\Check;

interface IOnCheckChangeDispatcher
{

public function addListener(IOnCheckChange $onCheckChange): void;


public function change(Check $check): void;

}
31 changes: 31 additions & 0 deletions app/Check/Listeners/DispatchProjectChangeListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Pd\Monitoring\Check\Listeners;

class DispatchProjectChangeListener implements \Pd\Monitoring\Check\IOnCheckChange, \Pd\Monitoring\Project\IOnProjectChange
{

/**
* @var \Kdyby\RabbitMq\IProducer
*/
private $producer;


public function __construct(
\Kdyby\RabbitMq\IProducer $producer
) {
$this->producer = $producer;
}


public function onCheckChange(\Pd\Monitoring\Check\Check $check): void
{
$this->onProjectChange($check->project);
}


public function onProjectChange(\Pd\Monitoring\Project\Project $project): void
{
$this->producer->publish('', $project->id);
}
}
26 changes: 26 additions & 0 deletions app/Check/Listeners/NotifyWebSocketListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Pd\Monitoring\Check\Listeners;

class NotifyWebSocketListener implements \Pd\Monitoring\Check\IOnCheckChange
{

/**
* @var \Kdyby\RabbitMq\IProducer
*/
private $producer;


public function __construct(
\Kdyby\RabbitMq\IProducer $producer,
\Pd\Monitoring\Check\ChecksRepository $checksRepository
) {
$this->producer = $producer;
}


public function onCheckChange(\Pd\Monitoring\Check\Check $check): void
{
$this->producer->publish('', $check->id);
}
}
26 changes: 26 additions & 0 deletions app/Check/OnCheckChangeDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Pd\Monitoring\Check;

class OnCheckChangeDispatcher implements IOnCheckChangeDispatcher
{

/**
* @var iterable|IOnCheckChange[]
*/
private $listeners;


public function change(Check $check): void
{
foreach ($this->listeners as $listener) {
$listener->onChange($check);
}
}


public function addListener(IOnCheckChange $onCheckChange): void
{
$this->listeners[] = $onCheckChange;
}
}
24 changes: 22 additions & 2 deletions app/DI/Extension.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);

namespace Pd\Monitoring\DI;

use Pd;
use Nette;
use Pd;


class Extension extends Nette\DI\CompilerExtension
Expand All @@ -19,4 +19,24 @@ public function beforeCompile()
;
}


public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
parent::afterCompile($class);

$container = $this->getContainerBuilder();

/** @var Pd\Monitoring\Check\Listeners\NotifyWebSocketListener $notifyWebSocketListener */
$notifyWebSocketListener = $container->getByType(Pd\Monitoring\Check\Listeners\NotifyWebSocketListener::class);

/** @var \Nextras\Orm\Repository\Repository $projectsRepository */
$projectsRepository = $container->getByType(Pd\Monitoring\Check\ChecksRepository::class);

$projectsRepository->onFlush[] = function ($persisted, $removed) use ($notifyWebSocketListener) {
foreach ($persisted as $entity) {
$notifyWebSocketListener->onCheckChange($entity);
}
};
}

}
7 changes: 6 additions & 1 deletion app/DashBoard/Controls/Check/Control.latte
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{snippet}
<div n:class="panel, $check->paused ? panel-default, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_OK ? panel-success, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_ALERT ? panel-warning, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_ERROR ? panel-danger">
<div
n:class="panel, $check->paused ? panel-default, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_OK ? panel-success, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_ALERT ? panel-warning, ! $check->paused && $check->status === Pd\Monitoring\Check\ICheck::STATUS_ERROR ? panel-danger"
data-socket="checkChange"
data-socket-key="{$check->id}"
data-socket-link="{$control->link('redraw!')}"
>
<div class="panel-heading">
<h3 class="panel-title">{$check->fullName}</h3>
</div>
Expand Down
19 changes: 19 additions & 0 deletions app/DashBoard/Controls/Check/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Control extends \Nette\Application\UI\Control
*/
private $rabbitConnection;

/**
* @var array|IOnRedraw
*/
private $onRedrawListeners = [];


public function __construct(
\Pd\Monitoring\Check\Check $check,
Expand All @@ -33,6 +38,12 @@ public function __construct(
}


public function addOnRedraw(IOnRedraw $onRedraw)
{
$this->onRedrawListeners[] = $onRedraw;
}


protected function createTemplate()
{
/** @var \Latte\Runtime\Template $template */
Expand Down Expand Up @@ -79,11 +90,19 @@ public function handleRefresh()
$this->processRequest();
}

public function handleRedraw()
{
$this->processRequest();
}


private function processRequest()
{
if ($this->getPresenter()->isAjax()) {
$this->redrawControl();
foreach($this->onRedrawListeners as $listener) {
$listener->onRedraw($this, $this->check);
}
} else {
$this->redirect('this');
}
Expand Down
10 changes: 10 additions & 0 deletions app/DashBoard/Controls/Check/IOnRedraw.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Pd\Monitoring\DashBoard\Controls\Check;

interface IOnRedraw
{

public function onRedraw(Control $control, \Pd\Monitoring\Check\Check $check);

}
2 changes: 0 additions & 2 deletions app/DashBoard/Controls/LastRefresh/Control.latte

This file was deleted.

13 changes: 0 additions & 13 deletions app/DashBoard/Controls/LastRefresh/Control.php

This file was deleted.

9 changes: 0 additions & 9 deletions app/DashBoard/Controls/LastRefresh/IFactory.php

This file was deleted.

24 changes: 0 additions & 24 deletions app/DashBoard/Controls/LastRefresh/TFactory.php

This file was deleted.

9 changes: 8 additions & 1 deletion app/DashBoard/Controls/Project/Control.latte
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<div class="panel panel-default">
{snippet}
<div
class="panel panel-default"
data-socket="projectChange"
data-socket-key="{$project->id}"
data-socket-link="{$control->link('redraw!')}"
>
<div class="panel-body">
<h2>{if $project->maintenance}<small class="glyphicon glyphicon-fire" aria-hidden="true"></small> {/if}<a href="{plink Project: $project->id}">{$project->name}</a></h2>

Expand All @@ -22,3 +28,4 @@
{/if}
</div>
</div>
{/snippet}
Loading