From e2bfc06d6cba32522e999649823c43df1c5bc47b Mon Sep 17 00:00:00 2001 From: Alexander Klimov Date: Tue, 1 Apr 2014 11:48:44 +0200 Subject: [PATCH] Moved application log from monitoring module refs #4514 --- application/controllers/ListController.php | 141 ++++++++++++++++++ .../views/scripts/list/applicationlog.phtml | 0 .../controllers/ListController.php | 22 --- 3 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 application/controllers/ListController.php rename {modules/monitoring/application => application}/views/scripts/list/applicationlog.phtml (100%) diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php new file mode 100644 index 000000000..34208757a --- /dev/null +++ b/application/controllers/ListController.php @@ -0,0 +1,141 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + * + */ +// {{{ICINGA_LICENSE_HEADER}}} + +use Icinga\Module\Monitoring\Controller; +use Icinga\Web\Hook; +use Icinga\Web\Widget\Tabextension\DashboardAction; +use Icinga\Web\Widget\Tabextension\OutputFormat; +use Icinga\Web\Widget\Tabs; +use Icinga\Module\Monitoring\Backend; +use Icinga\Application\Config as IcingaConfig; + +use Icinga\Filter\Filterable; +use Icinga\Web\Url; +use Icinga\Data\ResourceFactory; + +class ListController extends Controller +{ + /** + * The backend used for this controller + * + * @var Backend + */ + protected $backend; + /** + * Retrieve backend and hooks for this controller + * + * @see ActionController::init + */ + public function init() + { + $this->backend = Backend::createBackend($this->_getParam('backend')); + $this->view->grapher = Hook::get('grapher'); + $this->createTabs(); + $this->view->activeRowHref = $this->getParam('detail'); + $this->view->compact = ($this->_request->getParam('view') === 'compact'); + } + + /** + * Overwrite the backend to use (used for testing) + * + * @param Backend $backend The Backend that should be used for querying + */ + public function setBackend($backend) + { + $this->backend = $backend; + } + + /** + * Apply current users monitoring/filter restrictions to the given query + * + * @param $query Filterable Query that should be filtered + * @return Filterable + */ + protected function applyRestrictions(Filterable $query) + { + foreach ($this->getRestrictions('monitoring/filter') as $restriction) { + parse_str($restriction, $filter); + foreach ($filter as $k => $v) { + if ($query->isValidFilterTarget($k)) { + // TODO: This is NOT enough. We need to fix filters and get + // applyAuthFilters back. + $query->where($k, $v); + } + } + } + return $query; + } + + protected function addTitleTab($action) + { + $this->getTabs()->add($action, array( + 'title' => ucfirst($action), + 'url' => Url::fromPath('monitoring/list/' . $action) + ))->activate($action); + } + + /** + * Return all tabs for this controller + * + * @return Tabs + */ + private function createTabs() + { + $tabs = $this->getTabs(); + if (in_array($this->_request->getActionName(), array( + 'hosts', + 'services', + 'eventhistory', + 'notifications' + ))) { + $tabs->extend(new OutputFormat())->extend(new DashboardAction()); + } + } + + public function applicationlogAction() + { + $this->addTitleTab('application log'); + $config_ini = IcingaConfig::app()->toArray(); + if (!in_array('logging', $config_ini) || ( + in_array('type', $config_ini['logging']) && + $config_ini['logging']['type'] === 'stream' && + in_array('target', $config_ini['logging']) && + file_exists($config_ini['logging']['target']) + ) + ) { + $config = ResourceFactory::getResourceConfig('logfile'); + $resource = ResourceFactory::createResource($config); + $this->view->logData = $resource->select()->paginate(); + } else { + $this->view->logData = null; + } + } +} +// @codingStandardsIgnoreEnd diff --git a/modules/monitoring/application/views/scripts/list/applicationlog.phtml b/application/views/scripts/list/applicationlog.phtml similarity index 100% rename from modules/monitoring/application/views/scripts/list/applicationlog.phtml rename to application/views/scripts/list/applicationlog.phtml diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index c875ed69e..89b84873f 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -57,7 +57,6 @@ use Icinga\Module\Monitoring\Filter\UrlViewFilter; use Icinga\Module\Monitoring\DataView\ServiceStatus; use Icinga\Filter\Filterable; use Icinga\Web\Url; -use Icinga\Data\ResourceFactory; class Monitoring_ListController extends Controller { @@ -628,26 +627,5 @@ class Monitoring_ListController extends Controller $tabs->extend(new OutputFormat())->extend(new DashboardAction()); } } - - public function applicationlogAction() - { - $this->addTitleTab('application log'); - $config_ini = IcingaConfig::app()->toArray(); - if (!in_array('logging', $config_ini) || ( - in_array('type', $config_ini['logging']) && - $config_ini['logging']['type'] === 'stream' && - in_array('target', $config_ini['logging']) && - file_exists($config_ini['logging']['target']) - ) - ) { - $config = ResourceFactory::getResourceConfig('logfile'); - $resource = ResourceFactory::createResource($config); - $this->view->logData = $resource->select()->paginate(); - - //$resource->select()->andWhere('error')->order('desc')->limit(200, 50)->fetchAll(); - } else { - $this->view->logData = null; - } - } } // @codingStandardsIgnoreEnd