summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/application/views/scripts/list/eventgrid.phtml
blob: ca191237861f14f9d1cd4e3f67a37612f8705940 (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
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
116
117
118
119
120
121
122
123
<?php
use Icinga\Data\Filter\Filter;
use Icinga\Web\Widget\Chart\HistoryColorGrid;

if (! $this->compact): ?>
<div class="controls">
    <?= $this->tabs ?>
    <?= $this->form ?>
</div>
<?php endif ?>
<div class="content" data-base-target="_next">
<?php

$settings = array(
    'cnt_up' => array(
        'tooltip' => $this->translate('%d hosts ok on %s'),
        'color' => '#49DF96',
        'opacity' => '0.55'
    ),
    'cnt_unreachable_hard' => array(
        'tooltip' => $this->translate('%d hosts unreachable on %s'),
        'color' => '#77AAFF',
        'opacity' => '0.55'
    ),
    'cnt_critical_hard' => array(
        'tooltip' => $this->translate('%d services critical on %s'),
        'color' => '#ff5566',
        'opacity' => '0.9'
    ),

    'cnt_warning_hard' => array(
        'tooltip' => $this->translate('%d services warning on %s'),
        'color' => '#ffaa44',
        'opacity' => '1.0'
    ),

    'cnt_down_hard' => array(
        'tooltip' => $this->translate('%d hosts down on %s'),
        'color' => '#ff5566',
        'opacity' => '0.9'
    ),
    'cnt_unknown_hard' => array(
        'tooltip' => $this->translate('%d services unknown on %s'),
        'color' => '#cc77ff',
        'opacity' => '0.7'
    ),
    'cnt_ok' => array(
        'tooltip' => $this->translate('%d services ok on %s'),
        'color' => '#49DF96',
        'opacity' => '0.55'
    )
);

$data = array();
foreach ($summary as $entry) {
    $day = $entry->day;
    $value = $entry->$column;
    $caption = sprintf(
        $settings[$column]['tooltip'],
        $value,
        $this->formatDate(strtotime($day ?? ''))
    );
    $linkFilter = Filter::matchAll(
        Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')),
        Filter::expression('timestamp', '>', strtotime($day . ' 00:00:00')),
        $form->getFilter(),
        $filter
    );
    $data[$day] = array(
        'value'   => $value,
        'caption' => $caption,
        'url'     => $this->href('monitoring/list/eventhistory?' . $linkFilter->toQueryString())
    );
}

if (! $summary->hasResult()) {
    echo $this->translate('No state changes in the selected time period.') . '</div>';
    return;
}

$from = intval($form->getValue('from', strtotime('3 months ago')));
$to = intval($form->getValue('to', time()));

// don't display more than ten years, or else this will get really slow
if ($to - $from > 315360000) {
    $from = $to - 315360000;
}

$f = new DateTime();
$f->setTimestamp($from);
$t = new DateTime();
$t->setTimestamp($to);
$diff = $t->diff($f);
$step = 124;

for ($i = 0; $i < $diff->days; $i += $step) {
    $end = clone $f;
    if ($diff->days - $i > $step) {
        // full range, move last day to next chunk
        $end->add(new DateInterval('P' . ($step - 1) . 'D'));
    } else {
        // include last day
        $end->add(new DateInterval('P' . ($diff->days - $i) . 'D'));
    }
    $grid = new HistoryColorGrid(null, $f->getTimestamp(), $end->getTimestamp());
    $grid->setColor($settings[$column]['color']);
    $grid->opacity = $settings[$column]['opacity'];
    $grid->orientation = $orientation;
    $grid->setData($data);
    $grids[] = $grid;

    $f->add(new DateInterval('P' . $step . 'D'));
}
?>
<div class="event-grid">
<?php foreach (array_reverse($grids) as $key => $grid): ?>
    <div class=" <?= $this->orientation === 'horizontal' ? '' : 'vertical' ?>">
        <?= $grid; ?>
        <?= $this->orientation === 'horizontal' ? '<br />' : '' ?>
    </div>
<?php endforeach ?>
    </div>
</div>