1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Controllers;
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Icingadb\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Forms\Command\Instance\ToggleInstanceFeaturesForm;
use Icinga\Module\Icingadb\Model\HoststateSummary;
use Icinga\Module\Icingadb\Model\Instance;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Health;
use ipl\Web\Widget\VerticalKeyValue;
use ipl\Html\Html;
use ipl\Web\Url;
class HealthController extends Controller
{
public function indexAction()
{
$this->addTitleTab(t('Health'));
$db = $this->getDb();
$instance = Instance::on($db)->with(['endpoint']);
$hoststateSummary = HoststateSummary::on($db);
$servicestateSummary = ServicestateSummary::on($db);
$this->applyRestrictions($hoststateSummary);
$this->applyRestrictions($servicestateSummary);
yield $this->export($instance, $hoststateSummary, $servicestateSummary);
$instance = $instance->first();
if ($instance === null) {
$this->addContent(Html::tag('p', t(
'It seems that Icinga DB is not running.'
. ' Make sure Icinga DB is running and writing into the database.'
)));
return;
}
$hoststateSummary = $hoststateSummary->first();
$servicestateSummary = $servicestateSummary->first();
$this->content->addAttributes(['class' => 'monitoring-health']);
$this->addContent(new Health($instance));
$this->addContent(Html::tag('section', ['class' => 'check-summary'], [
Html::tag('div', ['class' => 'col'], [
Html::tag('h3', t('Host Checks')),
Html::tag('div', ['class' => 'col-content'], [
new VerticalKeyValue(
t('Active'),
$hoststateSummary->hosts_active_checks_enabled
),
new VerticalKeyValue(
t('Passive'),
$hoststateSummary->hosts_passive_checks_enabled
)
])
]),
Html::tag('div', ['class' => 'col'], [
Html::tag('h3', t('Service Checks')),
Html::tag('div', ['class' => 'col-content'], [
new VerticalKeyValue(
t('Active'),
$servicestateSummary->services_active_checks_enabled
),
new VerticalKeyValue(
t('Passive'),
$servicestateSummary->services_passive_checks_enabled
)
])
])
]));
$featureCommands = Html::tag(
'section',
['class' => 'instance-commands'],
Html::tag('h2', t('Feature Commands'))
);
$toggleInstanceFeaturesCommandForm = new ToggleInstanceFeaturesForm([
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS =>
$instance->icinga2_active_host_checks_enabled,
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS =>
$instance->icinga2_active_service_checks_enabled,
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS =>
$instance->icinga2_event_handlers_enabled,
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION =>
$instance->icinga2_flap_detection_enabled,
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS =>
$instance->icinga2_notifications_enabled,
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA =>
$instance->icinga2_performance_data_enabled
]);
$toggleInstanceFeaturesCommandForm->setObjects([$instance]);
$toggleInstanceFeaturesCommandForm->on(ToggleInstanceFeaturesForm::ON_SUCCESS, function () {
$this->getResponse()->setAutoRefreshInterval(1);
$this->redirectNow(Url::fromPath('icingadb/health')->getAbsoluteUrl());
});
$toggleInstanceFeaturesCommandForm->handleRequest(ServerRequest::fromGlobals());
$featureCommands->add($toggleInstanceFeaturesCommandForm);
$this->addContent($featureCommands);
$this->setAutorefreshInterval(30);
}
}
|