Quick & dirty proposal for new grouped history overviews
This commit is contained in:
parent
1b0ddec998
commit
7ff4f55737
|
@ -0,0 +1,159 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
</div>
|
||||
<style>
|
||||
table.colorizedsummary td {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
table.colorizedsummary a {
|
||||
margin: 0;
|
||||
display: block;
|
||||
float: left;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
}
|
||||
</style>
|
||||
<div class="content">
|
||||
<?php
|
||||
|
||||
if (empty($this->summary)) {
|
||||
echo 'No entries found</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
$cols = array('cnt_events'/*, 'cnt_up', 'cnt_down', 'cnt_ok', 'cnt_critical'*/);
|
||||
$show = array('cnt_events');
|
||||
|
||||
$max = (object) array();
|
||||
|
||||
foreach ($cols as $col) {
|
||||
$max->$col = 0;
|
||||
}
|
||||
|
||||
foreach ($this->summary as & $row) {
|
||||
foreach ($cols as $col) {
|
||||
if ($row->$col > $max->$col) {
|
||||
$max->$col = $row->$col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$colors->cnt_events = array(
|
||||
$max->cnt_events * 0.80 => '#0b5',
|
||||
$max->cnt_events * 0.60 => '#2b6',
|
||||
$max->cnt_events * 0.40 => '#4b7',
|
||||
$max->cnt_events * 0.20 => '#7b9',
|
||||
0 => '#9ba',
|
||||
);
|
||||
|
||||
$colors->cnt_up = array(
|
||||
$max->cnt_up * 0.80 => '#0b5',
|
||||
$max->cnt_up * 0.60 => '#2b6',
|
||||
$max->cnt_up * 0.40 => '#4b7',
|
||||
$max->cnt_up * 0.20 => '#7b9',
|
||||
0 => '#9ba',
|
||||
);
|
||||
|
||||
$colors->cnt_ok = array(
|
||||
$max->cnt_ok * 0.80 => '#0b5',
|
||||
$max->cnt_ok * 0.60 => '#2b6',
|
||||
$max->cnt_ok * 0.40 => '#4b7',
|
||||
$max->cnt_ok * 0.20 => '#7b9',
|
||||
0 => '#9ba',
|
||||
);
|
||||
|
||||
$colors->cnt_critical = array(
|
||||
$max->cnt_critical * 0.8 => '#f34',
|
||||
$max->cnt_critical * 0.6 => '#f56',
|
||||
$max->cnt_critical * 0.4 => '#f67',
|
||||
$max->cnt_critical * 0.2 => '#f9a',
|
||||
0 => '#fcd',
|
||||
);
|
||||
|
||||
$colors->cnt_down = array(
|
||||
$max->cnt_down * 0.8 => '#f34',
|
||||
$max->cnt_down * 0.6 => '#f56',
|
||||
$max->cnt_down * 0.4 => '#f67',
|
||||
$max->cnt_down * 0.2 => '#f9a',
|
||||
0 => '#fcd',
|
||||
);
|
||||
|
||||
|
||||
function getColor(& $colors, $value, $what = 'cnt_events') {
|
||||
foreach ($colors->$what as $level => $color) {
|
||||
if ($value >= $level) {
|
||||
return $color;
|
||||
}
|
||||
}
|
||||
return 'red';
|
||||
}
|
||||
$startDay = '2014-20-02';
|
||||
$start = strtotime($day);
|
||||
$wday = date('w', $start);
|
||||
$week = date('w', $start);
|
||||
if ($wday === 0) {
|
||||
$wday = 6;
|
||||
} else {
|
||||
$wday--;
|
||||
}
|
||||
|
||||
?>
|
||||
<table class="colorizedsummary">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>M</th>
|
||||
<th>T</th>
|
||||
<th>W</th>
|
||||
<th>T</th>
|
||||
<th>F</th>
|
||||
<th>S</th>
|
||||
<th>S</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- <th><?= $startDay ?></th>-->
|
||||
|
||||
<!--
|
||||
<tr>
|
||||
<?php
|
||||
|
||||
|
||||
foreach (array_keys((array) $this->summary[0]) as $title) {
|
||||
echo '<th>' . $this->escape($title) . '</th>';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
</tr>
|
||||
-->
|
||||
<?php
|
||||
|
||||
for ($i = 0; $i <= $wday; $i++) {
|
||||
echo '<td></td>';
|
||||
}
|
||||
|
||||
foreach ($this->summary as $row) {
|
||||
$wday--;
|
||||
if ($wday < 0) {
|
||||
$wday = 6;
|
||||
$week--;
|
||||
echo '</tr><tr><!--<th>' . $row->day . '</th>-->';
|
||||
|
||||
}
|
||||
echo '<td>';
|
||||
foreach ($show as $col) {
|
||||
echo '<a style="background-color: '
|
||||
. getColor($colors, $row->$col, $col)
|
||||
. '" title="'
|
||||
. $this->escape($row->$col . ' ' . strtoupper(substr($col, 4)) . ' Events on ' . $row->day)
|
||||
. '"></a>';
|
||||
}
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
?>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
class StateHistorySummaryQuery extends IdoQuery
|
||||
{
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'day' => 'DATE(sh.state_time)',
|
||||
'cnt_events' => 'COUNT(*)',
|
||||
'cnt_up' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 0 THEN 1 ELSE 0 END)',
|
||||
'cnt_down_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_down' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unreachable_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unreachable' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 THEN 1 ELSE 0 END)',
|
||||
'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_critical' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 THEN 1 ELSE 0 END)',
|
||||
'cnt_critical_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_warning' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_warning_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
|
||||
'cnt_ok' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 0 THEN 1 ELSE 0 END)',
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->baseQuery = $this->db->select()->from(
|
||||
array('sh' => $this->prefix . 'statehistory'),
|
||||
array()
|
||||
)->join(
|
||||
array('sho' => $this->prefix . 'objects'),
|
||||
'sh.object_id = sho.object_id AND sho.is_active = 1',
|
||||
array()
|
||||
)->where('sh.state_time >= ?', '2013-11-20 00:00:00')
|
||||
->where('sh.state_type = 1')
|
||||
->where('sh.state = 2')
|
||||
->group('DATE(sh.state_time)');
|
||||
$this->joinedVirtualTables = array('statehistory' => true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
class StateHistorySummary extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'day',
|
||||
'cnt_events',
|
||||
'cnt_up',
|
||||
'cnt_down_hard',
|
||||
'cnt_down',
|
||||
'cnt_unreachable_hard',
|
||||
'cnt_unreachable',
|
||||
'cnt_unknown_hard',
|
||||
'cnt_unknown',
|
||||
'cnt_unknown_hard',
|
||||
'cnt_critical',
|
||||
'cnt_critical_hard',
|
||||
'cnt_warning',
|
||||
'cnt_warning_hard',
|
||||
'cnt_ok',
|
||||
);
|
||||
}
|
||||
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
'day' => array(
|
||||
'order' => self::SORT_DESC
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue