mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-05-28 04:34:57 -04:00
ShowController: add serviceAction, adjust host
This commit is contained in:
parent
b289163099
commit
5e314cc84c
2 changed files with 151 additions and 23 deletions
|
|
@ -146,29 +146,164 @@ class ShowController extends Controller
|
|||
|
||||
public function hostAction()
|
||||
{
|
||||
$this->handleDatasourceToggles();
|
||||
$this->handleGraphParams();
|
||||
$hostname = $this->view->hostname = $this->params->get('host');
|
||||
if (! $hostname) {
|
||||
throw new NotFoundError('Host is required');
|
||||
}
|
||||
$this->tabs()->activate('host');
|
||||
$hosts = $this->Config()->get('global', 'host_pattern');
|
||||
|
||||
$view = $this->view;
|
||||
$this->getTabs()->add('host', array(
|
||||
'label' => $this->translate('Graphite - Single Host'),
|
||||
'url' => $this->getRequest()->getUrl()
|
||||
))->activate('host');
|
||||
|
||||
$imgs = array();
|
||||
$this->view->templates = $this->loadTemplates();
|
||||
$this->view->templates = array();
|
||||
|
||||
foreach ($this->view->templates as $type => $template) {
|
||||
foreach ($this->templateStore->loadTemplateSets() as $setname => $set) {
|
||||
|
||||
$imgs[$type] = $this->graphiteWeb
|
||||
->select()
|
||||
->from(
|
||||
array('host' => $hosts),
|
||||
$template->getFilterString()
|
||||
)
|
||||
->where('hostname', $hostname)
|
||||
->getImages($template);
|
||||
$patterns = $set->getBasePatterns();
|
||||
if (! array_key_exists('icingaHost', $patterns)) continue;
|
||||
|
||||
foreach ($imgs[$type] as $img) {
|
||||
$this->applyGraphParams($img)
|
||||
->showLegend(! $this->params->get('hideLegend', false));
|
||||
foreach ($set->loadTemplates() as $key => $template) {
|
||||
if (strpos($template->getFilterString(), '$service') !== false) continue;
|
||||
|
||||
$imgParams = array(
|
||||
'template' => $key,
|
||||
'start' => $view->start,
|
||||
'width' => $view->width,
|
||||
'height' => $view->height
|
||||
);
|
||||
|
||||
if ($this->view->disabledDatasources) {
|
||||
$imgParams['disabled'] = $this->view->disabledDatasources;
|
||||
foreach ($this->view->disabledDatasources as $dis) {
|
||||
if ($template->hasDatasource($dis)) {
|
||||
$template->getDatasource($dis)->disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->templates[$key] = $template;
|
||||
|
||||
$imgs[$key] = $this->graphiteWeb
|
||||
->select()
|
||||
->from($template->getFilterString())
|
||||
->where('hostname', $hostname)
|
||||
->getWrappedImageLinks($template, $imgParams);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$view->images = $imgs;
|
||||
}
|
||||
|
||||
public function serviceAction()
|
||||
{
|
||||
$this->handleDatasourceToggles();
|
||||
$this->handleGraphParams();
|
||||
$hostname = $this->view->hostname = $this->params->get('host');
|
||||
$service = $this->view->service = $this->params->get('service');
|
||||
if (! $hostname) {
|
||||
throw new NotFoundError('Host is required');
|
||||
}
|
||||
if (! $service) {
|
||||
throw new NotFoundError('Service is required');
|
||||
}
|
||||
$this->getTabs()->add('service', array(
|
||||
'label' => $this->translate('Graphite - Single service'),
|
||||
'url' => $this->getRequest()->getUrl()
|
||||
))->activate('service');
|
||||
|
||||
$view = $this->view;
|
||||
|
||||
$imgs = array();
|
||||
$this->view->templates = array();
|
||||
|
||||
foreach ($this->templateStore->loadTemplateSets() as $setname => $set) {
|
||||
|
||||
$patterns = $set->getBasePatterns();
|
||||
if (! array_key_exists('icingaHost', $patterns)) continue;
|
||||
|
||||
foreach ($set->loadTemplates() as $key => $template) {
|
||||
if (strpos($template->getFilterString(), '$service') === false) continue;
|
||||
|
||||
$imgParams = array(
|
||||
'template' => $key,
|
||||
'start' => $view->start,
|
||||
'width' => $view->width,
|
||||
'height' => $view->height
|
||||
);
|
||||
|
||||
if ($this->view->disabledDatasources) {
|
||||
$imgParams['disabled'] = $this->view->disabledDatasources;
|
||||
foreach ($this->view->disabledDatasources as $dis) {
|
||||
if ($template->hasDatasource($dis)) {
|
||||
$template->getDatasource($dis)->disable();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->templates[$key] = $template;
|
||||
|
||||
$imgs[$key] = $this->graphiteWeb
|
||||
->select()
|
||||
->from($template->getFilterString())
|
||||
->where('hostname', $hostname)
|
||||
->where('service', $service)
|
||||
->getWrappedImageLinks($template, $imgParams);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$view->images = $imgs;
|
||||
}
|
||||
|
||||
public function XXXserviceAction()
|
||||
{
|
||||
$this->handleDatasourceToggles();
|
||||
$this->handleGraphParams();
|
||||
$hostname = $this->view->hostname = $this->params->get('host');
|
||||
$service = $this->view->service = $this->params->get('service');
|
||||
if (! $hostname) {
|
||||
throw new NotFoundError('Host is required');
|
||||
}
|
||||
if (! $service) {
|
||||
throw new NotFoundError('Service is required');
|
||||
}
|
||||
$this->getTabs()->add('service', array(
|
||||
'label' => $this->translate('Graphite - Single service'),
|
||||
'url' => $this->getRequest()->getUrl()
|
||||
))->activate('service');
|
||||
|
||||
$imgs = array();
|
||||
$this->view->templates = array();
|
||||
|
||||
foreach ($this->templateStore->loadTemplateSets() as $setname => $set) {
|
||||
|
||||
$patterns = $set->getBasePatterns();
|
||||
if (! array_key_exists('icingaService', $patterns)) continue;
|
||||
|
||||
foreach ($set->loadTemplates() as $key => $template) {
|
||||
|
||||
if (strpos($template->getFilterString(), '$service') === false) continue;
|
||||
|
||||
$this->view->templates[$key] = $template;
|
||||
|
||||
$imgs[$key] = $this->graphiteWeb
|
||||
->select()
|
||||
->from($template->getFilterString())
|
||||
->where('hostname', $hostname)
|
||||
->where('service', $service)
|
||||
->getImages($template);
|
||||
|
||||
foreach ($imgs[$key] as $img) {
|
||||
$this->applyGraphParams($img)
|
||||
->showLegend(! $this->params->get('hideLegend', false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,12 +383,4 @@ class ShowController extends Controller
|
|||
$this->redirectNow($url);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tabs()
|
||||
{
|
||||
return $this->view->tabs = Widget::create('tabs')->add('host', array(
|
||||
'label' => $this->translate('Graphite - Single Host'),
|
||||
'url' => $this->getRequest()->getUrl()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
run.php
1
run.php
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
$this->registerHook('Monitoring\\HostActions', '\\Icinga\\Module\\Graphite\\HostActions');
|
||||
$this->registerHook('Monitoring\\ServiceActions', '\\Icinga\\Module\\Graphite\\ServiceActions');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue