mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
8f26f0dbf6
commit
6622042539
@ -11,18 +11,28 @@ use Icinga\Web\Url;
|
|||||||
|
|
||||||
class Monitoring_AlertsummaryController extends Controller
|
class Monitoring_AlertsummaryController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $notificationData;
|
private $notificationData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $problemData;
|
private $problemData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init data set
|
||||||
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$tabs = $this->getTabs();
|
$tabs = $this->getTabs();
|
||||||
if (in_array($this->_request->getActionName(), array(
|
if (in_array($this->_request->getActionName(), array('alertsummary'))) {
|
||||||
'alertsummary',
|
|
||||||
))) {
|
|
||||||
$tabs->extend(new OutputFormat())->extend(new DashboardAction());
|
$tabs->extend(new OutputFormat())->extend(new DashboardAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,17 +42,26 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
$this->problemData = $this->createProblemData();
|
$this->problemData = $this->createProblemData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $action
|
||||||
|
* @param bool $title
|
||||||
|
*/
|
||||||
protected function addTitleTab($action, $title = false)
|
protected function addTitleTab($action, $title = false)
|
||||||
{
|
{
|
||||||
$title = $title ?: ucfirst($action);
|
$title = $title ?: ucfirst($action);
|
||||||
$this->getTabs()->add($action, array(
|
$this->getTabs()->add(
|
||||||
|
$action,
|
||||||
|
array(
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
// 'url' => Url::fromPath('monitoring/list/' . $action)
|
|
||||||
'url' => $this->url
|
'url' => $this->url
|
||||||
))->activate($action);
|
)
|
||||||
|
)->activate($action);
|
||||||
$this->view->title = $title;
|
$this->view->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creat full report
|
||||||
|
*/
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$this->addTitleTab('alertsummary');
|
$this->addTitleTab('alertsummary');
|
||||||
@ -55,29 +74,41 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
$this->view->trend = $this->createTrendInformation();
|
$this->view->trend = $this->createTrendInformation();
|
||||||
|
|
||||||
$this->setAutorefreshInterval(15);
|
$this->setAutorefreshInterval(15);
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_output',
|
'notification_output',
|
||||||
'notification_contact',
|
'notification_contact',
|
||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state'
|
'notification_state'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->view->notifications = $query->paginate();
|
$this->view->notifications = $query->paginate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createNotificationData() {
|
/**
|
||||||
|
* Create data for charts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function createNotificationData()
|
||||||
|
{
|
||||||
$interval = $this->getInterval();
|
$interval = $this->getInterval();
|
||||||
|
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_output',
|
'notification_output',
|
||||||
'notification_contact',
|
'notification_contact',
|
||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state'
|
'notification_state'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->setFilter(
|
$query->setFilter(
|
||||||
new Icinga\Data\Filter\FilterExpression(
|
new Icinga\Data\Filter\FilterExpression(
|
||||||
@ -93,8 +124,6 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
$data = array();
|
$data = array();
|
||||||
$period = $this->createPeriod($interval);
|
$period = $this->createPeriod($interval);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($period as $entry) {
|
foreach ($period as $entry) {
|
||||||
$id = $this->getPeriodFormat($interval, $entry->getTimestamp());
|
$id = $this->getPeriodFormat($interval, $entry->getTimestamp());
|
||||||
$data[$id] = array($id, 0);
|
$data[$id] = array($id, 0);
|
||||||
@ -112,19 +141,27 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trend information for notifications
|
||||||
|
*
|
||||||
|
* @return stdClass
|
||||||
|
*/
|
||||||
private function createTrendInformation()
|
private function createTrendInformation()
|
||||||
{
|
{
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
|
|
||||||
$beginDate = $date->sub(new DateInterval('P3D'));
|
$beginDate = $date->sub(new DateInterval('P3D'));
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_output',
|
'notification_output',
|
||||||
'notification_contact',
|
'notification_contact',
|
||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state'
|
'notification_state'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->setFilter(
|
$query->setFilter(
|
||||||
new Icinga\Data\Filter\FilterExpression(
|
new Icinga\Data\Filter\FilterExpression(
|
||||||
@ -175,18 +212,26 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perfdata for notifications
|
||||||
|
*
|
||||||
|
* @return stdClass
|
||||||
|
*/
|
||||||
private function createNotificationPerfdata()
|
private function createNotificationPerfdata()
|
||||||
{
|
{
|
||||||
$interval = $this->getInterval();
|
$interval = $this->getInterval();
|
||||||
|
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_output',
|
'notification_output',
|
||||||
'notification_contact',
|
'notification_contact',
|
||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state'
|
'notification_state'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->setFilter(
|
$query->setFilter(
|
||||||
new Icinga\Data\Filter\FilterExpression(
|
new Icinga\Data\Filter\FilterExpression(
|
||||||
@ -218,11 +263,18 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Problems for notifications
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function createProblemData()
|
private function createProblemData()
|
||||||
{
|
{
|
||||||
$interval = $this->getInterval();
|
$interval = $this->getInterval();
|
||||||
|
|
||||||
$query = $this->backend->select()->from('eventhistory', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'eventhistory',
|
||||||
|
array(
|
||||||
'host_name',
|
'host_name',
|
||||||
'service_description',
|
'service_description',
|
||||||
'object_type',
|
'object_type',
|
||||||
@ -235,7 +287,8 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'service_host_name'
|
'service_host_name'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->addFilter(
|
$query->addFilter(
|
||||||
new Icinga\Data\Filter\FilterExpression(
|
new Icinga\Data\Filter\FilterExpression(
|
||||||
@ -273,6 +326,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $defects;
|
return $defects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Healing svg image
|
||||||
|
*
|
||||||
|
* @return GridChart
|
||||||
|
*/
|
||||||
public function createHealingChart()
|
public function createHealingChart()
|
||||||
{
|
{
|
||||||
$gridChart = new GridChart();
|
$gridChart = new GridChart();
|
||||||
@ -285,7 +343,9 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
|
|
||||||
$interval = $this->getInterval();
|
$interval = $this->getInterval();
|
||||||
|
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_object_id',
|
'notification_object_id',
|
||||||
@ -294,7 +354,8 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state',
|
'notification_state',
|
||||||
'acknowledgement_entry_time'
|
'acknowledgement_entry_time'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->setFilter(
|
$query->setFilter(
|
||||||
new Icinga\Data\Filter\FilterExpression(
|
new Icinga\Data\Filter\FilterExpression(
|
||||||
@ -326,7 +387,8 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
$id = $this->getPeriodFormat($interval, $item->notification_start_time);
|
$id = $this->getPeriodFormat($interval, $item->notification_start_time);
|
||||||
|
|
||||||
if ($item->notification_state == '0' && isset($rData[$item->notification_object_id])) {
|
if ($item->notification_state == '0' && isset($rData[$item->notification_object_id])) {
|
||||||
$rData[$item->notification_object_id]['recover'] = $item->notification_start_time - $rData[$item->notification_object_id]['entry'];
|
$rData[$item->notification_object_id]['recover'] =
|
||||||
|
$item->notification_start_time - $rData[$item->notification_object_id]['entry'];
|
||||||
} elseif ($item->notification_state !== '0') {
|
} elseif ($item->notification_state !== '0') {
|
||||||
$recover = 0;
|
$recover = 0;
|
||||||
if ($item->acknowledgement_entry_time) {
|
if ($item->acknowledgement_entry_time) {
|
||||||
@ -392,6 +454,11 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $gridChart;
|
return $gridChart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifications and defects
|
||||||
|
*
|
||||||
|
* @return GridChart
|
||||||
|
*/
|
||||||
public function createDefectImage()
|
public function createDefectImage()
|
||||||
{
|
{
|
||||||
$gridChart = new GridChart();
|
$gridChart = new GridChart();
|
||||||
@ -423,22 +490,35 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $gridChart;
|
return $gridChart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top recent alerts
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function createRecentAlerts()
|
private function createRecentAlerts()
|
||||||
{
|
{
|
||||||
$query = $this->backend->select()->from('notification', array(
|
$query = $this->backend->select()->from(
|
||||||
|
'notification',
|
||||||
|
array(
|
||||||
'host',
|
'host',
|
||||||
'service',
|
'service',
|
||||||
'notification_output',
|
'notification_output',
|
||||||
'notification_contact',
|
'notification_contact',
|
||||||
'notification_start_time',
|
'notification_start_time',
|
||||||
'notification_state'
|
'notification_state'
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$query->order('notification_start_time', 'desc');
|
$query->order('notification_start_time', 'desc');
|
||||||
|
|
||||||
return $query->paginate(5);
|
return $query->paginate(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval selector box
|
||||||
|
*
|
||||||
|
* @return SelectBox
|
||||||
|
*/
|
||||||
private function createIntervalBox()
|
private function createIntervalBox()
|
||||||
{
|
{
|
||||||
$box = new SelectBox(
|
$box = new SelectBox(
|
||||||
@ -456,6 +536,14 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return $box;
|
return $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return reasonable date time format for an interval
|
||||||
|
*
|
||||||
|
* @param string $interval
|
||||||
|
* @param string $timestamp
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
private function getPeriodFormat($interval, $timestamp)
|
private function getPeriodFormat($interval, $timestamp)
|
||||||
{
|
{
|
||||||
$format = '';
|
$format = '';
|
||||||
@ -472,6 +560,12 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return strftime($format, $timestamp);
|
return strftime($format, $timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a reasonable period based in interval strings
|
||||||
|
*
|
||||||
|
* @param $interval
|
||||||
|
* @return DatePeriod
|
||||||
|
*/
|
||||||
private function createPeriod($interval)
|
private function createPeriod($interval)
|
||||||
{
|
{
|
||||||
if ($interval === '1d') {
|
if ($interval === '1d') {
|
||||||
@ -485,6 +579,12 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return start timestamps based on interval strings
|
||||||
|
*
|
||||||
|
* @param $interval
|
||||||
|
* @return DateTime|null
|
||||||
|
*/
|
||||||
private function getBeginDate($interval)
|
private function getBeginDate($interval)
|
||||||
{
|
{
|
||||||
$new = new DateTime();
|
$new = new DateTime();
|
||||||
@ -501,8 +601,20 @@ class Monitoring_AlertsummaryController extends Controller
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for interval
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws Zend_Controller_Action_Exception
|
||||||
|
*/
|
||||||
private function getInterval()
|
private function getInterval()
|
||||||
{
|
{
|
||||||
return $this->getParam('interval', '1d');
|
$interval = $this->getParam('interval', '1d');
|
||||||
|
if (false === in_array($interval, array('1d', '1w', '1m', '1y'))) {
|
||||||
|
throw new Zend_Controller_Action_Exception($this->translate('Value for interval not valid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user