icingaweb2/application/controllers/ListController.php

57 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Url;
use Icinga\Application\Logger;
use Icinga\Data\ConfigObject;
use Icinga\Protocol\File\FileReader;
use \Zend_Controller_Action_Exception as ActionError;
2014-04-02 13:23:18 +02:00
/**
* Class ListController
*
* Application wide controller for various listing actions
*/
class ListController extends Controller
{
2014-04-02 13:23:18 +02:00
/**
* Add title tab
*
* @param string $action
*/
protected function addTitleTab($action)
{
$this->getTabs()->add($action, array(
'title' => ucfirst($action),
2014-04-02 13:23:18 +02:00
'url' => Url::fromPath(
'list/'
. str_replace(' ', '', $action)
)
))->activate($action);
}
2014-04-02 13:23:18 +02:00
/**
* Display the application log
*/
public function applicationlogAction()
{
if (! Logger::writesToFile()) {
throw new ActionError('Site not found', 404);
}
$this->addTitleTab('application log');
$pattern = '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
2014-09-05 15:33:34 +02:00
. ' - (?<message>.*)$/'; // message
$loggerWriter = Logger::getInstance()->getWriter();
$resource = new FileReader(new ConfigObject(array(
'filename' => $loggerWriter->getPath(),
'fields' => $pattern
)));
$this->view->logData = $resource->select()->order('DESC')->paginate();
}
}