* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Web\Form; use Icinga\Web\Controller\ActionController; use Icinga\Filter\Filter; use Icinga\Filter\FilterAttribute; use Icinga\Filter\Type\TextFilter; use Icinga\Application\Logger; use Icinga\Module\Monitoring\Filter\Type\StatusFilter; use Icinga\Module\Monitoring\Filter\UrlViewFilter; use Icinga\Web\Url; class FilterController extends ActionController { /** * @var Filter */ private $registry; public function indexAction() { $this->registry = new Filter(); $filter = new UrlViewFilter(); $this->view->form = new Form(); $this->view->form->addElement( 'text', 'query', array( 'name' => 'query', 'label' => 'search', 'type' => 'search', 'data-icinga-component' => 'app/semanticsearch', 'data-icinga-target' => 'host', 'helptext' => 'Filter test' ) ); $this->view->form->addElement( 'submit', 'btn_submit', array( 'name' => 'submit' ) ); $this->setupQueries(); $this->view->form->setRequest($this->getRequest()); if ($this->view->form->isSubmittedAndValid()) { $tree = $this->registry->createQueryTreeForFilter($this->view->form->getValue('query')); $this->view->tree = new \Icinga\Web\Widget\FilterBadgeRenderer($tree); $view = \Icinga\Module\Monitoring\DataView\HostAndServiceStatus::fromRequest($this->getRequest()); $cv = new \Icinga\Module\Monitoring\Filter\Backend\IdoQueryConverter($view); $this->view->sqlString = $cv->treeToSql($tree); $this->view->params = $cv->getParams(); } else if ($this->getRequest()->getHeader('accept') == 'application/json') { $this->getResponse()->setHeader('Content-Type', 'application/json'); $this->_helper->json($this->parse($this->getRequest()->getParam('query', ''))); } } private function setupQueries() { $this->registry->addDomain(\Icinga\Module\Monitoring\Filter\MonitoringFilter::hostFilter()); } private function parse($text) { try { return $this->registry->getProposalsForQuery($text); } catch (\Exception $exc) { Logger::error($exc); } } }