summaryrefslogtreecommitdiffstats
path: root/application/controllers/DaemonController.php
blob: ab0038fd87f97aa89c3c25450e9539204fe2f702 (plain)
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
<?php

namespace Icinga\Module\Director\Controllers;

use gipfl\Web\Widget\Hint;
use Icinga\Application\Icinga;
use Icinga\Module\Director\Daemon\RunningDaemonInfo;
use Icinga\Module\Director\Web\Tabs\MainTabs;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Web\Widget\BackgroundDaemonDetails;
use Icinga\Module\Director\Web\Widget\Documentation;
use ipl\Html\Html;

class DaemonController extends ActionController
{
    public function indexAction()
    {
        $this->setAutorefreshInterval(10);
        $this->tabs(new MainTabs($this->Auth(), $this->getDbResourceName()))->activate('daemon');
        $this->setTitle($this->translate('Director Background Daemon'));
        // Avoiding layout issues:
        $this->content()->add(Html::tag('h1', $this->translate('Director Background Daemon')));
        // TODO: move dashboard titles into controls. Or figure out whether 2.7 "broke" this

        $error = null;
        try {
            $db = $this->db()->getDbAdapter();
            $daemons = $db->fetchAll(
                $db->select()->from('director_daemon_info')->order('fqdn')->order('username')->order('pid')
            );
        } catch (\Exception $e) {
            $daemons = [];
            $error = $e->getMessage();
        }

        if (empty($daemons)) {
            $documentation = new Documentation(Icinga::app(), $this->Auth());
            $message = Html::sprintf($this->translate(
                'The Icinga Director Background Daemon is not running.'
                . ' Please check our %s in case you need step by step instructions'
                . ' showing you how to fix this.'
            ), $documentation->getModuleLink(
                $this->translate('documentation'),
                'director',
                '75-Background-Daemon',
                $this->translate('Icinga Director Background Daemon')
            ));
            $this->content()->add(Hint::error([
                $message,
                ($error ? [Html::tag('br'), Html::tag('strong', $error)] : null),
            ]));
            return;
        }

        try {
            foreach ($daemons as $daemon) {
                $info = new RunningDaemonInfo($daemon);
                $this->content()->add([new BackgroundDaemonDetails($info, $daemon)  /*, $logWindow*/]);
            }
        } catch (\Exception $e) {
            $this->content()->add(Hint::error($e->getMessage()));
        }
    }
}