public function filterAction()
 {
     $flat = array();
     $filter = Filter::fromQueryString('vars.bpconfig=*');
     Benchmark::measure('ready');
     $objs = IcingaHost::loadAll($this->db());
     Benchmark::measure('db done');
     foreach ($objs as $host) {
         $flat[$host->id] = (object) array();
         foreach ($host->getProperties() as $k => $v) {
             $flat[$host->id]->{$k} = $v;
         }
     }
     Benchmark::measure('objects ready');
     $vars = IcingaHostVar::loadAll($this->db());
     Benchmark::measure('vars loaded');
     foreach ($vars as $var) {
         if (!array_key_exists($var->host_id, $flat)) {
             continue;
         }
         // Templates?
         $flat[$var->host_id]->{'vars.' . $var->varname} = $var->varvalue;
     }
     Benchmark::measure('vars done');
     foreach ($flat as $host) {
         if ($filter->matches($host)) {
             echo $host->object_name . "\n";
         }
     }
     return;
     Benchmark::measure('all done');
 }
Пример #2
0
 protected function filter()
 {
     if ($this->filter === null) {
         $this->filter = Filter::fromQueryString($this->filter_expression);
     }
     return $this->filter;
 }
Пример #3
0
 public function getFilter()
 {
     if ($this->filter === null) {
         $this->filter = Filter::fromQueryString((string) $this->url()->getParams());
     }
     return $this->filter;
 }
 /**
  * Fetch all downtimes matching the current filter and add tabs
  */
 public function init()
 {
     $this->filter = Filter::fromQueryString(str_replace('downtime_id', 'downtime_internal_id', (string) $this->params));
     $query = $this->backend->select()->from('downtime', array('id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', 'scheduled_start' => 'downtime_scheduled_start', 'scheduled_end' => 'downtime_scheduled_end', 'end' => 'downtime_end', 'duration' => 'downtime_duration', 'is_flexible' => 'downtime_is_flexible', 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', 'host_state', 'service_state', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
     $this->applyRestriction('monitoring/filter/objects', $query);
     $this->downtimes = $query;
     $this->getTabs()->add('downtimes', array('icon' => 'plug', 'label' => $this->translate('Downtimes') . sprintf(' (%d)', $query->count()), 'title' => $this->translate('Display detailed information about multiple downtimes.'), 'url' => 'monitoring/downtimes/show'))->activate('downtimes');
 }
 /**
  * Fetch all comments matching the current filter and add tabs
  */
 public function init()
 {
     $this->filter = Filter::fromQueryString(str_replace('comment_id', 'comment_internal_id', (string) $this->params));
     $query = $this->backend->select()->from('comment', array('id' => 'comment_internal_id', 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', 'type' => 'comment_type', 'persistent' => 'comment_is_persistent', 'expiration' => 'comment_expiration', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
     $this->applyRestriction('monitoring/filter/objects', $query);
     $this->comments = $query;
     $this->getTabs()->add('comments', array('icon' => 'comment', 'label' => $this->translate('Comments') . sprintf(' (%d)', $query->count()), 'title' => $this->translate('Display detailed information about multiple comments.'), 'url' => 'monitoring/comments/show'))->activate('comments');
 }
 public function testAction()
 {
     $pdb = new PuppetDbApi('v4', 'pe2015.example.com');
     // $filter = Filter::fromQueryString('type=Nagios_host&exported=true');
     // echo FilterRenderer::forFilter($filter)->toJson();
     $facts = $pdb->fetchFacts(Filter::fromQueryString('name=kernel|name=osfamily|name=partitions'));
     // certname=pe2015.example.com
 }
Пример #7
0
 /**
  * Get the filter from URL parameters or exit immediately if the filter is empty
  *
  * @return Filter
  */
 protected function getFilterOrExitIfEmpty()
 {
     $filter = Filter::fromQueryString((string) $this->params);
     if ($filter->isEmpty()) {
         $this->getResponse()->json()->setFailData(array('filter' => 'Filter is required and must not be empty'))->sendResponse();
     }
     return $filter;
 }
Пример #8
0
 public function init()
 {
     $serviceList = new ServiceList($this->backend);
     $this->applyRestriction('monitoring/filter/objects', $serviceList);
     $serviceList->addFilter(Filter::fromQueryString((string) $this->params->without(array('service_problem', 'service_handled', 'view'))));
     $this->serviceList = $serviceList;
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
     $this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u services'), count($this->serviceList)), 'label' => $this->translate('Services') . sprintf(' (%d)', count($this->serviceList)), 'url' => Url::fromRequest(), 'icon' => 'services'))->extend(new DashboardAction())->activate('show');
 }
Пример #9
0
 public function init()
 {
     $hostList = new HostList($this->backend);
     $hostList->setFilter(Filter::fromQueryString((string) $this->params));
     $this->applyRestriction('monitoring/filter/objects', $hostList);
     $this->hostList = $hostList;
     $this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'url' => Url::fromRequest(), 'icon' => 'host'))->extend(new DashboardAction())->activate('show');
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
 }
 /**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $filterable     The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected static function applyRestriction($restriction, Filterable $filterable)
 {
     $restrictions = Filter::matchAny();
     foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
         $restrictions->addFilter(Filter::fromQueryString($filter));
     }
     $filterable->applyFilter($restrictions);
     return $filterable;
 }
Пример #11
0
 public function init()
 {
     $hostList = new HostList($this->backend);
     $this->applyRestriction('monitoring/filter/objects', $hostList);
     $hostList->addFilter(Filter::fromQueryString((string) $this->params));
     $this->hostList = $hostList;
     $this->hostList->setColumns(array('host_acknowledged', 'host_active_checks_enabled', 'host_display_name', 'host_event_handler_enabled', 'host_flap_detection_enabled', 'host_handled', 'host_in_downtime', 'host_is_flapping', 'host_last_state_change', 'host_name', 'host_notifications_enabled', 'host_obsessing', 'host_passive_checks_enabled', 'host_problem', 'host_state', 'instance_name'));
     $this->view->baseFilter = $this->hostList->getFilter();
     $this->getTabs()->add('show', array('label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'url' => Url::fromRequest()))->extend(new DashboardAction())->extend(new MenuAction())->activate('show');
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
 }
Пример #12
0
 /**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $view           The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected function applyRestriction($restriction, Filterable $view)
 {
     $restrictions = Filter::matchAny();
     $restrictions->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', function ($c) {
         return preg_match('/^_(?:host|service)_/', $c);
     }));
     foreach ($this->getRestrictions($restriction) as $filter) {
         try {
             $restrictions->addFilter(Filter::fromQueryString($filter));
         } catch (QueryException $e) {
             throw new ConfigurationError($this->translate('Cannot apply restriction %s using the filter %s. You can only use the following columns: %s'), $restriction, $filter, implode(', ', array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', '_(host|service)_<customvar-name>')), $e);
         }
     }
     $view->applyFilter($restrictions);
     return $view;
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function isValid($formData)
 {
     if (!parent::isValid($formData)) {
         return false;
     }
     if (($filterString = $this->getValue('filter')) !== null) {
         $filter = Filter::matchAll();
         $filter->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'instance_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', function ($c) {
             return preg_match('/^_(?:host|service)_/', $c);
         }));
         try {
             $filter->addFilter(Filter::fromQueryString($filterString));
         } catch (QueryException $_) {
             $this->getElement('filter')->addError(sprintf($this->translate('Invalid filter provided. You can only use the following columns: %s'), implode(', ', array('instance_name', 'host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', '_(host|service)_<customvar-name>'))));
             return false;
         }
     }
     return true;
 }
Пример #14
0
 /**
  * Fetch all downtimes matching the current filter and add tabs
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function init()
 {
     $this->filter = Filter::fromQueryString(str_replace('downtime_id', 'downtime_internal_id', (string) $this->params));
     $query = $this->backend->select()->from('downtime', array('id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', 'scheduled_start' => 'downtime_scheduled_start', 'scheduled_end' => 'downtime_scheduled_end', 'end' => 'downtime_end', 'duration' => 'downtime_duration', 'is_flexible' => 'downtime_is_flexible', 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', 'host_state', 'service_state', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
     $this->applyRestriction('monitoring/filter/objects', $query);
     $this->downtimes = $query->getQuery()->fetchAll();
     if (false === $this->downtimes) {
         throw new Zend_Controller_Action_Exception($this->translate('Downtime not found'));
     }
     $this->getTabs()->add('downtimes', array('title' => $this->translate('Display detailed information about multiple downtimes.'), 'icon' => 'plug', 'label' => $this->translate('Downtimes') . sprintf(' (%d)', count($this->downtimes)), 'url' => 'monitoring/downtimes/show'))->activate('downtimes');
     foreach ($this->downtimes as $downtime) {
         if (isset($downtime->service_description)) {
             $downtime->isService = true;
         } else {
             $downtime->isService = false;
         }
         if ($downtime->isService) {
             $downtime->stateText = Service::getStateText($downtime->service_state);
         } else {
             $downtime->stateText = Host::getStateText($downtime->host_state);
         }
     }
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function getRender()
 {
     if ($this->render === null) {
         $filter = $this->getFilter();
         $this->render = $filter ? Filter::fromQueryString($filter)->matches($this->getObject()) : true;
     }
     return $this->render;
 }
 public function fetchResourcesByType($type, Filter $filter = null)
 {
     if (substr($type, 0, 2) === '@@') {
         $exported = true;
         $type = substr($type, 2);
     } else {
         $exported = false;
     }
     if ($filter === null) {
         $filter = Filter::fromQueryString('type=' . $type);
     } else {
         $filter = $filter->andFilter(Filter::fromQueryString('type=' . $type));
     }
     return $this->fetchResources($filter, $exported);
 }
Пример #17
0
 /**
  * Add the given filter to the current filter of the URL
  *
  * @param   Filter $and
  *
  * @return  $this
  */
 public function addFilter($and)
 {
     $this->setQueryString(Filter::fromQueryString($this->getQueryString())->andFilter($and)->toQueryString());
     return $this;
 }
Пример #18
0
 /**
  * Create a Filter object for a given URL-like filter string. We allow
  * for spaces as we do not search for custom string values here. This is
  * internal voodoo.
  *
  * @param string $string Filter string
  *
  * @return Filter
  */
 protected function filterStringToFilter($string)
 {
     return Filter::fromQueryString(str_replace(' ', '', $string));
 }
 /**
  * @param Filter $filter
  * @return $this
  * @throws IcingaException
  */
 public function setFilter($filter)
 {
     if (is_string($filter)) {
         $this->filter = Filter::fromQueryString($filter);
         return $this;
     } else {
         throw new IcingaException('EventType filter can not be empty!');
     }
 }
Пример #20
0
 public function testLeadingAndTrailingWhitespaces()
 {
     $columnWithWhitespaces = Filter::where(' host ', 'localhost');
     $this->assertTrue($columnWithWhitespaces->matches((object) array('host' => 'localhost')), 'Filter doesn\'t remove leading and trailing whitespaces from columns');
     $expressionWithLeadingWhitespaces = Filter::where('host', ' localhost');
     $this->assertTrue($expressionWithLeadingWhitespaces->matches((object) array('host' => ' localhost')), 'Filter doesn\'t take leading whitespaces of expressions into account');
     $this->assertFalse($expressionWithLeadingWhitespaces->matches((object) array('host' => ' localhost ')), 'Filter doesn\'t take trailing whitespaces of expressions into account');
     $expressionWithTrailingWhitespaces = Filter::where('host', 'localhost ');
     $this->assertTrue($expressionWithTrailingWhitespaces->matches((object) array('host' => 'localhost ')), 'Filter doesn\'t take trailing whitespaces of expressions into account');
     $this->assertFalse($expressionWithTrailingWhitespaces->matches((object) array('host' => ' localhost ')), 'Filter doesn\'t take leading whitespaces of expressions into account');
     $expressionWithLeadingAndTrailingWhitespaces = Filter::where('host', ' localhost ');
     $this->assertTrue($expressionWithLeadingAndTrailingWhitespaces->matches((object) array('host' => ' localhost ')), 'Filter doesn\'t take leading and trailing whitespaces of expressions into account');
     $this->assertFalse($expressionWithLeadingAndTrailingWhitespaces->matches((object) array('host' => ' localhost  ')), 'Filter doesn\'t take leading and trailing whitespaces of expressions into account');
     $queryStringWithWhitespaces = Filter::fromQueryString(' host = localhost ');
     $this->assertTrue($queryStringWithWhitespaces->matches((object) array('host' => ' localhost ')), 'Filter doesn\'t take leading and trailing whitespaces of expressions in query strings into account');
 }