protected function evaluate() { $phpVersion = Platform::getPhpVersion(); $this->setStateText(sprintf(mt('setup', 'You are running PHP version %s.'), $phpVersion)); list($operator, $requiredVersion) = $this->getCondition(); return version_compare($phpVersion, $requiredVersion, $operator); }
/** * {@inheritdoc} */ public function getCount() { if ($this->count === null) { try { $count = 0; $programStatus = $this->isCurrentlyRunning(); $titles = array(); if (!(bool) $programStatus->notifications_enabled) { $count = 1; $this->state = static::STATE_WARNING; $titles[] = mt('monitoring', 'Notifications are disabled'); } if (!(bool) $programStatus->is_currently_running) { $count = 1; $this->state = static::STATE_CRITICAL; array_unshift($titles, sprintf(mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName())); } $this->count = $count; $this->title = implode('. ', $titles); } catch (Exception $_) { $this->count = 1; } } return $this->count; }
/** * Get the problem data for the summary * * @return array|null */ public function getSummary() { if (!$this->isCurrentlyRunning()) { return array('problems' => 1, 'title' => sprintf(mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName())); } return null; }
protected function evaluate() { list($configDirective, $value) = $this->getCondition(); $configValue = Platform::getPhpConfig($configDirective); $this->setStateText($configValue ? sprintf(mt('setup', 'The PHP config `%s\' is set to "%s".'), $configDirective, $configValue) : sprintf(mt('setup', 'The PHP config `%s\' is not defined.'), $configDirective)); return is_bool($value) ? $configValue == $value : $configValue === $value; }
/** * {@inheritdoc} */ public function render() { if ($this->getInnerIterator()->isEmpty()) { return '<p>' . mt('doc', 'Documentation is empty.') . '</p>'; } $view = $this->getView(); $zendUrlHelper = $view->getHelper('Url'); foreach ($this as $section) { $path = $zendUrlHelper->url(array_merge($this->urlParams, array('chapter' => $this->encodeUrlParam($section->getChapter()->getId()))), $this->url, false, false); $url = $view->url($path); /** @var \Icinga\Web\Url $url */ if ($this->getDepth() > 0) { $url->setAnchor($this->encodeAnchor($section->getId())); } $urlAttributes = array('data-base-target' => '_next', 'title' => $section->getId() === $section->getChapter()->getId() ? sprintf($view->translate('Show the chapter "%s"', 'toc.render.section.link'), $section->getChapter()->getTitle()) : sprintf($view->translate('Show the section "%s" of the chapter "%s"', 'toc.render.section.link'), $section->getTitle(), $section->getChapter()->getTitle())); if ($section->getNoFollow()) { $urlAttributes['rel'] = 'nofollow'; } $this->content[] = '<li>' . $this->getView()->qlink($section->getTitle(), $url->getAbsoluteUrl(), null, $urlAttributes); if (!$section->hasChildren()) { $this->content[] = '</li>'; } } return implode("\n", $this->content); }
/** * Get the problem data for the summary * * @return array|null */ public function getSummary() { if (!(bool) $this->isCurrentlyRunning()) { return array('problems' => 1, 'title' => mt('monitoring', 'monitoring backend is not running')); } return null; }
public function getReport() { if ($this->error === false) { return array(sprintf(mt('monitoring', 'Command transport configuration has been successfully created: %s'), Config::resolvePath('modules/monitoring/commandtransports.ini'))); } elseif ($this->error !== null) { return array(sprintf(mt('monitoring', 'Command transport configuration could not be written to: %s. An error occured:'), Config::resolvePath('modules/monitoring/commandtransports.ini')), sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error))); } }
/** * Create a new documentation parser for the given path * * @param string $path Path to the documentation * * @throws DocException If the documentation directory does not exist * @throws NotReadableError If the documentation directory is not readable */ public function __construct($path) { if (!DirectoryIterator::isReadable($path)) { throw new DocException(mt('doc', 'Documentation directory \'%s\' is not readable'), $path); } $this->path = $path; $this->docIterator = new DirectoryIterator($path, 'md', DirectoryIterator::FILES_FIRST); }
public function getReport() { if ($this->error === false) { return array(sprintf(mt('setup', 'General configuration has been successfully written to: %s'), Config::resolvePath('config.ini'))); } elseif ($this->error !== null) { return array(sprintf(mt('setup', 'General configuration could not be written to: %s. An error occured:'), Config::resolvePath('config.ini')), sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->error))); } }
public function getReport() { if ($this->error === false) { return array(sprintf(mt('monitoring', 'Monitoring instance configuration has been successfully created: %s'), Config::resolvePath('modules/monitoring/instances.ini'))); } elseif ($this->error !== null) { return array(sprintf(mt('monitoring', 'Monitoring instance configuration could not be written to: %s. An error occured:'), Config::resolvePath('modules/monitoring/instances.ini')), sprintf(mt('setup', 'ERROR: %s'), $this->error->getMessage())); } }
public function getReport() { if ($this->error === false) { $message = mt('setup', 'General configuration has been successfully written to: %s'); return '<p>' . sprintf($message, Config::resolvePath('config.ini')) . '</p>'; } elseif ($this->error !== null) { $message = mt('setup', 'General configuration could not be written to: %s; An error occured:'); return '<p class="error">' . sprintf($message, Config::resolvePath('config.ini')) . '</p>' . '<p>' . $this->error->getMessage() . '</p>'; } }
public function getReport() { if ($this->error === false) { $message = mt('monitoring', 'Monitoring instance configuration has been successfully created: %s'); return '<p>' . sprintf($message, Config::resolvePath('modules/monitoring/instances.ini')) . '</p>'; } elseif ($this->error !== null) { $message = mt('monitoring', 'Monitoring instance configuration could not be written to: %s; An error occured:'); return '<p class="error">' . sprintf($message, Config::resolvePath('modules/monitoring/instances.ini')) . '</p><p>' . $this->error->getMessage() . '</p>'; } }
public function getActionsForService(Service $service) { if ($service->check_command == "logstash_events") { // TODO: add icon when Icingaweb2 supports it // <i class="icon-doc-text"></i> return array(mt('logstash', 'Logstash events') => Url::fromPath('elasticsearch/event/list', array('host' => $service->getHost()->getName(), 'service' => $service->getName()))); } else { return array(); } }
protected function evaluate() { $moduleName = $this->getCondition(); if (Platform::extensionLoaded($moduleName)) { $this->setStateText(sprintf(mt('setup', 'The PHP module %s is available.'), $this->getAlias() ?: $moduleName)); return true; } else { $this->setStateText(sprintf(mt('setup', 'The PHP module %s is missing.'), $this->getAlias() ?: $moduleName)); return false; } }
protected function evaluate() { $classNameOrPath = $this->getCondition(); if (Platform::classExists($classNameOrPath)) { $this->setStateText(sprintf(mt('setup', 'The %s is available.', 'setup.requirement.class'), $this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class'))); return true; } else { $this->setStateText(sprintf(mt('setup', 'The %s is missing.', 'setup.requirement.class'), $this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class'))); return false; } }
protected function getBadgeTitle() { $translations = array('hosts_down_unhandled' => mt('monitoring', '%d unhandled hosts down'), 'services_critical_unhandled' => mt('monitoring', '%d unhandled services critical')); $titles = array(); $sum = $this->summary(); foreach ($this->columns as $col) { if (isset($sum->{$col}) && $sum->{$col} > 0) { $titles[] = sprintf($translations[$col], $sum->{$col}); } } return implode(', ', $titles); }
/** * {@inheritdoc} */ public function getStateText() { $stateText = parent::getStateText(); if ($stateText === null) { $alias = $this->getAlias(); if ($this->getState()) { $stateText = $alias === null ? sprintf(mt('setup', 'The %s class is available.', 'setup.requirement.class'), $this->getCondition()) : sprintf(mt('setup', 'The %s is available.', 'setup.requirement.class'), $alias); } else { $stateText = $alias === null ? sprintf(mt('setup', 'The %s class is missing.', 'setup.requirement.class'), $this->getCondition()) : sprintf(mt('setup', 'The %s is missing.', 'setup.requirement.class'), $alias); } } return $stateText; }
/** * Create a new section renderer * * @param SimpleTree $tree The documentation tree * @param string|null $chapter If not null, the chapter to filter for * * @throws ChapterNotFoundException If the chapter to filter for was not found */ public function __construct(SimpleTree $tree, $chapter = null) { if ($chapter !== null) { $filter = new DocSectionFilterIterator($tree->getIterator(), $chapter); if ($filter->isEmpty()) { throw new ChapterNotFoundException(mt('doc', 'Chapter %s not found'), $chapter); } parent::__construct($filter, RecursiveIteratorIterator::SELF_FIRST); } else { parent::__construct($tree->getIterator(), RecursiveIteratorIterator::SELF_FIRST); } $this->tree = $tree; $this->parsedown = Parsedown::instance(); }
public function getReport() { $okMessage = mt('setup', 'Module "%s" has been successfully enabled.'); $failMessage = mt('setup', 'Module "%s" could not be enabled. An error occured:'); $report = ''; foreach ($this->moduleNames as $moduleName) { if (isset($this->errors[$moduleName])) { $report .= '<p class="error">' . sprintf($failMessage, $moduleName) . '</p>' . '<p>' . $this->errors[$moduleName]->getMessage() . '</p>'; } else { $report .= '<p>' . sprintf($okMessage, $moduleName) . '</p>'; } } return $report; }
/** * Get the transport used to send commands * * @param Request $request * * @return CommandTransportInterface * * @throws ConfigurationError */ public function getTransport(Request $request) { if (($transportName = $request->getParam('transport')) !== null) { $config = CommandTransport::getConfig(); if ($config->hasSection($transportName)) { $transport = CommandTransport::createTransport($config->getSection($transportName)); } else { throw new ConfigurationError(sprintf(mt('monitoring', 'Command transport "%s" not found.'), $transportName)); } } else { $transport = new CommandTransport(); } return $transport; }
public function getReport() { $okMessage = mt('setup', 'Module "%s" has been successfully enabled.'); $failMessage = mt('setup', 'Module "%s" could not be enabled. An error occured:'); $report = array(); foreach ($this->moduleNames as $moduleName) { if (isset($this->errors[$moduleName])) { $report[] = sprintf($failMessage, $moduleName); $report[] = sprintf(mt('setup', 'ERROR: %s'), $this->errors[$moduleName]->getMessage()); } else { $report[] = sprintf($okMessage, $moduleName); } } return $report; }
/** * Create a new documentation parser for the given path * * @param string $path Path to the documentation * * @throws DocException If the documentation directory does not exist * @throws NotReadableError If the documentation directory is not readable * @throws DocEmptyException If the documentation directory is empty */ public function __construct($path) { if (!is_dir($path)) { throw new DocException(sprintf(mt('doc', 'Documentation directory \'%s\' does not exist'), $path)); } if (!is_readable($path)) { throw new DocException(sprintf(mt('doc', 'Documentation directory \'%s\' is not readable'), $path)); } $docIterator = new DocIterator($path); if ($docIterator->count() === 0) { throw new DocEmptyException(sprintf(mt('doc', 'Documentation directory \'%s\' does not contain any non-empty Markdown file (\'.md\' suffix)'), $path)); } $this->path = $path; $this->docIterator = $docIterator; }
public function getReport() { $okMessage = mt('setup', 'Directory "%s" in "%s" has been successfully created.'); $failMessage = mt('setup', 'Unable to create directory "%s" in "%s". An error occured:'); $report = ''; foreach ($this->paths as $path) { if (array_key_exists($path, $this->errors)) { if (is_array($this->errors[$path])) { $report .= '<p class="error">' . sprintf($failMessage, basename($path), dirname($path)) . '</p>' . '<p>' . $this->errors[$path]['message'] . '</p>'; } else { $report .= '<p>' . sprintf($okMessage, basename($path), dirname($path)) . '</p>'; } } } return $report; }
public function getReport() { $okMessage = mt('setup', 'Directory "%s" in "%s" has been successfully created.'); $failMessage = mt('setup', 'Unable to create directory "%s" in "%s". An error occured:'); $report = array(); foreach ($this->paths as $path) { if (array_key_exists($path, $this->errors)) { if (is_array($this->errors[$path])) { $report[] = sprintf($failMessage, basename($path), dirname($path)); $report[] = sprintf(mt('setup', 'ERROR: %s'), $this->errors[$path]['message']); } else { $report[] = sprintf($okMessage, basename($path), dirname($path)); } } } return $report; }
protected function evaluate() { $path = $this->getCondition(); if (file_exists($path)) { $readable = is_readable($path); if ($readable && is_writable($path)) { $this->setStateText(sprintf(mt('setup', 'The directory %s is read- and writable.'), $path)); return true; } else { $this->setStateText(sprintf($readable ? mt('setup', 'The directory %s is not writable.') : mt('setup', 'The directory %s is not readable.'), $path)); return false; } } else { $this->setStateText(sprintf(mt('setup', 'The directory %s does not exist.'), $path)); return false; } }
public function getReport() { $report = array(); if ($this->backendIniError === false) { $report[] = sprintf(mt('monitoring', 'Monitoring backend configuration has been successfully written to: %s'), Config::resolvePath('modules/monitoring/backends.ini')); } elseif ($this->backendIniError !== null) { $report[] = sprintf(mt('monitoring', 'Monitoring backend configuration could not be written to: %s. An error occured:'), Config::resolvePath('modules/monitoring/backends.ini')); $report[] = sprintf(mt('setup', 'ERROR: %s'), $this->backendIniError->getMessage()); } if ($this->resourcesIniError === false) { $report[] = sprintf(mt('monitoring', 'Resource configuration has been successfully updated: %s'), Config::resolvePath('resources.ini')); } elseif ($this->resourcesIniError !== null) { $report[] = sprintf(mt('monitoring', 'Resource configuration could not be udpated: %s. An error occured:'), Config::resolvePath('resources.ini')); $report[] = sprintf(mt('setup', 'ERROR: %s'), $this->resourcesIniError->getMessage()); } return $report; }
public function getReport() { $report = ''; if ($this->backendIniError === false) { $message = mt('monitoring', 'Monitoring backend configuration has been successfully written to: %s'); $report .= '<p>' . sprintf($message, Config::resolvePath('modules/monitoring/backends.ini')) . '</p>'; } elseif ($this->backendIniError !== null) { $message = mt('monitoring', 'Monitoring backend configuration could not be written to: %s; An error occured:'); $report .= '<p class="error">' . sprintf($message, Config::resolvePath('modules/monitoring/backends.ini')) . '</p><p>' . $this->backendIniError->getMessage() . '</p>'; } if ($this->resourcesIniError === false) { $message = mt('monitoring', 'Resource configuration has been successfully updated: %s'); $report .= '<p>' . sprintf($message, Config::resolvePath('resources.ini')) . '</p>'; } elseif ($this->resourcesIniError !== null) { $message = mt('monitoring', 'Resource configuration could not be udpated: %s; An error occured:'); $report .= '<p class="error">' . sprintf($message, Config::resolvePath('resources.ini')) . '</p>' . '<p>' . $this->resourcesIniError->getMessage() . '</p>'; } return $report; }
public function renderStateBadges($summary) { $html = ''; foreach ($summary as $state => $cnt) { if ($cnt === 0) { continue; } if ($state === 'OK') { continue; } if ($state === 'UP') { continue; } $html .= '<span class="badge badge-' . strtolower($state) . '" title="' . mt('monitoring', $state) . '">' . $cnt . '</span>'; } if ($html !== '') { $html = '<div class="badges">' . $html . '</div>'; } return $html; }
public static function enumProperties(DbConnection $connection = null) { $properties = static::create()->listProperties(); $props = mt('director', 'Properties'); $vars = mt('director', 'Custom variables'); $properties = array($props => array_combine($properties, $properties), $vars => array()); if ($connection !== null) { foreach ($connection->fetchDistinctHostVars() as $var) { if ($var->datatype) { $properties[$vars]['vars.' . $var->varname] = sprintf('%s (%s)', $var->varname, $var->caption); } else { $properties[$vars]['vars.' . $var->varname] = $var->varname; } } } //$properties['vars.*'] = 'Other custom variable'; ksort($properties[$vars]); ksort($properties[$props]); return $properties; }
public function xb($url, $method, array $par) { $ck = $this->ck; $at = $this->at; $api = array("consumer_key" => $ck, "access_token" => $at); $main = array_merge($api, $par); if ("POST" == strtoupper($method)) { if (array_key_exists('image', $par)) { $file = $main["image"]; $mt = mt($file); $c = curl_init($url); $cfile = curl_file_create("{$file}", "{$mt}", "Xlib"); $data = array('image' => $cfile); $d = array_merge($main, $data); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, $d); curl_exec($c); } return c_as($url, $method, $main); } elseif ("GET" == strtoupper($method)) { return c_as($url, $method, $main); } }