2013-09-09 13:55:29 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Application\Config;
|
2014-02-26 11:19:52 +01:00
|
|
|
use Icinga\Logger\Logger;
|
2013-09-09 13:55:29 +02:00
|
|
|
use Icinga\Web\Form;
|
2014-06-22 14:04:03 +02:00
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2013-09-09 13:55:29 +02:00
|
|
|
use Icinga\Chart\SVGRenderer;
|
|
|
|
use Icinga\Chart\GridChart;
|
2013-10-22 12:08:44 +02:00
|
|
|
use Icinga\Chart\Palette;
|
2013-09-09 13:55:29 +02:00
|
|
|
use Icinga\Chart\Axis;
|
2013-10-22 12:08:44 +02:00
|
|
|
use Icinga\Chart\PieChart;
|
2014-06-22 14:04:03 +02:00
|
|
|
use Icinga\Chart\Unit\StaticAxis;
|
2013-09-09 13:55:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Monitoring_CommandController
|
|
|
|
*
|
|
|
|
* Interface to send commands and display forms
|
|
|
|
*/
|
|
|
|
|
2014-06-22 14:04:03 +02:00
|
|
|
class Monitoring_ChartController extends Controller
|
2013-09-09 13:55:29 +02:00
|
|
|
{
|
2014-08-28 16:52:02 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->view->compact = $this->_request->getParam('view') === 'compact';
|
|
|
|
}
|
|
|
|
|
2014-07-09 18:04:03 +02:00
|
|
|
public function testAction()
|
|
|
|
{
|
2013-09-09 13:55:29 +02:00
|
|
|
$this->chart = new GridChart();
|
2014-08-27 14:00:01 +02:00
|
|
|
$this->chart->alignTopLeft();
|
2014-06-22 14:04:03 +02:00
|
|
|
$this->chart->setAxisLabel('X axis label', 'Y axis label')->setXAxis(new StaticAxis());
|
2013-09-09 13:55:29 +02:00
|
|
|
$data1 = array();
|
|
|
|
$data2 = array();
|
|
|
|
$data3 = array();
|
2014-07-09 18:04:03 +02:00
|
|
|
for ($i = 0; $i < 25; $i++) {
|
|
|
|
$data3[] = array('Label ' . $i, rand(0, 30));
|
2013-09-09 13:55:29 +02:00
|
|
|
}
|
2013-10-23 13:05:06 +02:00
|
|
|
|
|
|
|
/*
|
2013-09-09 13:55:29 +02:00
|
|
|
$this->chart->drawLines(
|
|
|
|
array(
|
|
|
|
'label' => 'Nr of outtakes',
|
|
|
|
'color' => 'red',
|
|
|
|
'width' => '5',
|
|
|
|
|
|
|
|
'data' => $data
|
|
|
|
), array(
|
|
|
|
'label' => 'Some line',
|
|
|
|
'color' => 'blue',
|
|
|
|
'width' => '4',
|
|
|
|
|
|
|
|
'data' => $data3,
|
|
|
|
'showPoints' => true
|
|
|
|
)
|
|
|
|
);
|
2013-10-23 13:05:06 +02:00
|
|
|
*/
|
2013-09-09 13:55:29 +02:00
|
|
|
$this->chart->drawBars(
|
|
|
|
array(
|
|
|
|
'label' => 'Some other line',
|
2013-10-22 12:08:44 +02:00
|
|
|
'color' => 'green',
|
2013-09-09 13:55:29 +02:00
|
|
|
'data' => $data3,
|
|
|
|
'showPoints' => true
|
|
|
|
)
|
|
|
|
);
|
2013-10-23 13:05:06 +02:00
|
|
|
/*
|
2013-09-09 13:55:29 +02:00
|
|
|
$this->chart->drawLines(
|
|
|
|
array(
|
|
|
|
'label' => 'Nr of outtakes',
|
|
|
|
'color' => 'yellow',
|
|
|
|
'width' => '5',
|
|
|
|
'data' => $data2
|
|
|
|
)
|
|
|
|
);
|
2013-10-23 13:05:06 +02:00
|
|
|
*/
|
2013-09-09 13:55:29 +02:00
|
|
|
$this->view->svg = $this->chart;
|
|
|
|
}
|
2013-10-22 12:08:44 +02:00
|
|
|
|
|
|
|
public function hostgroupAction()
|
|
|
|
{
|
2014-06-22 14:04:03 +02:00
|
|
|
$query = $this->backend->select()->from(
|
|
|
|
'groupsummary',
|
2013-10-22 12:08:44 +02:00
|
|
|
array(
|
2013-10-23 13:05:06 +02:00
|
|
|
'hostgroup',
|
|
|
|
'hosts_up',
|
|
|
|
'hosts_unreachable_handled',
|
|
|
|
'hosts_unreachable_unhandled',
|
|
|
|
'hosts_down_handled',
|
|
|
|
'hosts_down_unhandled',
|
|
|
|
'hosts_pending',
|
|
|
|
'services_ok',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_pending'
|
2013-10-22 12:08:44 +02:00
|
|
|
)
|
2013-10-23 13:05:06 +02:00
|
|
|
)->getQuery()->fetchAll();
|
2014-07-21 13:06:35 +02:00
|
|
|
$this->view->height = intval($this->getParam('height', 500));
|
|
|
|
$this->view->width = intval($this->getParam('width', 500));
|
2013-10-23 13:05:06 +02:00
|
|
|
if (count($query) === 1) {
|
2014-08-28 16:50:29 +02:00
|
|
|
$this->drawHostGroupPie($query[0]);
|
2013-10-23 13:05:06 +02:00
|
|
|
} else {
|
|
|
|
$this->drawHostGroupChart($query);
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 12:08:44 +02:00
|
|
|
|
2013-10-23 13:05:06 +02:00
|
|
|
public function servicegroupAction()
|
|
|
|
{
|
2014-06-22 14:04:03 +02:00
|
|
|
$query = $this->backend->select()->from(
|
|
|
|
'groupsummary',
|
2013-10-22 12:08:44 +02:00
|
|
|
array(
|
2013-10-23 13:05:06 +02:00
|
|
|
'servicegroup',
|
|
|
|
'services_ok',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_pending'
|
|
|
|
)
|
|
|
|
)->getQuery()->fetchAll();
|
2014-07-21 13:06:35 +02:00
|
|
|
$this->view->height = intval($this->getParam('height', 500));
|
|
|
|
$this->view->width = intval($this->getParam('width', 500));
|
2013-10-23 13:05:06 +02:00
|
|
|
|
|
|
|
|
2014-08-28 16:50:29 +02:00
|
|
|
if (count($query) === 1) {
|
|
|
|
$this->drawServiceGroupPie($query[0]);
|
|
|
|
} else {
|
|
|
|
$this->drawServiceGroupChart($query);
|
|
|
|
}
|
2013-10-23 13:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function drawServiceGroupChart($query)
|
|
|
|
{
|
|
|
|
$okBars = array();
|
|
|
|
$warningBars = array();
|
|
|
|
$critBars = array();
|
|
|
|
$unknownBars = array();
|
|
|
|
foreach ($query as $servicegroup) {
|
|
|
|
$okBars[] = array($servicegroup->servicegroup, $servicegroup->services_ok);
|
|
|
|
$warningBars[] = array($servicegroup->servicegroup, $servicegroup->services_warning_unhandled);
|
|
|
|
$critBars[] = array($servicegroup->servicegroup, $servicegroup->services_critical_unhandled);
|
|
|
|
$unknownBars[] = array($servicegroup->servicegroup, $servicegroup->services_unknown_unhandled);
|
|
|
|
}
|
|
|
|
$this->view->chart = new GridChart();
|
2014-08-27 14:00:01 +02:00
|
|
|
$this->view->chart->alignTopLeft();
|
2014-07-09 18:13:01 +02:00
|
|
|
$this->view->chart->setAxisLabel('', t('Services'))
|
2014-07-21 17:17:09 +02:00
|
|
|
->setXAxis(new \Icinga\Chart\Unit\StaticAxis())
|
|
|
|
->setAxisMin(null, 0);
|
2014-07-09 18:13:01 +02:00
|
|
|
|
2013-10-23 13:05:06 +02:00
|
|
|
$this->view->chart->drawBars(
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Ok'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#44bb77',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $okBars
|
|
|
|
),
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Warning'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#ffaa44',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $warningBars
|
2013-10-22 12:08:44 +02:00
|
|
|
),
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Critical'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#ff5566',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $critBars
|
|
|
|
),
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Unknown'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#dd66ff',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $unknownBars
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function drawHostGroupChart($query)
|
|
|
|
{
|
|
|
|
$upBars = array();
|
|
|
|
$downBars = array();
|
|
|
|
$unreachableBars = array();
|
|
|
|
foreach ($query as $hostgroup) {
|
2014-07-09 18:04:03 +02:00
|
|
|
$upBars[] = array(
|
|
|
|
$hostgroup->hostgroup,
|
|
|
|
$hostgroup->hosts_up
|
|
|
|
);
|
|
|
|
$downBars[] = array(
|
|
|
|
$hostgroup->hostgroup,
|
|
|
|
$hostgroup->hosts_down_unhandled
|
|
|
|
);
|
|
|
|
$unreachableBars[] = array(
|
|
|
|
$hostgroup->hostgroup,
|
|
|
|
$hostgroup->hosts_unreachable_unhandled
|
|
|
|
);
|
2013-10-23 13:05:06 +02:00
|
|
|
}
|
|
|
|
$this->view->chart = new GridChart();
|
2014-08-27 14:00:01 +02:00
|
|
|
$this->view->chart->alignTopLeft();
|
2014-07-21 17:17:09 +02:00
|
|
|
$this->view->chart->setAxisLabel('', t('Hosts'))
|
|
|
|
->setXAxis(new StaticAxis())
|
|
|
|
->setAxisMin(null, 0);
|
2013-10-23 13:05:06 +02:00
|
|
|
$this->view->chart->drawBars(
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Up'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#44bb77',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $upBars
|
|
|
|
),
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Down'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#ff5566',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $downBars
|
|
|
|
),
|
|
|
|
array(
|
2014-07-09 18:13:01 +02:00
|
|
|
'label' => t('Unreachable'),
|
2014-03-08 00:24:41 +01:00
|
|
|
'color' => '#dd66ff',
|
2013-10-23 13:05:06 +02:00
|
|
|
'stack' => 'stack1',
|
|
|
|
'data' => $unreachableBars
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-28 16:50:29 +02:00
|
|
|
private function drawServiceGroupPie($query)
|
2013-10-23 13:05:06 +02:00
|
|
|
{
|
|
|
|
$this->view->chart = new PieChart();
|
2014-08-27 14:00:01 +02:00
|
|
|
$this->view->chart->alignTopLeft();
|
2014-08-28 16:50:29 +02:00
|
|
|
$this->view->chart->drawPie(array(
|
2013-10-23 13:05:06 +02:00
|
|
|
'data' => array(
|
2014-08-21 03:58:36 +02:00
|
|
|
(int) $query->services_ok,
|
2013-10-23 13:05:06 +02:00
|
|
|
(int) $query->services_warning_unhandled,
|
|
|
|
(int) $query->services_warning_handled,
|
|
|
|
(int) $query->services_critical_unhandled,
|
|
|
|
(int) $query->services_critical_handled,
|
|
|
|
(int) $query->services_unknown_unhandled,
|
|
|
|
(int) $query->services_unknown_handled,
|
|
|
|
(int) $query->services_pending
|
|
|
|
),
|
2014-08-21 03:58:36 +02:00
|
|
|
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'),
|
2013-10-23 13:05:06 +02:00
|
|
|
'labels'=> array(
|
2014-08-21 03:58:36 +02:00
|
|
|
$query->services_ok . ' Up Services',
|
2014-07-09 18:13:01 +02:00
|
|
|
$query->services_warning_handled . t(' Warning Services (Handled)'),
|
|
|
|
$query->services_warning_unhandled . t(' Warning Services (Unhandled)'),
|
|
|
|
$query->services_critical_handled . t(' Down Services (Handled)'),
|
|
|
|
$query->services_critical_unhandled . t(' Down Services (Unhandled)'),
|
|
|
|
$query->services_unknown_handled . t(' Unreachable Services (Handled)'),
|
|
|
|
$query->services_unknown_unhandled . t(' Unreachable Services (Unhandled)'),
|
|
|
|
$query->services_pending . t(' Pending Services')
|
2014-08-28 16:50:29 +02:00
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function drawHostGroupPie($query)
|
|
|
|
{
|
|
|
|
$this->view->chart = new PieChart();
|
|
|
|
$this->view->chart->alignTopLeft();
|
|
|
|
$this->view->chart->drawPie(array(
|
|
|
|
'data' => array(
|
|
|
|
(int) $query->hosts_up,
|
|
|
|
(int) $query->hosts_down_handled,
|
|
|
|
(int) $query->hosts_down_unhandled,
|
|
|
|
(int) $query->hosts_unreachable_handled,
|
|
|
|
(int) $query->hosts_unreachable_unhandled,
|
|
|
|
(int) $query->hosts_pending
|
|
|
|
),
|
|
|
|
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#E066FF', '#f099FF', '#fefefe'),
|
|
|
|
'labels'=> array(
|
|
|
|
(int) $query->hosts_up . ' Up Hosts',
|
|
|
|
(int) $query->hosts_down_handled . t(' Down Hosts (Handled)'),
|
|
|
|
(int) $query->hosts_down_unhandled . t(' Down Hosts (Unhandled)'),
|
|
|
|
(int) $query->hosts_unreachable_handled . t(' Unreachable Hosts (Handled)'),
|
|
|
|
(int) $query->hosts_unreachable_unhandled . t(' Unreachable Hosts (Unhandled)'),
|
|
|
|
(int) $query->hosts_pending . t(' Pending Hosts')
|
|
|
|
)
|
|
|
|
), array(
|
|
|
|
'data' => array(
|
|
|
|
(int) $query->services_ok,
|
|
|
|
(int) $query->services_warning_unhandled,
|
|
|
|
(int) $query->services_warning_handled,
|
|
|
|
(int) $query->services_critical_unhandled,
|
|
|
|
(int) $query->services_critical_handled,
|
|
|
|
(int) $query->services_unknown_unhandled,
|
|
|
|
(int) $query->services_unknown_handled,
|
|
|
|
(int) $query->services_pending
|
|
|
|
),
|
|
|
|
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'),
|
|
|
|
'labels'=> array(
|
|
|
|
$query->services_ok . ' Up Services',
|
|
|
|
$query->services_warning_handled . t(' Warning Services (Handled)'),
|
|
|
|
$query->services_warning_unhandled . t(' Warning Services (Unhandled)'),
|
|
|
|
$query->services_critical_handled . t(' Down Services (Handled)'),
|
|
|
|
$query->services_critical_unhandled . t(' Down Services (Unhandled)'),
|
|
|
|
$query->services_unknown_handled . t(' Unreachable Services (Handled)'),
|
|
|
|
$query->services_unknown_unhandled . t(' Unreachable Services (Unhandled)'),
|
|
|
|
$query->services_pending . t(' Pending Services')
|
|
|
|
)
|
2013-10-23 13:05:06 +02:00
|
|
|
));
|
2013-10-22 12:08:44 +02:00
|
|
|
}
|
2014-03-08 00:24:41 +01:00
|
|
|
}
|