mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-05-28 04:34:57 -04:00
parent
3a98d2c473
commit
369a9db684
6 changed files with 92 additions and 108 deletions
|
|
@ -8,6 +8,8 @@ use Icinga\Module\Graphite\Web\Controller\MonitoringAwareController;
|
|||
use Icinga\Module\Graphite\Web\Controller\TimeRangePickerTrait;
|
||||
use Icinga\Module\Graphite\Web\Widget\Graphs;
|
||||
use Icinga\Module\Monitoring\DataView\DataView;
|
||||
use Icinga\Module\Monitoring\Object\Host;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||
use Icinga\Web\Widget\Tabextension\MenuAction;
|
||||
|
|
@ -34,13 +36,8 @@ class ListController extends MonitoringAwareController
|
|||
mt('monitoring', 'List hosts')
|
||||
);
|
||||
|
||||
$this->view->hosts = $hosts = $this->applyMonitoringRestriction(
|
||||
$this->backend->select()->from('hoststatus', [
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'host_check_command',
|
||||
'_host_check_command' => '_host_' . Graphs::getObscuredCheckCommandCustomVar()
|
||||
])
|
||||
$hostsQuery = $this->applyMonitoringRestriction(
|
||||
$this->backend->select()->from('hoststatus', ['host_name'])
|
||||
);
|
||||
|
||||
$this->view->baseUrl = $baseUrl = Url::fromPath('monitoring/host/show');
|
||||
|
|
@ -49,13 +46,23 @@ class ListController extends MonitoringAwareController
|
|||
$this->getRequest()->getUrl()->getParams()
|
||||
);
|
||||
|
||||
$this->filterQuery($hosts);
|
||||
$this->setupPaginationControl($hosts);
|
||||
$this->filterQuery($hostsQuery);
|
||||
$this->setupPaginationControl($hostsQuery);
|
||||
$this->setupLimitControl();
|
||||
$this->setupSortControl(['host_display_name' => mt('monitoring', 'Hostname')], $hosts);
|
||||
$this->setupSortControl(['host_display_name' => mt('monitoring', 'Hostname')], $hostsQuery);
|
||||
|
||||
$hosts = [];
|
||||
foreach ($hostsQuery->peekAhead($this->view->compact) as $host) {
|
||||
$host = new Host($this->backend, $host->host_name);
|
||||
$host->fetch();
|
||||
$host->fetchCustomvars();
|
||||
$hosts[] = $host;
|
||||
}
|
||||
|
||||
$this->handleTimeRangePickerRequest();
|
||||
$this->view->timeRangePicker = $this->renderTimeRangePicker($this->view);
|
||||
$this->view->hosts = $hosts;
|
||||
$this->view->hasMoreHosts = ! $this->view->compact && $hostsQuery->hasMore();
|
||||
}
|
||||
|
||||
public function servicesAction()
|
||||
|
|
@ -66,15 +73,8 @@ class ListController extends MonitoringAwareController
|
|||
mt('monitoring', 'List services')
|
||||
);
|
||||
|
||||
$this->view->services = $services = $this->applyMonitoringRestriction(
|
||||
$this->backend->select()->from('servicestatus', [
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'service_description',
|
||||
'service_display_name',
|
||||
'service_check_command',
|
||||
'_service_check_command' => '_service_' . Graphs::getObscuredCheckCommandCustomVar()
|
||||
])
|
||||
$servicesQuery = $this->applyMonitoringRestriction(
|
||||
$this->backend->select()->from('servicestatus', ['host_name', 'service_description'])
|
||||
);
|
||||
|
||||
$this->view->hostBaseUrl = $hostBaseUrl = Url::fromPath('monitoring/host/show');
|
||||
|
|
@ -89,16 +89,26 @@ class ListController extends MonitoringAwareController
|
|||
$this->getRequest()->getUrl()->getParams()
|
||||
);
|
||||
|
||||
$this->filterQuery($services);
|
||||
$this->setupPaginationControl($services);
|
||||
$this->filterQuery($servicesQuery);
|
||||
$this->setupPaginationControl($servicesQuery);
|
||||
$this->setupLimitControl();
|
||||
$this->setupSortControl([
|
||||
'service_display_name' => mt('monitoring', 'Service Name'),
|
||||
'host_display_name' => mt('monitoring', 'Hostname')
|
||||
], $services);
|
||||
], $servicesQuery);
|
||||
|
||||
$services = [];
|
||||
foreach ($servicesQuery->peekAhead($this->view->compact) as $service) {
|
||||
$service = new Service($this->backend, $service->host_name, $service->service_description);
|
||||
$service->fetch();
|
||||
$service->fetchCustomvars();
|
||||
$services[] = $service;
|
||||
}
|
||||
|
||||
$this->handleTimeRangePickerRequest();
|
||||
$this->view->timeRangePicker = $this->renderTimeRangePicker($this->view);
|
||||
$this->view->services = $services;
|
||||
$this->view->hasMoreServices = ! $this->view->compact && $servicesQuery->hasMore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use Icinga\Web\Url;
|
|||
|
||||
/** @var \Icinga\Web\View $this */
|
||||
/** @var \Icinga\Web\Widget\FilterEditor $filterEditor */
|
||||
/** @var \Icinga\Module\Monitoring\DataView\DataView $hosts */
|
||||
/** @var \Icinga\Module\Monitoring\Object\Host[] $hosts */
|
||||
/** @var bool $hasMoreHosts */
|
||||
/** @var \Icinga\Web\Url $baseUrl */
|
||||
|
||||
if (! $compact): ?>
|
||||
|
|
@ -22,13 +23,9 @@ if (! $compact): ?>
|
|||
<?php endif ?>
|
||||
<div class="content">
|
||||
<?php
|
||||
if ($hosts->hasResult()) {
|
||||
foreach ($hosts->peekAhead($compact) as $host) {
|
||||
$hostGraphs = (string) (new Host(
|
||||
$host->host_name,
|
||||
$host->host_check_command,
|
||||
$host->_host_check_command
|
||||
))->handleRequest();
|
||||
if (! empty($hosts)) {
|
||||
foreach ($hosts as $host) {
|
||||
$hostGraphs = (string) (new Host($host))->handleRequest();
|
||||
|
||||
if ($hostGraphs !== '') {
|
||||
echo '<div class="grid-item">'
|
||||
|
|
@ -47,7 +44,7 @@ if ($hosts->hasResult()) {
|
|||
}
|
||||
}
|
||||
|
||||
if (! $compact && $hosts->hasMore()) {
|
||||
if ($hasMoreHosts) {
|
||||
echo '<div class="action-links">'
|
||||
. $this->qlink(
|
||||
mt('monitoring', 'Show More'),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use Icinga\Web\Url;
|
|||
|
||||
/** @var \Icinga\Web\View $this */
|
||||
/** @var \Icinga\Web\Widget\FilterEditor $filterEditor */
|
||||
/** @var \Icinga\Module\Monitoring\DataView\DataView $services */
|
||||
/** @var \Icinga\Module\Monitoring\Object\Service[] $services */
|
||||
/** @var bool $hasMoreServices */
|
||||
/** @var \Icinga\Web\Url $hostBaseUrl */
|
||||
/** @var \Icinga\Web\Url $serviceBaseUrl */
|
||||
|
||||
|
|
@ -23,8 +24,8 @@ if (! $compact): ?>
|
|||
<?php endif ?>
|
||||
<div class="content">
|
||||
<?php
|
||||
if ($services->hasResult()) {
|
||||
foreach ($services->peekAhead($compact) as $service) {
|
||||
if (! empty($services)) {
|
||||
foreach ($services as $service) {
|
||||
echo '<div class="grid-item">'
|
||||
. '<h2>'
|
||||
. $this->qlink(
|
||||
|
|
@ -49,16 +50,11 @@ if ($services->hasResult()) {
|
|||
)
|
||||
. '</h2>';
|
||||
|
||||
echo (new Service(
|
||||
$service->host_name,
|
||||
$service->service_description,
|
||||
$service->service_check_command,
|
||||
$service->_service_check_command
|
||||
))->handleRequest();
|
||||
echo (new Service($service))->handleRequest();
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if (! $compact && $services->hasMore()) {
|
||||
if ($hasMoreServices) {
|
||||
echo '<div class="action-links">'
|
||||
. $this->qlink(
|
||||
mt('monitoring', 'Show More'),
|
||||
|
|
|
|||
|
|
@ -31,6 +31,20 @@ abstract class Graphs extends AbstractWidget
|
|||
*/
|
||||
protected static $obscuredCheckCommandCustomVar;
|
||||
|
||||
/**
|
||||
* The type of the monitored object to render the graphs of
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $monitoredObjectType;
|
||||
|
||||
/**
|
||||
* The monitored object to render the graphs of
|
||||
*
|
||||
* @var MonitoredObject
|
||||
*/
|
||||
protected $monitoredObject;
|
||||
|
||||
/**
|
||||
* Graph image width
|
||||
*
|
||||
|
|
@ -122,20 +136,11 @@ abstract class Graphs extends AbstractWidget
|
|||
switch ($object->getType()) {
|
||||
case 'host':
|
||||
/** @var Host $object */
|
||||
return new HostGraphs(
|
||||
$object->getName(),
|
||||
$object->host_check_command,
|
||||
$object->{'_host_' . Graphs::getObscuredCheckCommandCustomVar()}
|
||||
);
|
||||
return new HostGraphs($object);
|
||||
|
||||
case 'service':
|
||||
/** @var Service $object */
|
||||
return new ServiceGraphs(
|
||||
$object->getHost()->getName(),
|
||||
$object->getName(),
|
||||
$object->service_check_command,
|
||||
$object->{'_service_' . Graphs::getObscuredCheckCommandCustomVar()}
|
||||
);
|
||||
return new ServiceGraphs($object);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,14 +162,15 @@ abstract class Graphs extends AbstractWidget
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
|
||||
* we display graphs for
|
||||
* @param MonitoredObject $monitoredObject The monitored object to render the graphs of
|
||||
*/
|
||||
public function __construct($checkCommand, $obscuredCheckCommand)
|
||||
public function __construct(MonitoredObject $monitoredObject)
|
||||
{
|
||||
$this->checkCommand = $checkCommand;
|
||||
$this->obscuredCheckCommand = $obscuredCheckCommand;
|
||||
$this->monitoredObject = $monitoredObject;
|
||||
$this->checkCommand = $monitoredObject->{"{$this->monitoredObjectType}_check_command"};
|
||||
$this->obscuredCheckCommand = $monitoredObject->{
|
||||
"_{$this->monitoredObjectType}_" . Graphs::getObscuredCheckCommandCustomVar()
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,31 +4,19 @@ namespace Icinga\Module\Graphite\Web\Widget\Graphs;
|
|||
|
||||
use Icinga\Module\Graphite\Graphing\Template;
|
||||
use Icinga\Module\Graphite\Web\Widget\Graphs;
|
||||
use Icinga\Module\Monitoring\Object\Host as MonitoredHost;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class Host extends Graphs
|
||||
{
|
||||
protected $monitoredObjectType = 'host';
|
||||
|
||||
/**
|
||||
* The host to render the graphs of
|
||||
*
|
||||
* @var string
|
||||
* @var MonitoredHost
|
||||
*/
|
||||
protected $host;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
|
||||
* we display graphs for
|
||||
*/
|
||||
public function __construct($host, $checkCommand, $obscuredCheckCommand)
|
||||
{
|
||||
parent::__construct($checkCommand, $obscuredCheckCommand);
|
||||
|
||||
$this->host = $host;
|
||||
}
|
||||
protected $monitoredObject;
|
||||
|
||||
protected function getImageBaseUrl()
|
||||
{
|
||||
|
|
@ -42,22 +30,22 @@ class Host extends Graphs
|
|||
|
||||
protected function getGraphsListBaseUrl()
|
||||
{
|
||||
return Url::fromPath('graphite/list/hosts', ['host' => $this->host]);
|
||||
return Url::fromPath('graphite/list/hosts', ['host' => $this->monitoredObject->getName()]);
|
||||
}
|
||||
|
||||
protected function filterImageUrl(Url $url)
|
||||
{
|
||||
return $url->setParam('host.name', $this->host);
|
||||
return $url->setParam('host.name', $this->monitoredObject->getName());
|
||||
}
|
||||
|
||||
protected function getMonitoredObjectIdentifier()
|
||||
{
|
||||
return $this->host;
|
||||
return $this->monitoredObject->getName();
|
||||
}
|
||||
|
||||
protected function getMonitoredObjectFilter()
|
||||
{
|
||||
return ['host.name' => $this->host];
|
||||
return ['host.name' => $this->monitoredObject->getName()];
|
||||
}
|
||||
|
||||
protected function designedForMyMonitoredObjectType(Template $template)
|
||||
|
|
|
|||
|
|
@ -4,40 +4,19 @@ namespace Icinga\Module\Graphite\Web\Widget\Graphs;
|
|||
|
||||
use Icinga\Module\Graphite\Graphing\Template;
|
||||
use Icinga\Module\Graphite\Web\Widget\Graphs;
|
||||
use Icinga\Module\Monitoring\Object\Service as MonitoredService;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class Service extends Graphs
|
||||
{
|
||||
/**
|
||||
* The host to render the graphs of
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
protected $monitoredObjectType = 'service';
|
||||
|
||||
/**
|
||||
* The service to render the graphs of
|
||||
*
|
||||
* @var string
|
||||
* @var MonitoredService
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $service The service to render the graphs of
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
|
||||
* we display graphs for
|
||||
*/
|
||||
public function __construct($host, $service, $checkCommand, $obscuredCheckCommand)
|
||||
{
|
||||
parent::__construct($checkCommand, $obscuredCheckCommand);
|
||||
|
||||
$this->host = $host;
|
||||
$this->service = $service;
|
||||
}
|
||||
protected $monitoredObject;
|
||||
|
||||
protected function getImageBaseUrl()
|
||||
{
|
||||
|
|
@ -51,22 +30,30 @@ class Service extends Graphs
|
|||
|
||||
protected function getGraphsListBaseUrl()
|
||||
{
|
||||
return Url::fromPath('graphite/list/services', ['host' => $this->host, 'service' => $this->service]);
|
||||
return Url::fromPath(
|
||||
'graphite/list/services',
|
||||
['host' => $this->monitoredObject->getHost()->getName(), 'service' => $this->monitoredObject->getName()]
|
||||
);
|
||||
}
|
||||
|
||||
protected function filterImageUrl(Url $url)
|
||||
{
|
||||
return $url->setParam('host.name', $this->host)->setParam('service.name', $this->service);
|
||||
return $url
|
||||
->setParam('host.name', $this->monitoredObject->getHost()->getName())
|
||||
->setParam('service.name', $this->monitoredObject->getName());
|
||||
}
|
||||
|
||||
protected function getMonitoredObjectIdentifier()
|
||||
{
|
||||
return $this->host . ':' . $this->service;
|
||||
return $this->monitoredObject->getHost()->getName() . ':' . $this->monitoredObject->getName();
|
||||
}
|
||||
|
||||
protected function getMonitoredObjectFilter()
|
||||
{
|
||||
return ['host.name' => $this->host, 'service.name' => $this->service];
|
||||
return [
|
||||
'host.name' => $this->monitoredObject->getHost()->getName(),
|
||||
'service.name' => $this->monitoredObject->getName()
|
||||
];
|
||||
}
|
||||
|
||||
protected function designedForMyMonitoredObjectType(Template $template)
|
||||
|
|
|
|||
Loading…
Reference in a new issue