public function showAction() { $this->setAutorefreshInterval(15); $checkNowForm = new CheckNowCommandForm(); $checkNowForm->setObjects($this->serviceList)->handleRequest(); $this->view->checkNowForm = $checkNowForm; $this->serviceList->setColumns(array('host_display_name', 'host_handled', 'host_name', 'host_problem', 'host_state', 'service_acknowledged', 'service_active_checks_enabled', 'service_description', 'service_display_name', 'service_handled', 'service_in_downtime', 'service_is_flapping', 'service_last_state_change', 'service_notifications_enabled', 'service_passive_checks_enabled', 'service_problem', 'service_state')); $acknowledgedObjects = $this->serviceList->getAcknowledgedObjects(); if (!empty($acknowledgedObjects)) { $removeAckForm = new RemoveAcknowledgementCommandForm(); $removeAckForm->setObjects($acknowledgedObjects)->handleRequest(); $this->view->removeAckForm = $removeAckForm; } $this->setAutorefreshInterval(15); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime'); $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/services/process-check-result'); $this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/services/add-comment'); $this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/services/delete-comment'); $this->view->stats = $this->serviceList->getServiceStateSummary(); $this->view->objects = $this->serviceList; $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects(); $this->view->problemObjects = $this->serviceList->getProblemObjects(); $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString()); $this->view->acknowledgedObjects = $acknowledgedObjects; $this->view->acknowledgeLink = Url::fromPath('monitoring/services/acknowledge-problem')->setQueryString($this->serviceList->getUnacknowledgedObjects()->objectsFilter()->toQueryString()); $this->view->unacknowledgedObjects = $this->serviceList->getUnacknowledgedObjects(); $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime(); $this->view->inDowntimeLink = Url::fromPath('monitoring/list/services')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter(array('host' => 'host_name', 'service' => 'service_description'))->toQueryString()); $this->view->showDowntimesLink = Url::fromPath('monitoring/downtimes/show')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter()->andFilter(Filter::where('object_type', 'service'))->toQueryString()); $this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments'); $this->view->sendCustomNotificationLink = Url::fromRequest()->setPath('monitoring/services/send-custom-notification'); }
/** * Returns a Filter that matches all hosts in this list * * @return Filter */ public function objectsFilter($columns = array('host' => 'host')) { $filterExpression = array(); foreach ($this as $host) { $filterExpression[] = Filter::where($columns['host'], $host->getName()); } return FilterOr::matchAny($filterExpression); }
public function argumentsAction() { $this->getTabs()->activate('arguments'); $this->view->title = $this->translate('Command arguments'); $this->view->table = $this->loadTable('icingaCommandArgument')->setCommandObject($this->object)->setFilter(Filter::where('command', $this->params->get('name'))); $form = $this->view->form = $this->loadForm('icingaCommandArgument')->setCommandObject($this->object); if ($id = $this->params->shift('argument_id')) { $form->loadObject($id); } $form->handleRequest(); }
/** * Create and add elements to this form * * @param array $formData The data sent by the user */ public function createElements(array $formData) { // TODO(jom): Fetching already existing members to prevent the user from mistakenly creating duplicate // memberships (no matter whether the data source permits it or not, a member does never need to be // added more than once) should be kept at backend level (GroupController::fetchUsers) but this does // not work currently as our ldap protocol stuff is unable to handle our filter implementation.. $members = $this->backend->select()->from('group_membership', array('user_name'))->where('group_name', $this->groupName)->fetchColumn(); $filter = empty($members) ? Filter::matchAll() : Filter::not(Filter::where('user_name', $members)); $users = $this->ds->select()->from('user', array('user_name'))->applyFilter($filter)->fetchColumn(); if (!empty($users)) { $this->addElement('multiselect', 'user_name', array('multiOptions' => array_combine($users, $users), 'label' => $this->translate('Backend Users'), 'description' => $this->translate('Select one or more users (fetched from your user backends) to add as group member'), 'class' => 'grant-permissions')); } $this->addElement('textarea', 'users', array('required' => empty($users), 'label' => $this->translate('Users'), 'description' => $this->translate('Provide one or more usernames separated by comma to add as group member'))); $this->setTitle(sprintf($this->translate('Add members for group %s'), $this->groupName)); $this->setSubmitLabel($this->translate('Add')); }
public function showAction() { $this->setAutorefreshInterval(15); if ($this->Auth()->hasPermission('monitoring/command/schedule-check')) { $checkNowForm = new CheckNowCommandForm(); $checkNowForm->setObjects($this->serviceList)->handleRequest(); $this->view->checkNowForm = $checkNowForm; } $acknowledgedObjects = $this->serviceList->getAcknowledgedObjects(); if (!empty($acknowledgedObjects)) { $removeAckForm = new RemoveAcknowledgementCommandForm(); $removeAckForm->setObjects($acknowledgedObjects)->handleRequest(); $this->view->removeAckForm = $removeAckForm; } $featureStatus = $this->serviceList->getFeatureStatus(); $toggleFeaturesForm = new ToggleObjectFeaturesCommandForm(array('backend' => $this->backend, 'objects' => $this->serviceList)); $toggleFeaturesForm->load((object) $featureStatus)->handleRequest(); $this->view->toggleFeaturesForm = $toggleFeaturesForm; $this->setAutorefreshInterval(15); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime'); $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/services/process-check-result'); $this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/services/add-comment'); $this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/services/delete-comment'); $this->view->stats = $this->serviceList->getServiceStateSummary(); $this->view->objects = $this->serviceList; $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects(); $this->view->problemObjects = $this->serviceList->getProblemObjects(); $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString()); $this->view->acknowledgedObjects = $acknowledgedObjects; $this->view->acknowledgeLink = Url::fromPath('monitoring/services/acknowledge-problem')->setQueryString($this->serviceList->getUnacknowledgedObjects()->objectsFilter()->toQueryString()); $this->view->unacknowledgedObjects = $this->serviceList->getUnacknowledgedObjects(); $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime(); $this->view->inDowntimeLink = Url::fromPath('monitoring/list/services')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter(array('host' => 'host_name', 'service' => 'service_description'))->toQueryString()); $this->view->showDowntimesLink = Url::fromPath('monitoring/downtimes/show')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter()->andFilter(Filter::where('object_type', 'service'))->toQueryString()); $this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments'); $this->view->sendCustomNotificationLink = Url::fromRequest()->setPath('monitoring/services/send-custom-notification'); }
public function addpropertyAction() { $this->view->stayHere = true; $edit = false; if ($id = $this->params->get('id')) { $edit = true; } $form = $this->view->form = $this->loadForm('syncProperty')->setDb($this->db()); if ($edit) { $form->loadObject($id); $rule_id = $form->getObject()->rule_id; $form->setRule(SyncRule::load($rule_id, $this->db())); } elseif ($rule_id = $this->params->get('rule_id')) { $form->setRule(SyncRule::load($rule_id, $this->db())); } $form->setSuccessUrl('director/syncrule/property', array('rule_id' => $rule_id)); $form->handleRequest(); $tabs = $this->getTabs()->add('edit', array('url' => 'director/syncrule/edit', 'urlParams' => array('id' => $rule_id), 'label' => $this->translate('Edit sync rule'))); if ($edit) { $tabs->add('property', array('label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $rule_id))); } else { $tabs->add('property', array('label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $rule_id))); } $tabs->activate('property'); $this->view->title = $this->translate('Sync property'); // add/edit $this->view->table = $this->loadTable('syncproperty')->enforceFilter(Filter::where('rule_id', $rule_id))->setConnection($this->db()); $this->render('list/table', null, true); }
/** * Delete table rows, optionally limited by using a filter * * @param string $table * @param Filter $filter */ public function delete($table, Filter $filter = null) { if ($table === 'group') { parent::delete('group_membership', $filter); $idQuery = $this->select(array('group_id')); if ($filter !== null) { $idQuery->applyFilter($filter); } $this->update('group', array('parent' => null), Filter::where('parent', $idQuery->fetchColumn())); } parent::delete($table, $filter); }
/** * Filter this query using the given column and value * * This notifies the repository about the required filter column. * * @param string $column * @param mixed $value * * @return $this */ public function where($column, $value = null) { $this->addFilter(Filter::where($column, $value)); return $this; }
/** * Returns a Filter that matches all hosts in this HostList * * @param array $columns Override filter column names * * @return Filter */ public function objectsFilter($columns = array('host' => 'host', 'service' => 'service')) { $filterExpression = array(); foreach ($this as $service) { $filterExpression[] = Filter::matchAll(Filter::where($columns['host'], $service->getHost()->getName()), Filter::where($columns['service'], $service->getName())); } return FilterOr::matchAny($filterExpression); }
public function enforceFilter($filter, $expression = null) { if (!$filter instanceof Filter) { $filter = Filter::where($filter, $expression); } $this->enforcedFilters[] = $filter; return $this; }
public function servicegridAction() { $this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid')); $this->setAutorefreshInterval(15); $query = $this->backend->select()->from('servicestatus', array('host_display_name', 'host_name', 'service_description', 'service_display_name', 'service_handled', 'service_output', 'service_state')); $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); $filter = (bool) $this->params->shift('problems', false) ? Filter::where('service_problem', 1) : null; $pivot = $query->pivot('service_description', 'host_name', $filter, $filter ? clone $filter : null)->setXAxisHeader('service_display_name')->setYAxisHeader('host_display_name'); $this->setupSortControl(array('host_display_name' => $this->translate('Hostname'), 'service_display_name' => $this->translate('Service Name')), $pivot); $this->view->horizontalPaginator = $pivot->paginateXAxis(); $this->view->verticalPaginator = $pivot->paginateYAxis(); list($pivotData, $pivotHeader) = $pivot->toArray(); $this->view->pivotData = $pivotData; $this->view->pivotHeader = $pivotHeader; }
/** * Fetch all entries and forecasts by using the dataview associated with this timeline * * @return array The dataview's result */ private function fetchResults() { $hookResults = array(); foreach (Hook::all('timeline') as $timelineProvider) { $hookResults = array_merge($hookResults, $timelineProvider->fetchEntries($this->displayRange), $timelineProvider->fetchForecasts($this->forecastRange)); foreach ($timelineProvider->getIdentifiers() as $identifier => $attributes) { if (!array_key_exists($identifier, $this->identifiers)) { $this->identifiers[$identifier] = $attributes; } } } $query = $this->dataview; $filter = Filter::matchAll(Filter::where('type', array_keys($this->identifiers)), Filter::expression('timestamp', '<=', $this->displayRange->getStart()->getTimestamp()), Filter::expression('timestamp', '>', $this->displayRange->getEnd()->getTimestamp())); $query->applyFilter($filter); return array_merge($query->getQuery()->fetchAll(), $hookResults); }
/** * {@inheritdoc} */ public function onSuccess() { $backend = $this->getBackend(); $backend->update($backend->getBaseTable(), array('password' => $this->getElement('new_password')->getValue()), Filter::where('user_name', $this->Auth()->getUser()->getUsername())); Notification::success($this->translate('Account updated')); }
public function reallyRetrieveStatesFromBackend() { Benchmark::measure('Retrieving states for business process ' . $this->getName()); $backend = $this->getBackend(); // TODO: Split apart, create a dedicated function. // Separate "parse-logic" from "retrieve-state-logic" // Allow DB-based backend // Use IcingaWeb2 Multi-Backend-Support $check_results = array(); $hostFilter = array_keys($this->hosts); if ($this->state_type === self::HARD_STATE) { $hostStateColumn = 'host_hard_state'; $hostStateChangeColumn = 'host_last_hard_state_change'; $serviceStateColumn = 'service_hard_state'; $serviceStateChangeColumn = 'service_last_hard_state_change'; } else { $hostStateColumn = 'host_state'; $hostStateChangeColumn = 'host_last_state_change'; $serviceStateColumn = 'service_state'; $serviceStateChangeColumn = 'service_last_state_change'; } $filter = Filter::matchAny(); foreach ($hostFilter as $host) { $filter->addFilter(Filter::where('host_name', $host)); } if ($filter->isEmpty()) { return $this; } $hostStatus = $backend->select()->from('hostStatus', array('hostname' => 'host_name', 'last_state_change' => $hostStateChangeColumn, 'in_downtime' => 'host_in_downtime', 'ack' => 'host_acknowledged', 'state' => $hostStateColumn))->applyFilter($filter)->getQuery()->fetchAll(); $serviceStatus = $backend->select()->from('serviceStatus', array('hostname' => 'host_name', 'service' => 'service_description', 'last_state_change' => $serviceStateChangeColumn, 'in_downtime' => 'service_in_downtime', 'ack' => 'service_acknowledged', 'state' => $serviceStateColumn))->applyFilter($filter)->getQuery()->fetchAll(); foreach ($serviceStatus as $row) { $this->handleDbRow($row); } foreach ($hostStatus as $row) { $this->handleDbRow($row); } ksort($this->root_nodes); Benchmark::measure('Got states for business process ' . $this->getName()); return $this; }
public function where($condition, $value = null) { $this->filter->addFilter(Filter::where($condition, $value)); $this->query->where($condition, $value); return $this; }
public function servicegridAction() { $this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid')); $this->setAutorefreshInterval(15); $problems = (bool) $this->params->shift('problems', 0); $query = $this->backend->select()->from('servicestatus', array('host_name', 'service_description', 'service_state', 'service_output', 'service_handled')); $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); $this->setupSortControl(array('host_name' => $this->translate('Hostname'), 'service_description' => $this->translate('Service description')), $query); $pivot = $query->pivot('service_description', 'host_name', $problems ? Filter::where('service_problem', 1) : null, $problems ? Filter::where('service_problem', 1) : null); $this->view->pivot = $pivot; $this->view->horizontalPaginator = $pivot->paginateXAxis(); $this->view->verticalPaginator = $pivot->paginateYAxis(); }
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'); }
/** * Remove a group member */ public function removememberAction() { $this->assertPermission('config/authentication/groups/edit'); $this->assertHttpMethod('POST'); $groupName = $this->params->getRequired('group'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\\Data\\Reducible'); $form = new Form(array('onSuccess' => function ($form) use($groupName, $backend) { foreach ($form->getValue('user_name') as $userName) { try { $backend->delete('group_membership', Filter::matchAll(Filter::where('group_name', $groupName), Filter::where('user_name', $userName))); Notification::success(sprintf(t('User "%s" has been removed from group "%s"'), $userName, $groupName)); } catch (NotFoundError $e) { throw $e; } catch (Exception $e) { Notification::error($e->getMessage()); } } $redirect = $form->getValue('redirect'); if (!empty($redirect)) { $form->setRedirectUrl(htmlspecialchars_decode($redirect)); } return true; })); $form->setUidDisabled(); $form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called $form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true)); $form->addElement('hidden', 'redirect'); try { $form->handleRequest(); } catch (NotFoundError $_) { $this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName)); } }
public function where($condition, $value = null) { $this->getFilter()->addFilter(Filter::where($condition, $value)); }
/** * Create and return a filter to use when updating or deleting a group * * @return Filter */ protected function createFilter() { return Filter::where('group_name', $this->getIdentifier()); }
/** * Applies the name filter of EventType restrictions onto a Query * * @param RepositoryQuery $query */ public function filterEventTypes(RepositoryQuery $query) { $allowedTypes = $this->canEventTypes(); if (!empty($allowedTypes)) { $filter = Filter::matchAny(); foreach ($allowedTypes as $type) { $here = Filter::where('name', $type); $filter->addFilter($here); } $query->addFilter($filter); } }