Merge pull request #4758 from Icinga/remove-depricated-classes-and-methods
Remove deprecated classes and methods
This commit is contained in:
commit
3203cd8fea
|
@ -12,12 +12,12 @@ class Zend_View_Helper_CreateTicketLinks extends Zend_View_Helper_Abstract
|
||||||
* @param string $text
|
* @param string $text
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @see \Icinga\Web\Hook\TicketHook::createLinks()
|
* @see \Icinga\Application\Hook\TicketHook::createLinks()
|
||||||
*/
|
*/
|
||||||
public function createTicketLinks($text)
|
public function createTicketLinks($text)
|
||||||
{
|
{
|
||||||
$tickets = $this->view->tickets;
|
$tickets = $this->view->tickets;
|
||||||
/** @var \Icinga\Web\Hook\TicketHook $tickets */
|
/** @var \Icinga\Application\Hook\TicketHook $tickets */
|
||||||
return isset($tickets) ? $tickets->createLinks($text) : $text;
|
return isset($tickets) ? $tickets->createLinks($text) : $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,9 +159,6 @@ this, put the macro `$user.local_name$` in the restriction where you want it to
|
||||||
This can come in handy if you have e.g. an attribute on hosts or services defining which user is responsible for it:
|
This can come in handy if you have e.g. an attribute on hosts or services defining which user is responsible for it:
|
||||||
`_host_deputy=$user.local_name$|_service_deputy=$user.local_name$`
|
`_host_deputy=$user.local_name$|_service_deputy=$user.local_name$`
|
||||||
|
|
||||||
> Please note that since version 2.9 the use of `user.local_name` instead of `user:local_name` is supported and
|
|
||||||
> recommended. `user:local_name` is deprecated and will be removed in version 2.11.
|
|
||||||
|
|
||||||
### Filter Expressions
|
### Filter Expressions
|
||||||
|
|
||||||
Filters operate on columns. A complete list of all available filter columns on hosts and services can be found in
|
Filters operate on columns. A complete list of all available filter columns on hosts and services can be found in
|
||||||
|
|
|
@ -16,6 +16,50 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too.
|
||||||
In package installations this file can be found in `/usr/share/doc/icingaweb2/schema/*-upgrades/`
|
In package installations this file can be found in `/usr/share/doc/icingaweb2/schema/*-upgrades/`
|
||||||
(Debian/Ubuntu: `/usr/share/icingaweb2/etc/schema/*-upgrades/`).
|
(Debian/Ubuntu: `/usr/share/icingaweb2/etc/schema/*-upgrades/`).
|
||||||
|
|
||||||
|
**Breaking changes**
|
||||||
|
|
||||||
|
* The `user:local_name` macro in restrictions has been removed. Use `user.local_name` now.
|
||||||
|
|
||||||
|
**Framework changes affecting third-party code**
|
||||||
|
|
||||||
|
* All the following deprecated php classes and methods are removed:
|
||||||
|
|
||||||
|
**Methods:**
|
||||||
|
+ `Url::setBaseUrl()`: Please create a new url from scratch instead.
|
||||||
|
+ `Url::getBaseUrl()`: Use either `Url::getBasePath()` or `Url::getAbsoluteUrl()` now.
|
||||||
|
+ `ApplicationBootstrap::setupZendAutoloader()`: Since it does nothing. All uses removed.
|
||||||
|
+ `ApplicationBootstrap::listLocales()`: Use `\ipl\I18n\GettextTranslator::listLocales()` instead.
|
||||||
|
+ `Module::registerHook()`: Use `provideHook()` instead.
|
||||||
|
+ `Web::getMenu()`: Instantiate the menu class `new Menu()` directly instead.
|
||||||
|
+ `AesCrypt::encryptToBase64()`: Use `AesCrypt::encrypt()` instead as it also returns a base64 encoded string.
|
||||||
|
+ `AesCrypt::decryptFromBase64()`: Use `AesCrypt::decrypt()` instead as it also returns a base64 decoded string.
|
||||||
|
+ `InlinePie::disableNoScript()`: Empty method.
|
||||||
|
+ `SimpleQuery::paginate()`: Use `Icinga\Web\Controller::setupPaginationControl()` and/or `Icinga\Web\Widget\Paginator` instead.
|
||||||
|
+ `LdapConnection::connect()`: The connection is established lazily now.
|
||||||
|
+ `MonitoredObject::matches()`: Use `$filter->matches($object)` instead.
|
||||||
|
+ `MonitoredObject::fromParams()`: Deleted without substitution.
|
||||||
|
+ `DataView::fromRequest()`: Use `$backend->select()->from($viewName)` instead.
|
||||||
|
+ `DataView::sort()`: Use `DataView::order()` instead.
|
||||||
|
+ `MonitoringBackend::createBackend()`: Use `MonitoringBackend::instance()` instead.
|
||||||
|
+ `DbConnection::getConnection()`: Use `Connection::getDbAdapter()` instead.
|
||||||
|
+ `DbQuery::renderFilter()`: Use `DbConnection::renderFilter()` instead.
|
||||||
|
+ `DbQuery::whereToSql()`: Use `DbConnection::renderFilter()` instead.
|
||||||
|
+ `DataView::applyUrlFilter()`: Not in use.
|
||||||
|
|
||||||
|
**Classes:**
|
||||||
|
+ `Icinga\Util\String`: Use `Icinga\Util\StringHelper` instead.
|
||||||
|
+ `Icinga\Util\Translator`: Use `\ipl\I18n\StaticTranslator::$instance` or `\ipl\I18n\Translation` instead.
|
||||||
|
+ `Icinga\Module\Migrate\Clicommands\DashboardCommand`: Deleted without substitution.
|
||||||
|
+ `Icinga\Web\Hook\TicketHook`: Use `Icinga\Application\Hook\TicketHook` instead.
|
||||||
|
+ `Icinga\Web\Hook\GrapherHook`: Use `Icinga\Application\Hook\GrapherHook` instead.
|
||||||
|
+ `Icinga\Module\Monitoring\Environment`: Not in use.
|
||||||
|
+ `Icinga\Module\Monitoring\Backend`: Use `Icinga\Module\Monitoring\Backend\MonitoringBackend` instead.
|
||||||
|
|
||||||
|
* All the following deprecated js classes and methods are removed:
|
||||||
|
|
||||||
|
**Methods:**
|
||||||
|
+ `loader::addUrlFlag()`: Use `Icinga.Utils.addUrlFlag()` instead.
|
||||||
|
|
||||||
## Upgrading to Icinga Web 2 2.10.x
|
## Upgrading to Icinga Web 2 2.10.x
|
||||||
|
|
||||||
**General**
|
**General**
|
||||||
|
|
|
@ -434,17 +434,6 @@ abstract class ApplicationBootstrap
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the Zend Autoloader - compat only - does nothing
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setupZendAutoloader()
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup module manager
|
* Setup module manager
|
||||||
*
|
*
|
||||||
|
@ -766,19 +755,4 @@ abstract class ApplicationBootstrap
|
||||||
$localedir = $this->getLocaleDir();
|
$localedir = $this->getLocaleDir();
|
||||||
return $localedir !== false && file_exists($localedir) && is_dir($localedir);
|
return $localedir !== false && file_exists($localedir) && is_dir($localedir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* List all available locales
|
|
||||||
*
|
|
||||||
* @return array Locale list
|
|
||||||
*
|
|
||||||
* @deprecated Use {@see \ipl\I18n\GettextTranslator::listLocales()} instead
|
|
||||||
*/
|
|
||||||
public function listLocales()
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
return $translator->listLocales();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,6 @@ class EmbeddedWeb extends ApplicationBootstrap
|
||||||
protected function bootstrap()
|
protected function bootstrap()
|
||||||
{
|
{
|
||||||
return $this
|
return $this
|
||||||
->setupZendAutoloader()
|
|
||||||
->setupErrorHandling()
|
->setupErrorHandling()
|
||||||
->loadLibraries()
|
->loadLibraries()
|
||||||
->loadConfig()
|
->loadConfig()
|
||||||
|
|
|
@ -1388,22 +1388,6 @@ class Module
|
||||||
return $this->includeScript($this->configScript);
|
return $this->includeScript($this->configScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a hook
|
|
||||||
*
|
|
||||||
* @param string $name Name of the hook
|
|
||||||
* @param string $class Class of the hook w/ namespace
|
|
||||||
* @param string $key
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*
|
|
||||||
* @deprecated Deprecated since 2.1.1. Use {@link provideHook()} instead
|
|
||||||
*/
|
|
||||||
protected function registerHook($name, $class, $key = null)
|
|
||||||
{
|
|
||||||
return $this->provideHook($name, $class, $key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function slashesToNamespace($class)
|
protected function slashesToNamespace($class)
|
||||||
{
|
{
|
||||||
$list = explode('/', $class);
|
$list = explode('/', $class);
|
||||||
|
|
|
@ -20,7 +20,6 @@ use Icinga\User;
|
||||||
use Icinga\Util\DirectoryIterator;
|
use Icinga\Util\DirectoryIterator;
|
||||||
use Icinga\Util\TimezoneDetect;
|
use Icinga\Util\TimezoneDetect;
|
||||||
use Icinga\Web\Controller\Dispatcher;
|
use Icinga\Web\Controller\Dispatcher;
|
||||||
use Icinga\Web\Menu;
|
|
||||||
use Icinga\Web\Navigation\Navigation;
|
use Icinga\Web\Navigation\Navigation;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Web\Session;
|
use Icinga\Web\Session;
|
||||||
|
@ -82,7 +81,6 @@ class Web extends EmbeddedWeb
|
||||||
protected function bootstrap()
|
protected function bootstrap()
|
||||||
{
|
{
|
||||||
return $this
|
return $this
|
||||||
->setupZendAutoloader()
|
|
||||||
->setupLogging()
|
->setupLogging()
|
||||||
->setupErrorHandling()
|
->setupErrorHandling()
|
||||||
->loadLibraries()
|
->loadLibraries()
|
||||||
|
@ -284,18 +282,6 @@ class Web extends EmbeddedWeb
|
||||||
return $navigation;
|
return $navigation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the app's menu
|
|
||||||
*
|
|
||||||
* @deprecated Instantiate the returned class directly instead of using this method.
|
|
||||||
*
|
|
||||||
* @return Menu
|
|
||||||
*/
|
|
||||||
public function getMenu()
|
|
||||||
{
|
|
||||||
return new Menu();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch public interface
|
* Dispatch public interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -204,11 +204,8 @@ class AdmissionLoader
|
||||||
|
|
||||||
$roleRestrictions = $role->getRestrictions();
|
$roleRestrictions = $role->getRestrictions();
|
||||||
foreach ($roleRestrictions as $name => & $restriction) {
|
foreach ($roleRestrictions as $name => & $restriction) {
|
||||||
// TODO(el): user.local_name is supported since version 2.9.
|
|
||||||
// and therefore user:local_name is deprecated.
|
|
||||||
// The latter will be removed in version 2.11.
|
|
||||||
$restriction = str_replace(
|
$restriction = str_replace(
|
||||||
['$user.local_name$', '$user:local_name$'],
|
'$user.local_name$',
|
||||||
$user->getLocalUsername(),
|
$user->getLocalUsername(),
|
||||||
$restriction
|
$restriction
|
||||||
);
|
);
|
||||||
|
|
|
@ -244,22 +244,6 @@ class AesCrypt
|
||||||
return $decrypt;
|
return $decrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode from Base64 and decrypt the given string
|
|
||||||
*
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return string The base64 decoded and decrypted string
|
|
||||||
*
|
|
||||||
* @deprecated Use decrypt() instead as it also returns a base64 decoded string
|
|
||||||
*
|
|
||||||
* @throws RuntimeException If decryption fails
|
|
||||||
*/
|
|
||||||
public function decryptFromBase64($data)
|
|
||||||
{
|
|
||||||
return $this->decrypt(base64_decode($data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt the given string
|
* Encrypt the given string
|
||||||
*
|
*
|
||||||
|
@ -284,22 +268,6 @@ class AesCrypt
|
||||||
return $encrypt;
|
return $encrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Encrypt the given string and encode to Base64
|
|
||||||
*
|
|
||||||
* @param string $data
|
|
||||||
*
|
|
||||||
* @return string encrypted and base64 encoded string
|
|
||||||
*
|
|
||||||
* @deprecated Use encrypt() instead as it also returns a base64 encoded string
|
|
||||||
*
|
|
||||||
* @throws RuntimeException If encryption fails
|
|
||||||
*/
|
|
||||||
public function encryptToBase64($data)
|
|
||||||
{
|
|
||||||
return base64_encode($this->encrypt($data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt the given string with non Authenticated encryption (AE) cipher method
|
* Decrypt the given string with non Authenticated encryption (AE) cipher method
|
||||||
*
|
*
|
||||||
|
|
|
@ -268,14 +268,6 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
||||||
return new static(ResourceFactory::getResourceConfig($name));
|
return new static(ResourceFactory::getResourceConfig($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use Connection::getDbAdapter() instead
|
|
||||||
*/
|
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->dbAdapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for the table prefix
|
* Getter for the table prefix
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,13 +7,10 @@ use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Zend_Db_Expr;
|
use Zend_Db_Expr;
|
||||||
use Zend_Db_Select;
|
use Zend_Db_Select;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Data\Filter\FilterAnd;
|
|
||||||
use Icinga\Data\Filter\FilterChain;
|
|
||||||
use Icinga\Data\Filter\FilterNot;
|
|
||||||
use Icinga\Data\Filter\FilterOr;
|
|
||||||
use Icinga\Data\SimpleQuery;
|
use Icinga\Data\SimpleQuery;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Exception\QueryException;
|
use Icinga\Exception\QueryException;
|
||||||
|
@ -116,6 +113,23 @@ class DbQuery extends SimpleQuery
|
||||||
return parent::where($condition, $value);
|
return parent::where($condition, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addFilter(Filter $filter)
|
||||||
|
{
|
||||||
|
$this->expressionsToTimestamp($filter);
|
||||||
|
return parent::addFilter($filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function expressionsToTimestamp(Filter $filter)
|
||||||
|
{
|
||||||
|
if ($filter->isChain()) {
|
||||||
|
foreach ($filter->filters() as $child) {
|
||||||
|
$this->expressionsToTimestamp($child);
|
||||||
|
}
|
||||||
|
} elseif ($this->isTimestamp($filter->getColumn())) {
|
||||||
|
$filter->setExpression($this->valueToTimestamp($filter->getExpression()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function dbSelect()
|
protected function dbSelect()
|
||||||
{
|
{
|
||||||
return clone $this->select;
|
return clone $this->select;
|
||||||
|
@ -179,55 +193,12 @@ class DbQuery extends SimpleQuery
|
||||||
|
|
||||||
protected function applyFilterSql($select)
|
protected function applyFilterSql($select)
|
||||||
{
|
{
|
||||||
$where = $this->renderFilter($this->filter);
|
$where = $this->getDatasource()->renderFilter($this->filter);
|
||||||
if ($where !== '') {
|
if ($where !== '') {
|
||||||
$select->where($where);
|
$select->where($where);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use DbConnection::renderFilter() instead!
|
|
||||||
*/
|
|
||||||
protected function renderFilter($filter, $level = 0)
|
|
||||||
{
|
|
||||||
$str = '';
|
|
||||||
if ($filter instanceof FilterChain) {
|
|
||||||
if ($filter instanceof FilterAnd) {
|
|
||||||
$op = ' AND ';
|
|
||||||
} elseif ($filter instanceof FilterOr) {
|
|
||||||
$op = ' OR ';
|
|
||||||
} elseif ($filter instanceof FilterNot) {
|
|
||||||
$op = ' AND ';
|
|
||||||
$str .= ' NOT ';
|
|
||||||
} else {
|
|
||||||
throw new QueryException(
|
|
||||||
'Cannot render filter: %s',
|
|
||||||
$filter
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$parts = array();
|
|
||||||
if (! $filter->isEmpty()) {
|
|
||||||
foreach ($filter->filters() as $f) {
|
|
||||||
$filterPart = $this->renderFilter($f, $level + 1);
|
|
||||||
if ($filterPart !== '') {
|
|
||||||
$parts[] = $filterPart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! empty($parts)) {
|
|
||||||
if ($level > 0) {
|
|
||||||
$str .= ' (' . implode($op, $parts) . ') ';
|
|
||||||
} else {
|
|
||||||
$str .= implode($op, $parts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$str .= $this->whereToSql($filter->getColumn(), $filter->getSign(), $filter->getExpression());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function escapeForSql($value)
|
protected function escapeForSql($value)
|
||||||
{
|
{
|
||||||
// bindParam? bindValue?
|
// bindParam? bindValue?
|
||||||
|
@ -253,20 +224,16 @@ class DbQuery extends SimpleQuery
|
||||||
|
|
||||||
protected function valueToTimestamp($value)
|
protected function valueToTimestamp($value)
|
||||||
{
|
{
|
||||||
// We consider integers as valid timestamps. Does not work for URL params
|
if (ctype_digit($value)) {
|
||||||
if (! is_string($value) || ctype_digit($value)) {
|
$value = (int) $value;
|
||||||
return $value;
|
} elseif (is_string($value)) {
|
||||||
|
$value = strtotime($value);
|
||||||
}
|
}
|
||||||
$value = strtotime($value);
|
|
||||||
if (! $value) {
|
if (is_int($value)) {
|
||||||
/*
|
$value = $this->timestampForSql($value);
|
||||||
NOTE: It's too late to throw exceptions, we might finish in __toString
|
|
||||||
throw new QueryException(sprintf(
|
|
||||||
'"%s" is not a valid time expression',
|
|
||||||
$value
|
|
||||||
));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +268,7 @@ class DbQuery extends SimpleQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->escapeForSql($dateTime->format('Y-m-d H:i:s'));
|
return $dateTime->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,63 +289,6 @@ class DbQuery extends SimpleQuery
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
|
||||||
if ($this->isTimestamp($col)) {
|
|
||||||
$expression = $this->valueToTimestamp($expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($expression)) {
|
|
||||||
$comp = [];
|
|
||||||
$pattern = [];
|
|
||||||
foreach ($expression as $value) {
|
|
||||||
if (strpos($value, '*') === false) {
|
|
||||||
$comp[] = $value;
|
|
||||||
} else {
|
|
||||||
$pattern[] = $this->whereToSql($col, $sign, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$sql = $pattern;
|
|
||||||
if ($sign === '=') {
|
|
||||||
if (! empty($comp)) {
|
|
||||||
$sql[] = $col . ' IN (' . $this->escapeForSql($comp) . ')';
|
|
||||||
}
|
|
||||||
$operator = 'OR';
|
|
||||||
} elseif ($sign === '!=') {
|
|
||||||
if (! empty($comp)) {
|
|
||||||
$sql[] = sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $col, $this->escapeForSql($comp));
|
|
||||||
}
|
|
||||||
$operator = 'AND';
|
|
||||||
} else {
|
|
||||||
throw new QueryException(
|
|
||||||
'Unable to render array expressions with operators other than equal or not equal'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '(' . implode(" $operator ", $sql) . ')';
|
|
||||||
} elseif ($sign === '=' && $expression !== null && strpos($expression, '*') !== false) {
|
|
||||||
if ($expression === '*') {
|
|
||||||
return $col . ' IS NOT NULL';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $col . ' LIKE ' . $this->escapeForSql($this->escapeWildcards($expression));
|
|
||||||
} elseif ($sign === '!=' && $expression !== null && strpos($expression, '*') !== false) {
|
|
||||||
if ($expression === '*') {
|
|
||||||
return $col . ' IS NULL';
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf(
|
|
||||||
'(%1$s NOT LIKE %2$s OR %1$s IS NULL)',
|
|
||||||
$col,
|
|
||||||
$this->escapeForSql($this->escapeWildcards($expression))
|
|
||||||
);
|
|
||||||
} elseif ($sign === '!=') {
|
|
||||||
return sprintf('(%1$s %2$s %3$s OR %1$s IS NULL)', $col, $sign, $this->escapeForSql($expression));
|
|
||||||
} else {
|
|
||||||
return sprintf('%s %s %s', $col, $sign, $this->escapeForSql($expression));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the count query
|
* Get the count query
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,13 +5,10 @@ namespace Icinga\Data;
|
||||||
|
|
||||||
use Iterator;
|
use Iterator;
|
||||||
use IteratorAggregate;
|
use IteratorAggregate;
|
||||||
use Zend_Paginator;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Application\Benchmark;
|
use Icinga\Application\Benchmark;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Exception\IcingaException;
|
use Icinga\Exception\IcingaException;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
|
||||||
|
|
||||||
class SimpleQuery implements QueryInterface, Queryable, Iterator
|
class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||||
{
|
{
|
||||||
|
@ -517,43 +514,6 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||||
return $this->limitOffset;
|
return $this->limitOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Paginate data
|
|
||||||
*
|
|
||||||
* Auto-detects pagination parameters from request when unset
|
|
||||||
*
|
|
||||||
* @param int $itemsPerPage Number of items per page
|
|
||||||
* @param int $pageNumber Current page number
|
|
||||||
*
|
|
||||||
* @return Zend_Paginator
|
|
||||||
*
|
|
||||||
* @deprecated Use Icinga\Web\Controller::setupPaginationControl() and/or Icinga\Web\Widget\Paginator instead
|
|
||||||
*/
|
|
||||||
public function paginate($itemsPerPage = null, $pageNumber = null)
|
|
||||||
{
|
|
||||||
trigger_error(
|
|
||||||
'SimpleQuery::paginate() is deprecated. Use Icinga\Web\Controller::setupPaginationControl()'
|
|
||||||
. ' and/or Icinga\Web\Widget\Paginator instead',
|
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($itemsPerPage === null || $pageNumber === null) {
|
|
||||||
// Detect parameters from request
|
|
||||||
$request = Icinga::app()->getRequest();
|
|
||||||
if ($itemsPerPage === null) {
|
|
||||||
$itemsPerPage = $request->getParam('limit', 25);
|
|
||||||
}
|
|
||||||
if ($pageNumber === null) {
|
|
||||||
$pageNumber = $request->getParam('page', 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->limit($itemsPerPage, $pageNumber * $itemsPerPage);
|
|
||||||
$paginator = new Zend_Paginator(new QueryAdapter($this));
|
|
||||||
$paginator->setItemCountPerPage($itemsPerPage);
|
|
||||||
$paginator->setCurrentPageNumber($pageNumber);
|
|
||||||
return $paginator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an array containing all rows of the result set
|
* Retrieve an array containing all rows of the result set
|
||||||
*
|
*
|
||||||
|
|
|
@ -321,18 +321,6 @@ class LdapConnection implements Selectable, Inspectable
|
||||||
return $this->encrypted;
|
return $this->encrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Establish a connection
|
|
||||||
*
|
|
||||||
* @throws LdapException In case the connection could not be established
|
|
||||||
*
|
|
||||||
* @deprecated The connection is established lazily now
|
|
||||||
*/
|
|
||||||
public function connect()
|
|
||||||
{
|
|
||||||
$this->getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a LDAP bind on the current connection
|
* Perform a LDAP bind on the current connection
|
||||||
*
|
*
|
||||||
|
|
|
@ -305,7 +305,7 @@ namespace Icinga\Test {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource->getConnection()->exec($sqlData);
|
$resource->getDbAdapter()->exec($sqlData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,7 +324,7 @@ namespace Icinga\Test {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter = $resource->getConnection();
|
$adapter = $resource->getDbAdapter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$adapter->getConnection();
|
$adapter->getConnection();
|
||||||
|
|
|
@ -1,159 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common string functions
|
|
||||||
*
|
|
||||||
* @deprecated(el): For backwards compatibility only. Use StringHelper instead.
|
|
||||||
*/
|
|
||||||
class String
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Split string into an array and trim spaces
|
|
||||||
*
|
|
||||||
* @param string $value
|
|
||||||
* @param string $delimiter
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function trimSplit($value, $delimiter = ',')
|
|
||||||
{
|
|
||||||
return array_map('trim', explode($delimiter, $value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uppercase the first character of each word in a string
|
|
||||||
*
|
|
||||||
* Converts 'first_name' to 'FirstName' for example.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param string $separator Word separator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function cname($name, $separator = '_')
|
|
||||||
{
|
|
||||||
return str_replace(' ', '', ucwords(str_replace($separator, ' ', strtolower($name))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add ellipsis when a string is longer than max length
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @param int $maxLength
|
|
||||||
* @param string $ellipsis
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function ellipsis($string, $maxLength, $ellipsis = '...')
|
|
||||||
{
|
|
||||||
if (strlen($string) > $maxLength) {
|
|
||||||
return substr($string, 0, $maxLength - strlen($ellipsis)) . $ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add ellipsis in the center of a string when a string is longer than max length
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @param int $maxLength
|
|
||||||
* @param string $ellipsis
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function ellipsisCenter($string, $maxLength, $ellipsis = '...')
|
|
||||||
{
|
|
||||||
$start = ceil($maxLength / 2.0);
|
|
||||||
$end = floor($maxLength / 2.0);
|
|
||||||
if (strlen($string) > $maxLength) {
|
|
||||||
return substr($string, 0, $start - strlen($ellipsis)) . $ellipsis . substr($string, - $end);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find and return all similar strings in $possibilites matching $string with the given minimum $similarity
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @param array $possibilities
|
|
||||||
* @param float $similarity
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function findSimilar($string, array $possibilities, $similarity = 0.33)
|
|
||||||
{
|
|
||||||
if (empty($string)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$matches = array();
|
|
||||||
foreach ($possibilities as $possibility) {
|
|
||||||
$distance = levenshtein($string, $possibility);
|
|
||||||
if ($distance / strlen($string) <= $similarity) {
|
|
||||||
$matches[] = $possibility;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test whether the given string ends with the given suffix
|
|
||||||
*
|
|
||||||
* @param string $string The string to test
|
|
||||||
* @param string $suffix The suffix the string must end with
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function endsWith($string, $suffix)
|
|
||||||
{
|
|
||||||
$stringSuffix = substr($string, -strlen($suffix));
|
|
||||||
return $stringSuffix !== false ? $stringSuffix === $suffix : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates an array of strings that constitutes the cartesian product of all passed sets, with all
|
|
||||||
* string combinations concatenated using the passed join-operator.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* cartesianProduct(
|
|
||||||
* array(array('foo', 'bar'), array('mumble', 'grumble', null)),
|
|
||||||
* '_'
|
|
||||||
* );
|
|
||||||
* => array('foo_mumble', 'foo_grumble', 'bar_mumble', 'bar_grumble', 'foo', 'bar')
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param array $sets An array of arrays containing all sets for which the cartesian
|
|
||||||
* product should be calculated.
|
|
||||||
* @param string $glue The glue used to join the strings, defaults to ''.
|
|
||||||
*
|
|
||||||
* @returns array The cartesian product in one array of strings.
|
|
||||||
*/
|
|
||||||
public static function cartesianProduct(array $sets, $glue = '')
|
|
||||||
{
|
|
||||||
$product = null;
|
|
||||||
foreach ($sets as $set) {
|
|
||||||
if (! isset($product)) {
|
|
||||||
$product = $set;
|
|
||||||
} else {
|
|
||||||
$newProduct = array();
|
|
||||||
foreach ($product as $strA) {
|
|
||||||
foreach ($set as $strB) {
|
|
||||||
if ($strB === null) {
|
|
||||||
$newProduct []= $strA;
|
|
||||||
} else {
|
|
||||||
$newProduct []= $strA . $glue . $strB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$product = $newProduct;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $product;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,184 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Util;
|
|
||||||
|
|
||||||
use ipl\I18n\GettextTranslator;
|
|
||||||
use ipl\I18n\Locale;
|
|
||||||
use ipl\I18n\StaticTranslator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class to ease internationalization when using gettext
|
|
||||||
*
|
|
||||||
* @deprecated Use {@see \ipl\I18n\StaticTranslator::$instance} or {@see \ipl\I18n\Translation} instead
|
|
||||||
*/
|
|
||||||
class Translator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The default gettext domain used as fallback
|
|
||||||
*/
|
|
||||||
const DEFAULT_DOMAIN = 'icinga';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The locale code that is used in the project
|
|
||||||
*/
|
|
||||||
const DEFAULT_LOCALE = 'en_US';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Translate a string
|
|
||||||
*
|
|
||||||
* Falls back to the default domain in case the string cannot be translated using the given domain
|
|
||||||
*
|
|
||||||
* @param string $text The string to translate
|
|
||||||
* @param string $domain The primary domain to use
|
|
||||||
* @param string|null $context Optional parameter for context based translation
|
|
||||||
*
|
|
||||||
* @return string The translated string
|
|
||||||
*/
|
|
||||||
public static function translate($text, $domain, $context = null)
|
|
||||||
{
|
|
||||||
return StaticTranslator::$instance->translateInDomain($domain, $text, $context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Translate a plural string
|
|
||||||
*
|
|
||||||
* Falls back to the default domain in case the string cannot be translated using the given domain
|
|
||||||
*
|
|
||||||
* @param string $textSingular The string in singular form to translate
|
|
||||||
* @param string $textPlural The string in plural form to translate
|
|
||||||
* @param integer $number The amount to determine from whether to return singular or plural
|
|
||||||
* @param string $domain The primary domain to use
|
|
||||||
* @param string|null $context Optional parameter for context based translation
|
|
||||||
*
|
|
||||||
* @return string The translated string
|
|
||||||
*/
|
|
||||||
public static function translatePlural($textSingular, $textPlural, $number, $domain, $context = null)
|
|
||||||
{
|
|
||||||
return StaticTranslator::$instance->translatePluralInDomain(
|
|
||||||
$domain,
|
|
||||||
$textSingular,
|
|
||||||
$textPlural,
|
|
||||||
$number,
|
|
||||||
$context
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emulated pgettext()
|
|
||||||
*
|
|
||||||
* @link http://php.net/manual/de/book.gettext.php#89975
|
|
||||||
*
|
|
||||||
* @param $text
|
|
||||||
* @param $domain
|
|
||||||
* @param $context
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function pgettext($text, $domain, $context)
|
|
||||||
{
|
|
||||||
return StaticTranslator::$instance->translateInDomain($domain, $text, $context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emulated pngettext()
|
|
||||||
*
|
|
||||||
* @link http://php.net/manual/de/book.gettext.php#89975
|
|
||||||
*
|
|
||||||
* @param $textSingular
|
|
||||||
* @param $textPlural
|
|
||||||
* @param $number
|
|
||||||
* @param $domain
|
|
||||||
* @param $context
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function pngettext($textSingular, $textPlural, $number, $domain, $context)
|
|
||||||
{
|
|
||||||
return StaticTranslator::$instance->translatePluralInDomain(
|
|
||||||
$domain,
|
|
||||||
$textSingular,
|
|
||||||
$textPlural,
|
|
||||||
$number,
|
|
||||||
$context
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new gettext domain
|
|
||||||
*
|
|
||||||
* @param string $name The name of the domain to register
|
|
||||||
* @param string $directory The directory where message catalogs can be found
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function registerDomain($name, $directory)
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
$translator->addTranslationDirectory($directory, $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the locale to use
|
|
||||||
*
|
|
||||||
* @param string $localeName The name of the locale to use
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function setupLocale($localeName)
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
$translator->setLocale($localeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Split and return the language code and country code of the given locale or the current locale
|
|
||||||
*
|
|
||||||
* @param string $locale The locale code to split, or null to split the current locale
|
|
||||||
*
|
|
||||||
* @return object An object with a 'language' and 'country' attribute
|
|
||||||
*/
|
|
||||||
public static function splitLocaleCode($locale = null)
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
if ($locale === null) {
|
|
||||||
$locale = $translator->getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (new Locale())->parseLocale($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a list of all locale codes currently available in the known domains
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getAvailableLocaleCodes()
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
return $translator->listLocales();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the preferred locale based on the given HTTP header and the available translations
|
|
||||||
*
|
|
||||||
* @param string $header The HTTP "Accept-Language" header
|
|
||||||
*
|
|
||||||
* @return string The browser's preferred locale code
|
|
||||||
*/
|
|
||||||
public static function getPreferredLocaleCode($header)
|
|
||||||
{
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
return (new Locale())->getPreferred($header, $translator->listLocales());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,8 @@ use Icinga\Application\Hook as NewHookImplementation;
|
||||||
/**
|
/**
|
||||||
* Icinga Web Hook registry
|
* Icinga Web Hook registry
|
||||||
*
|
*
|
||||||
* Deprecated, please use Icinga\Application\Hook instead
|
* @deprecated It is highly recommended to use {@see Icinga\Application\Hook} instead. Though since this message
|
||||||
|
* (or rather the previous message) hasn't been visible for ages... This won't be removed anyway....
|
||||||
*/
|
*/
|
||||||
class Hook extends NewHookImplementation
|
class Hook extends NewHookImplementation
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Web\Hook;
|
|
||||||
|
|
||||||
use Icinga\Application\Hook\GrapherHook as BaseHook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated, compat only.
|
|
||||||
*
|
|
||||||
* Please implement hooks in Icinga\Application\Hook
|
|
||||||
*/
|
|
||||||
abstract class GrapherHook extends BaseHook
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Web\Hook;
|
|
||||||
|
|
||||||
use Icinga\Application\Hook\TicketHook as BaseHook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated, compat only.
|
|
||||||
*
|
|
||||||
* Please implement hooks in Icinga\Application\Hook
|
|
||||||
*/
|
|
||||||
abstract class TicketHook extends BaseHook
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -367,75 +367,6 @@ class Url
|
||||||
return $this->scheme;
|
return $this->scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the baseUrl for this url
|
|
||||||
*
|
|
||||||
* @deprecated Please create a new url from scratch instead
|
|
||||||
*
|
|
||||||
* @param string $baseUrl The url path to use as the url base
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setBaseUrl($baseUrl)
|
|
||||||
{
|
|
||||||
$urlParts = parse_url($baseUrl);
|
|
||||||
if (isset($urlParts["host"])) {
|
|
||||||
$this->setHost($urlParts["host"]);
|
|
||||||
}
|
|
||||||
if (isset($urlParts["port"])) {
|
|
||||||
$this->setPort($urlParts["port"]);
|
|
||||||
}
|
|
||||||
if (isset($urlParts['scheme'])) {
|
|
||||||
$this->setScheme($urlParts['scheme']);
|
|
||||||
}
|
|
||||||
if (isset($urlParts['user'])) {
|
|
||||||
$this->setUsername($urlParts['user']);
|
|
||||||
}
|
|
||||||
if (isset($urlParts['pass'])) {
|
|
||||||
$this->setPassword($urlParts['pass']);
|
|
||||||
}
|
|
||||||
if (isset($urlParts['path'])) {
|
|
||||||
$this->setBasePath($urlParts['path']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the baseUrl for this url
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getBaseUrl()
|
|
||||||
{
|
|
||||||
if (! $this->isExternal()) {
|
|
||||||
return $this->getBasePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
$urlString = '';
|
|
||||||
if ($this->getScheme()) {
|
|
||||||
$urlString .= $this->getScheme() . '://';
|
|
||||||
}
|
|
||||||
if ($this->getPassword()) {
|
|
||||||
$urlString .= $this->getUsername() . ':' . $this->getPassword() . '@';
|
|
||||||
} elseif ($this->getUsername()) {
|
|
||||||
$urlString .= $this->getUsername() . '@';
|
|
||||||
}
|
|
||||||
if ($this->getHost()) {
|
|
||||||
$urlString .= $this->getHost();
|
|
||||||
}
|
|
||||||
if ($this->getPort()) {
|
|
||||||
$urlString .= ':' . $this->getPort();
|
|
||||||
}
|
|
||||||
if ($this->getBasePath()) {
|
|
||||||
$urlString .= $this->getBasePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $urlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the relative path of this url, without query parameters
|
* Set the relative path of this url, without query parameters
|
||||||
*
|
*
|
||||||
|
|
|
@ -134,15 +134,6 @@ class InlinePie extends AbstractWidget
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not display the NoScript fallback html
|
|
||||||
*
|
|
||||||
* @deprecated noop
|
|
||||||
*/
|
|
||||||
public function disableNoScript()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the class to define the
|
* Set the class to define the
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,127 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Module\Migrate\Clicommands;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Application\Modules\DashboardContainer;
|
|
||||||
use Icinga\Cli\Command;
|
|
||||||
use Icinga\Application\Logger;
|
|
||||||
use ipl\I18n\GettextTranslator;
|
|
||||||
use ipl\I18n\StaticTranslator;
|
|
||||||
use ReflectionClass;
|
|
||||||
|
|
||||||
class DashboardCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Rename translated dashboard sections
|
|
||||||
*
|
|
||||||
* Migrates all locally found dashboard configurations so that the effects of
|
|
||||||
* https://github.com/Icinga/icingaweb2/issues/3542 are reversed.
|
|
||||||
*
|
|
||||||
* USAGE
|
|
||||||
*
|
|
||||||
* icingacli migrate dashboard sections
|
|
||||||
*/
|
|
||||||
public function sectionsAction()
|
|
||||||
{
|
|
||||||
$moduleReflection = new ReflectionClass('Icinga\Application\Modules\Module');
|
|
||||||
// There's no direct way to invoke this method
|
|
||||||
$launchConfigScriptMethod = $moduleReflection->getMethod('launchConfigScript');
|
|
||||||
$launchConfigScriptMethod->setAccessible(true);
|
|
||||||
// Calling getDashboard() results in Url::fromPath() getting called as well == the CLI's death
|
|
||||||
$paneItemsProperty = $moduleReflection->getProperty('paneItems');
|
|
||||||
$paneItemsProperty->setAccessible(true);
|
|
||||||
|
|
||||||
/** @var GettextTranslator $translator */
|
|
||||||
$translator = StaticTranslator::$instance;
|
|
||||||
|
|
||||||
$locales = $translator->listLocales();
|
|
||||||
$modules = Icinga::app()->getModuleManager()->getLoadedModules();
|
|
||||||
foreach ($this->listDashboardConfigs() as $path) {
|
|
||||||
Logger::info('Migrating dashboard config: %s', $path);
|
|
||||||
|
|
||||||
$config = Config::fromIni($path);
|
|
||||||
foreach ($modules as $module) {
|
|
||||||
if (! $module->hasLocales()) {
|
|
||||||
// Modules without any translations are not affected
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$launchConfigScriptMethod->invoke($module);
|
|
||||||
|
|
||||||
foreach ($locales as $locale) {
|
|
||||||
if ($locale === 'en_US') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$translator->setLocale($locale);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Logger::debug('Ignoring locale "%s". Reason: %s', $locale, $e->getMessage());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($paneItemsProperty->getValue($module) as $paneName => $container) {
|
|
||||||
/** @var DashboardContainer $container */
|
|
||||||
foreach ($config->toArray() as $section => $options) {
|
|
||||||
if (strpos($section, '.') !== false) {
|
|
||||||
list($paneTitle, $dashletTitle) = explode('.', $section, 2);
|
|
||||||
} else {
|
|
||||||
$paneTitle = $section;
|
|
||||||
$dashletTitle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mt($module->getName(), $paneName) !== $paneTitle) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dashletName = null;
|
|
||||||
if ($dashletTitle !== null) {
|
|
||||||
foreach ($container->getDashlets() as $name => $url) {
|
|
||||||
if (mt($module->getName(), $name) === $dashletTitle) {
|
|
||||||
$dashletName = $name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dashletName === null) {
|
|
||||||
$dashletName = $dashletTitle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$newSection = $paneName . ($dashletName ? '.' . $dashletName : '');
|
|
||||||
$config->removeSection($section);
|
|
||||||
$config->setSection($newSection, $options);
|
|
||||||
|
|
||||||
Logger::info('Migrated section "%s" to "%s"', $section, $newSection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$config->saveIni();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function listDashboardConfigs()
|
|
||||||
{
|
|
||||||
$dashboardConfigPath = Config::resolvePath('dashboards');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$dashboardConfigDir = opendir($dashboardConfigPath);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Logger::error('Cannot access dashboard configuration: %s', $e);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($entry = readdir($dashboardConfigDir)) {
|
|
||||||
$userDashboardPath = join(DIRECTORY_SEPARATOR, [$dashboardConfigPath, $entry, 'dashboard.ini']);
|
|
||||||
if (is_file($userDashboardPath)) {
|
|
||||||
yield $userDashboardPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Clicommands;
|
namespace Icinga\Module\Monitoring\Clicommands;
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Module\Monitoring\Cli\CliUtils;
|
use Icinga\Module\Monitoring\Cli\CliUtils;
|
||||||
use Icinga\Date\DateFormatter;
|
use Icinga\Date\DateFormatter;
|
||||||
use Icinga\Cli\Command;
|
use Icinga\Cli\Command;
|
||||||
|
@ -25,8 +25,7 @@ class ListCommand extends Command
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->app->setupZendAutoloader();
|
$this->backend = MonitoringBackend::instance($this->params->shift('backend'));
|
||||||
$this->backend = Backend::createBackend($this->params->shift('backend'));
|
|
||||||
$this->dumpSql = $this->params->shift('showsql');
|
$this->dumpSql = $this->params->shift('showsql');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Module\Monitoring\Forms\Config\TransportReorderForm;
|
use Icinga\Module\Monitoring\Forms\Config\TransportReorderForm;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
|
||||||
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
|
use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Config\TransportConfigForm;
|
use Icinga\Module\Monitoring\Forms\Config\TransportConfigForm;
|
||||||
|
@ -215,7 +215,7 @@ class ConfigController extends Controller
|
||||||
$form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName));
|
$form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName));
|
||||||
$form->setIniConfig($this->Config('commandtransports'));
|
$form->setIniConfig($this->Config('commandtransports'));
|
||||||
$form->setInstanceNames(
|
$form->setInstanceNames(
|
||||||
Backend::createBackend()->select()->from('instance', array('instance_name'))->fetchColumn()
|
MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||||
);
|
);
|
||||||
$form->setOnSuccess(function (TransportConfigForm $form) use ($transportName) {
|
$form->setOnSuccess(function (TransportConfigForm $form) use ($transportName) {
|
||||||
try {
|
try {
|
||||||
|
@ -259,7 +259,7 @@ class ConfigController extends Controller
|
||||||
$form->setTitle($this->translate('Create New Command Transport'));
|
$form->setTitle($this->translate('Create New Command Transport'));
|
||||||
$form->setIniConfig($this->Config('commandtransports'));
|
$form->setIniConfig($this->Config('commandtransports'));
|
||||||
$form->setInstanceNames(
|
$form->setInstanceNames(
|
||||||
Backend::createBackend()->select()->from('instance', array('instance_name'))->fetchColumn()
|
MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||||
);
|
);
|
||||||
$form->setOnSuccess(function (TransportConfigForm $form) {
|
$form->setOnSuccess(function (TransportConfigForm $form) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Controllers;
|
namespace Icinga\Module\Monitoring\Controllers;
|
||||||
|
|
||||||
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Security\SecurityException;
|
use Icinga\Security\SecurityException;
|
||||||
use Icinga\Util\GlobFilter;
|
use Icinga\Util\GlobFilter;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Zend_Form;
|
use Zend_Form;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\DataView\DataView;
|
use Icinga\Module\Monitoring\DataView\DataView;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
||||||
|
@ -34,7 +34,7 @@ class ListController extends Controller
|
||||||
/**
|
/**
|
||||||
* Overwrite the backend to use (used for testing)
|
* Overwrite the backend to use (used for testing)
|
||||||
*
|
*
|
||||||
* @param Backend $backend The Backend that should be used for querying
|
* @param MonitoringBackend $backend The Backend that should be used for querying
|
||||||
*/
|
*/
|
||||||
public function setBackend($backend)
|
public function setBackend($backend)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
namespace Icinga\Module\Monitoring\Controllers;
|
namespace Icinga\Module\Monitoring\Controllers;
|
||||||
|
|
||||||
use Icinga\Data\Filter\FilterEqual;
|
use Icinga\Data\Filter\FilterEqual;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Security\SecurityException;
|
use Icinga\Security\SecurityException;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
@ -17,7 +17,7 @@ use Icinga\Web\Url;
|
||||||
class ShowController extends Controller
|
class ShowController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Backend
|
* @var MonitoringBackend
|
||||||
*/
|
*/
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
// TODO: obsolete, remove once MonitoringBackend is in use everywhere
|
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring;
|
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
|
||||||
|
|
||||||
class Backend extends MonitoringBackend
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -8,16 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
*/
|
*/
|
||||||
class HostcommentdeletionhistoryQuery extends HostcommenthistoryQuery
|
class HostcommentdeletionhistoryQuery extends HostcommenthistoryQuery
|
||||||
{
|
{
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hch.deletion_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'hch.deletion_time';
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ class HostcommenthistoryQuery extends IdoQuery
|
||||||
'object_type' => '(\'host\')',
|
'object_type' => '(\'host\')',
|
||||||
'output' => "('[' || hch.author_name || '] ' || hch.comment_data)",
|
'output' => "('[' || hch.author_name || '] ' || hch.comment_data)",
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)',
|
'timestamp' => 'hch.comment_time',
|
||||||
'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -68,16 +68,13 @@ class HostcommenthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hch.comment_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'hch.comment_time';
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,18 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
*/
|
*/
|
||||||
class HostdowntimeendhistoryQuery extends HostdowntimestarthistoryQuery
|
class HostdowntimeendhistoryQuery extends HostdowntimestarthistoryQuery
|
||||||
{
|
{
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_end_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
return $field === 'hdh.actual_end_time';
|
||||||
$this->valueToTimestamp($expression)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ class HostdowntimestarthistoryQuery extends IdoQuery
|
||||||
'object_type' => '(\'host\')',
|
'object_type' => '(\'host\')',
|
||||||
'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)",
|
'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)",
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)',
|
'timestamp' => 'hdh.actual_start_time',
|
||||||
'type' => "('dt_start')"
|
'type' => "('dt_start')"
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -68,18 +68,13 @@ class HostdowntimestarthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_start_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
return $field === 'hdh.actual_start_time';
|
||||||
$this->valueToTimestamp($expression)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ class HostflappingstarthistoryQuery extends IdoQuery
|
||||||
'object_type' => '(\'host\')',
|
'object_type' => '(\'host\')',
|
||||||
'output' => '(hfh.percent_state_change || \'\')',
|
'output' => '(hfh.percent_state_change || \'\')',
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(hfh.event_time)',
|
'timestamp' => 'hfh.event_time',
|
||||||
'type' => '(\'flapping\')'
|
'type' => '(\'flapping\')'
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -68,16 +68,13 @@ class HostflappingstarthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hfh.event_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hfh.event_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'hfh.event_time';
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\Data\Filter\FilterExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for host notifications
|
* Query for host notifications
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +40,7 @@ class HostnotificationQuery extends IdoQuery
|
||||||
'history' => array(
|
'history' => array(
|
||||||
'output' => null,
|
'output' => null,
|
||||||
'state' => 'hn.state',
|
'state' => 'hn.state',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
'timestamp' => 'hn.start_time',
|
||||||
'type' => '
|
'type' => '
|
||||||
CASE hn.notification_reason
|
CASE hn.notification_reason
|
||||||
WHEN 1 THEN \'notification_ack\'
|
WHEN 1 THEN \'notification_ack\'
|
||||||
|
@ -60,7 +63,7 @@ class HostnotificationQuery extends IdoQuery
|
||||||
'notification_output' => 'hn.output',
|
'notification_output' => 'hn.output',
|
||||||
'notification_reason' => 'hn.notification_reason',
|
'notification_reason' => 'hn.notification_reason',
|
||||||
'notification_state' => 'hn.state',
|
'notification_state' => 'hn.state',
|
||||||
'notification_timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
'notification_timestamp' => 'hn.start_time',
|
||||||
'object_type' => '(\'host\')'
|
'object_type' => '(\'host\')'
|
||||||
),
|
),
|
||||||
'servicegroups' => array(
|
'servicegroups' => array(
|
||||||
|
@ -76,18 +79,24 @@ class HostnotificationQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
protected function requireFilterColumns(Filter $filter)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hn.start_time)') {
|
if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') {
|
||||||
return 'hn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
$this->requireColumn($filter->getColumn());
|
||||||
} elseif ($col === $this->columnMap['history']['output']) {
|
$filter->setColumn('hn.output');
|
||||||
return parent::whereToSql('hn.output', $sign, $expression);
|
return null;
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return parent::requireFilterColumns($filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTimestamp($field)
|
||||||
|
{
|
||||||
|
if (! parent::isTimestamp($field)) {
|
||||||
|
return $field === 'hn.start_time';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -73,26 +73,18 @@ class HoststatehistoryQuery extends IdoQuery
|
||||||
'object_type' => '(\'host\')',
|
'object_type' => '(\'host\')',
|
||||||
'output' => '(CASE WHEN hh.state_type = 1 THEN hh.output ELSE \'[ \' || hh.current_check_attempt || \'/\' || hh.max_check_attempts || \' ] \' || hh.output END)',
|
'output' => '(CASE WHEN hh.state_type = 1 THEN hh.output ELSE \'[ \' || hh.current_check_attempt || \'/\' || hh.max_check_attempts || \' ] \' || hh.output END)',
|
||||||
'state' => 'hh.state',
|
'state' => 'hh.state',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(hh.state_time)',
|
'timestamp' => 'hh.state_time',
|
||||||
'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(hh.state_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'hh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'hh.state_time';
|
||||||
} elseif ($col === $this->columnMap['statehistory']['type']
|
|
||||||
&& ! is_array($expression)
|
|
||||||
&& array_key_exists($expression, $this->types)
|
|
||||||
) {
|
|
||||||
return 'hh.state_type ' . $sign . ' ' . $this->types[$expression];
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,16 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
*/
|
*/
|
||||||
class ServicecommentdeletionhistoryQuery extends ServicecommenthistoryQuery
|
class ServicecommentdeletionhistoryQuery extends ServicecommenthistoryQuery
|
||||||
{
|
{
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sch.deletion_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'sch.deletion_time';
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,7 @@ class ServicecommenthistoryQuery extends IdoQuery
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||||
'service_host_name' => 'so.name1',
|
'service_host_name' => 'so.name1',
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)',
|
'timestamp' => 'sch.comment_time',
|
||||||
'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -69,16 +69,13 @@ class ServicecommenthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sch.comment_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'sch.comment_time';
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,18 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
*/
|
*/
|
||||||
class ServicedowntimeendhistoryQuery extends ServicedowntimestarthistoryQuery
|
class ServicedowntimeendhistoryQuery extends ServicedowntimestarthistoryQuery
|
||||||
{
|
{
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_end_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
return $field === 'sdh.actual_end_time';
|
||||||
$this->valueToTimestamp($expression)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,7 @@ class ServicedowntimestarthistoryQuery extends IdoQuery
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||||
'service_host_name' => 'so.name1',
|
'service_host_name' => 'so.name1',
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)',
|
'timestamp' => 'sdh.actual_start_time',
|
||||||
'type' => "('dt_start')"
|
'type' => "('dt_start')"
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -69,18 +69,13 @@ class ServicedowntimestarthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_start_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
return $field === 'sdh.actual_start_time';
|
||||||
$this->valueToTimestamp($expression)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,7 @@ class ServiceflappingstarthistoryQuery extends IdoQuery
|
||||||
'service_description' => 'so.name2',
|
'service_description' => 'so.name2',
|
||||||
'service_host_name' => 'so.name1',
|
'service_host_name' => 'so.name1',
|
||||||
'state' => '(-1)',
|
'state' => '(-1)',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(sfh.event_time)',
|
'timestamp' => 'sfh.event_time',
|
||||||
'type' => "('flapping')"
|
'type' => "('flapping')"
|
||||||
),
|
),
|
||||||
'hostgroups' => array(
|
'hostgroups' => array(
|
||||||
|
@ -68,18 +68,13 @@ class ServiceflappingstarthistoryQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sfh.event_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sfh.event_time ' . $sign . ' ' . $this->timestampForSql(
|
return $field === 'sfh.event_time';
|
||||||
$this->valueToTimestamp($expression)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\Data\Filter\FilterExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for service notifications
|
* Query for service notifications
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +31,7 @@ class ServicenotificationQuery extends IdoQuery
|
||||||
'history' => array(
|
'history' => array(
|
||||||
'output' => null,
|
'output' => null,
|
||||||
'state' => 'sn.state',
|
'state' => 'sn.state',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
'timestamp' => 'sn.start_time',
|
||||||
'type' => '
|
'type' => '
|
||||||
CASE sn.notification_reason
|
CASE sn.notification_reason
|
||||||
WHEN 1 THEN \'notification_ack\'
|
WHEN 1 THEN \'notification_ack\'
|
||||||
|
@ -60,7 +63,7 @@ class ServicenotificationQuery extends IdoQuery
|
||||||
'notification_output' => 'sn.output',
|
'notification_output' => 'sn.output',
|
||||||
'notification_reason' => 'sn.notification_reason',
|
'notification_reason' => 'sn.notification_reason',
|
||||||
'notification_state' => 'sn.state',
|
'notification_state' => 'sn.state',
|
||||||
'notification_timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
'notification_timestamp' => 'sn.start_time',
|
||||||
'object_type' => '(\'service\')',
|
'object_type' => '(\'service\')',
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
'service_description' => 'so.name2',
|
'service_description' => 'so.name2',
|
||||||
|
@ -76,18 +79,24 @@ class ServicenotificationQuery extends IdoQuery
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
protected function requireFilterColumns(Filter $filter)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sn.start_time)') {
|
if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') {
|
||||||
return 'sn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
$this->requireColumn($filter->getColumn());
|
||||||
} elseif ($col === $this->columnMap['history']['output']) {
|
$filter->setColumn('sn.output');
|
||||||
return parent::whereToSql('sn.output', $sign, $expression);
|
return null;
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return parent::requireFilterColumns($filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTimestamp($field)
|
||||||
|
{
|
||||||
|
if (! parent::isTimestamp($field)) {
|
||||||
|
return $field === 'sn.start_time';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,26 +74,18 @@ class ServicestatehistoryQuery extends IdoQuery
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||||
'service_host_name' => 'so.name1',
|
'service_host_name' => 'so.name1',
|
||||||
'state' => 'sh.state',
|
'state' => 'sh.state',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)',
|
'timestamp' => 'sh.state_time',
|
||||||
'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
public function isTimestamp($field)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
|
||||||
{
|
{
|
||||||
if ($col === 'UNIX_TIMESTAMP(sh.state_time)') {
|
if (! parent::isTimestamp($field)) {
|
||||||
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
return $field === 'sh.state_time';
|
||||||
} elseif ($col === $this->columnMap['statehistory']['type']
|
|
||||||
&& ! is_array($expression)
|
|
||||||
&& array_key_exists($expression, $this->types)
|
|
||||||
) {
|
|
||||||
return 'sh.state_type ' . $sign . ' ' . $this->types[$expression];
|
|
||||||
} else {
|
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -197,23 +197,6 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a backend
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param string $backendName Name of the backend or null for creating the default backend which is the first INI
|
|
||||||
* configuration entry not being disabled
|
|
||||||
*
|
|
||||||
* @return Backend
|
|
||||||
* @throws ConfigurationError When no backend has been configured or all backends are disabled or the
|
|
||||||
* configuration for the requested backend does either not exist or it's disabled
|
|
||||||
*/
|
|
||||||
public static function createBackend($name = null)
|
|
||||||
{
|
|
||||||
return self::instance($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this backend's internal resource
|
* Get this backend's internal resource
|
||||||
*
|
*
|
||||||
|
|
|
@ -9,6 +9,7 @@ use Icinga\Exception\QueryException;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Data\Filterable;
|
use Icinga\Data\Filterable;
|
||||||
use Icinga\File\Csv;
|
use Icinga\File\Csv;
|
||||||
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Module\Monitoring\Data\CustomvarProtectionIterator;
|
use Icinga\Module\Monitoring\Data\CustomvarProtectionIterator;
|
||||||
use Icinga\Util\Json;
|
use Icinga\Util\Json;
|
||||||
use Icinga\Web\Controller as IcingaWebController;
|
use Icinga\Web\Controller as IcingaWebController;
|
||||||
|
@ -22,13 +23,13 @@ class Controller extends IcingaWebController
|
||||||
/**
|
/**
|
||||||
* The backend used for this controller
|
* The backend used for this controller
|
||||||
*
|
*
|
||||||
* @var Backend
|
* @var MonitoringBackend
|
||||||
*/
|
*/
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
protected function moduleInit()
|
protected function moduleInit()
|
||||||
{
|
{
|
||||||
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
$this->backend = MonitoringBackend::instance($this->_getParam('backend'));
|
||||||
$this->view->url = Url::fromRequest();
|
$this->view->url = Url::fromRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,23 +123,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
*/
|
*/
|
||||||
abstract public function getColumns();
|
abstract public function getColumns();
|
||||||
|
|
||||||
/**
|
|
||||||
* Create view from request
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @param array $columns
|
|
||||||
*
|
|
||||||
* @return static
|
|
||||||
* @deprecated Use $backend->select()->from($viewName) instead
|
|
||||||
*/
|
|
||||||
public static function fromRequest($request, array $columns = null)
|
|
||||||
{
|
|
||||||
$view = new static(MonitoringBackend::instance($request->getParam('backend')), $columns);
|
|
||||||
$view->applyUrlFilter($request);
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getHookedColumns()
|
protected function getHookedColumns()
|
||||||
{
|
{
|
||||||
$columns = array();
|
$columns = array();
|
||||||
|
@ -152,26 +135,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is not the right place for this, move it away
|
|
||||||
protected function applyUrlFilter($request = null)
|
|
||||||
{
|
|
||||||
$url = Url::fromRequest();
|
|
||||||
|
|
||||||
$limit = $url->shift('limit');
|
|
||||||
$sort = $url->shift('sort');
|
|
||||||
$dir = $url->shift('dir');
|
|
||||||
$page = $url->shift('page');
|
|
||||||
$format = $url->shift('format');
|
|
||||||
$view = $url->shift('showCompact');
|
|
||||||
$view = $url->shift('backend');
|
|
||||||
foreach ($url->getParams() as $k => $v) {
|
|
||||||
$this->where($k, $v);
|
|
||||||
}
|
|
||||||
if ($sort) {
|
|
||||||
$this->order($sort, $dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create view from params
|
* Create view from params
|
||||||
*
|
*
|
||||||
|
@ -200,7 +163,7 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->sort($params['sort'], $order);
|
$view->order($params['sort'], $order);
|
||||||
}
|
}
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
@ -324,18 +287,14 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the rows, according to the specified sort column and order
|
* Sort result set either by the given column (and direction) or the sort defaults
|
||||||
*
|
*
|
||||||
* @param string $column Sort column
|
* @param string $column
|
||||||
* @param string $order Sort order, one of the SORT_ constants
|
* @param string $direction
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws QueryException If the sort column is not allowed
|
|
||||||
* @see DataView::SORT_ASC
|
|
||||||
* @see DataView::SORT_DESC
|
|
||||||
* @deprecated Use DataView::order() instead
|
|
||||||
*/
|
*/
|
||||||
public function sort($column = null, $order = null)
|
public function order($column = null, $direction = null)
|
||||||
{
|
{
|
||||||
$sortRules = $this->getSortRules();
|
$sortRules = $this->getSortRules();
|
||||||
if ($column === null) {
|
if ($column === null) {
|
||||||
|
@ -356,16 +315,16 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
} else {
|
} else {
|
||||||
$sortColumns = array(
|
$sortColumns = array(
|
||||||
'columns' => array($column),
|
'columns' => array($column),
|
||||||
'order' => $order
|
'order' => $direction
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : static::SORT_ASC) : $order;
|
$direction = $direction === null ? ($sortColumns['order'] ?? static::SORT_ASC) : $direction;
|
||||||
$order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
$direction = (strtoupper($direction) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
||||||
|
|
||||||
foreach ($sortColumns['columns'] as $column) {
|
foreach ($sortColumns['columns'] as $column) {
|
||||||
list($column, $direction) = $this->query->splitOrder($column);
|
list($column, $order) = $this->query->splitOrder($column);
|
||||||
if (! $this->isValidFilterTarget($column)) {
|
if (! $this->isValidFilterTarget($column)) {
|
||||||
throw new QueryException(
|
throw new QueryException(
|
||||||
mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
|
mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
|
||||||
|
@ -373,7 +332,7 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
get_class($this)
|
get_class($this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->query->order($column, $direction !== null ? $direction : $order);
|
$this->query->order($column, $order !== null ? $order : $direction);
|
||||||
}
|
}
|
||||||
$this->isSorted = true;
|
$this->isSorted = true;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -389,19 +348,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort result set either by the given column (and direction) or the sort defaults
|
|
||||||
*
|
|
||||||
* @param string $column
|
|
||||||
* @param string $direction
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function order($column = null, $direction = null)
|
|
||||||
{
|
|
||||||
return $this->sort($column, $direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether an order is set
|
* Whether an order is set
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring;
|
|
||||||
|
|
||||||
class Environment
|
|
||||||
{
|
|
||||||
protected static $envs = array(
|
|
||||||
'default' => array(
|
|
||||||
'backend' => null,
|
|
||||||
'grapher' => null,
|
|
||||||
'configBackend' => null,
|
|
||||||
'commandPipe' => null,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
public static function defaultName()
|
|
||||||
{
|
|
||||||
// TODO: Check session
|
|
||||||
reset(self::$envs);
|
|
||||||
return key(self::$envs);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function config($env, $what)
|
|
||||||
{
|
|
||||||
return self::$config[self::getName($env)][$what];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function getName($env)
|
|
||||||
{
|
|
||||||
return $env === null ? self::defaultName() : $env;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function backend($env = null)
|
|
||||||
{
|
|
||||||
return Backend::getInstance(self::config($env, 'backend'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function grapher($env = null)
|
|
||||||
{
|
|
||||||
return Hook::createInstance('grapher', null, self::config($env, 'grapher'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function configBackend($env = null)
|
|
||||||
{
|
|
||||||
return Hook::createInstance(
|
|
||||||
'configBackend',
|
|
||||||
null,
|
|
||||||
self::config($env, 'configBackend')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function commandPipe($env = null)
|
|
||||||
{
|
|
||||||
return CommandPipe::getInstance(self::config($env, 'commandPipe'));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -234,30 +234,6 @@ abstract class MonitoredObject implements Filterable
|
||||||
// Left out on purpose. Interface is deprecated.
|
// Left out on purpose. Interface is deprecated.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return whether this object matches the given filter
|
|
||||||
*
|
|
||||||
* @param Filter $filter
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @throws ProgrammingError In case the object cannot be found
|
|
||||||
*
|
|
||||||
* @deprecated Use $filter->matches($object) instead
|
|
||||||
*/
|
|
||||||
public function matches(Filter $filter)
|
|
||||||
{
|
|
||||||
if ($this->properties === null && $this->fetch() === false) {
|
|
||||||
throw new ProgrammingError(
|
|
||||||
'Unable to apply filter. Object %s of type %s not found.',
|
|
||||||
$this->getName(),
|
|
||||||
$this->getType()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filter->matches($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Require the object's type to be one of the given types
|
* Require the object's type to be one of the given types
|
||||||
*
|
*
|
||||||
|
@ -951,17 +927,4 @@ abstract class MonitoredObject implements Filterable
|
||||||
|
|
||||||
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
|
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public static function fromParams(UrlParams $params)
|
|
||||||
{
|
|
||||||
if ($params->has('service') && $params->has('host')) {
|
|
||||||
return new Service(MonitoringBackend::instance(), $params->get('host'), $params->get('service'));
|
|
||||||
} elseif ($params->has('host')) {
|
|
||||||
return new Host(MonitoringBackend::instance(), $params->get('host'));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Icinga\Module\Monitoring\ProvidedHook;
|
||||||
|
|
||||||
use Icinga\Application\Hook\HealthHook;
|
use Icinga\Application\Hook\HealthHook;
|
||||||
use Icinga\Date\DateFormatter;
|
use Icinga\Date\DateFormatter;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use ipl\Web\Url;
|
use ipl\Web\Url;
|
||||||
|
|
||||||
class Health extends HealthHook
|
class Health extends HealthHook
|
||||||
|
@ -25,7 +25,7 @@ class Health extends HealthHook
|
||||||
|
|
||||||
public function checkHealth()
|
public function checkHealth()
|
||||||
{
|
{
|
||||||
$backendName = Backend::instance()->getName();
|
$backendName = MonitoringBackend::instance()->getName();
|
||||||
$programStatus = $this->getProgramStatus();
|
$programStatus = $this->getProgramStatus();
|
||||||
if ($programStatus === false) {
|
if ($programStatus === false) {
|
||||||
$this->setState(self::STATE_UNKNOWN);
|
$this->setState(self::STATE_UNKNOWN);
|
||||||
|
@ -55,7 +55,7 @@ class Health extends HealthHook
|
||||||
protected function getProgramStatus()
|
protected function getProgramStatus()
|
||||||
{
|
{
|
||||||
if ($this->programStatus === null) {
|
if ($this->programStatus === null) {
|
||||||
$this->programStatus = Backend::instance()->select()
|
$this->programStatus = MonitoringBackend::instance()->select()
|
||||||
->from('programstatus', [
|
->from('programstatus', [
|
||||||
'program_version',
|
'program_version',
|
||||||
'status_update_time',
|
'status_update_time',
|
||||||
|
|
|
@ -9,7 +9,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../../test/php/bootstrap.ph
|
||||||
|
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Bug7043Test extends BaseTestCase
|
||||||
)
|
)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$defaultBackend = Backend::createBackend();
|
$defaultBackend = MonitoringBackend::instance();
|
||||||
|
|
||||||
$this->assertEquals('backendName', $defaultBackend->getName(), 'Default backend has name set');
|
$this->assertEquals('backendName', $defaultBackend->getName(), 'Default backend has name set');
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,21 +443,6 @@
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Add the specified flag to the given URL
|
|
||||||
*
|
|
||||||
* @param {string} url
|
|
||||||
* @param {string} flag
|
|
||||||
*
|
|
||||||
* @returns {string}
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8.0. Use {@link Icinga.Utils.addUrlFlag()} instead
|
|
||||||
*/
|
|
||||||
addUrlFlag: function(url, flag)
|
|
||||||
{
|
|
||||||
return this.icinga.utils.addUrlFlag(url, flag);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the X-Icinga-Redirect HTTP Response Header
|
* Process the X-Icinga-Redirect HTTP Response Header
|
||||||
*
|
*
|
||||||
|
|
|
@ -25,7 +25,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherMySqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
public function testWhetherMySqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getConnection());
|
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getDbAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherCreatingTablesWithMySqlAdapterWorks($resource)
|
public function testWhetherCreatingTablesWithMySqlAdapterWorks($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$adapter = $resource->getConnection();
|
$adapter = $resource->getDbAdapter();
|
||||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||||
|
|
||||||
$tables = $adapter->listTables();
|
$tables = $adapter->listTables();
|
||||||
|
@ -58,7 +58,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
|
|
||||||
$tables = $resource->getConnection()->listTables();
|
$tables = $resource->getDbAdapter()->listTables();
|
||||||
$this->assertCount(0, $tables);
|
$this->assertCount(0, $tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherPgSqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
public function testWhetherPgSqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getConnection());
|
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getDbAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +86,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherCreatingTablesWithPgSqlAdapterWorks($resource)
|
public function testWhetherCreatingTablesWithPgSqlAdapterWorks($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$adapter = $resource->getConnection();
|
$adapter = $resource->getDbAdapter();
|
||||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||||
|
|
||||||
$tables = $adapter->listTables();
|
$tables = $adapter->listTables();
|
||||||
|
@ -101,7 +101,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
|
|
||||||
$tables = $resource->getConnection()->listTables();
|
$tables = $resource->getDbAdapter()->listTables();
|
||||||
$this->assertCount(0, $tables);
|
$this->assertCount(0, $tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherOciProviderAnnotationSetsUpZendDbAdapter($resource)
|
public function testWhetherOciProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Oci', $resource->getConnection());
|
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Oci', $resource->getDbAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,7 +129,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
public function testWhetherCreatingTablesWithOciAdapterWorks($resource)
|
public function testWhetherCreatingTablesWithOciAdapterWorks($resource)
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
$adapter = $resource->getConnection();
|
$adapter = $resource->getDbAdapter();
|
||||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||||
|
|
||||||
$tables = $adapter->listTables();
|
$tables = $adapter->listTables();
|
||||||
|
@ -144,7 +144,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
$this->setupDbProvider($resource);
|
$this->setupDbProvider($resource);
|
||||||
|
|
||||||
$tables = $resource->getConnection()->listTables();
|
$tables = $resource->getDbAdapter()->listTables();
|
||||||
$this->assertCount(0, $tables);
|
$this->assertCount(0, $tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ class BaseTestCaseTest extends BaseTestCase
|
||||||
|
|
||||||
$this->loadSql($resource, $tempFile);
|
$this->loadSql($resource, $tempFile);
|
||||||
|
|
||||||
$count = (int) $resource->getConnection()->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
$count = (int) $resource->getDbAdapter()->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
||||||
$this->assertSame(20, $count);
|
$this->assertSame(20, $count);
|
||||||
|
|
||||||
$this->assertTrue(unlink($tempFile));
|
$this->assertTrue(unlink($tempFile));
|
||||||
|
|
Loading…
Reference in New Issue