diff --git a/application/forms/Config/Resource/LdapResourceForm.php b/application/forms/Config/Resource/LdapResourceForm.php index fea16c4e5..6d9bf74d4 100644 --- a/application/forms/Config/Resource/LdapResourceForm.php +++ b/application/forms/Config/Resource/LdapResourceForm.php @@ -113,16 +113,17 @@ class LdapResourceForm extends Form 'text', 'bind_dn', array( - 'required' => true, 'label' => $this->translate('Bind DN'), - 'description' => $this->translate('The user dn to use for querying the ldap server') + 'description' => $this->translate( + 'The user dn to use for querying the ldap server. Leave the dn and password empty for attempting' + . ' an anonymous bind' + ) ) ); $this->addElement( 'password', 'bind_pw', array( - 'required' => true, 'renderPassword' => true, 'label' => $this->translate('Bind Password'), 'description' => $this->translate('The password to use for querying the ldap server') diff --git a/application/views/helpers/DateFormat.php b/application/views/helpers/DateFormat.php deleted file mode 100644 index 6df8c32bb..000000000 --- a/application/views/helpers/DateFormat.php +++ /dev/null @@ -1,133 +0,0 @@ -request = Icinga::app()->getFrontController()->getRequest(); - } else { - $this->request = $request; - } - } - - /** - * Helper entry point - * - * @return $this - */ - public function dateFormat() - { - return $this; - } - - /** - * Return date formatted according to given format respecting the user's timezone - * - * @param int $timestamp - * @param string $format - * - * @return string - */ - public function format($timestamp, $format) - { - $dt = DateTimeFactory::create(); - if (DateTimeFactory::isUnixTimestamp($timestamp)) { - $dt->setTimestamp($timestamp); - } else { - return $timestamp; - } - - return $dt->format($format); - } - - /** - * Format date according to user's format - * - * @param int $timestamp A unix timestamp - * - * @return string The formatted date string - */ - public function formatDate($timestamp) - { - return $this->format($timestamp, $this->getDateFormat()); - } - - /** - * Format time according to user's format - * - * @param int $timestamp A unix timestamp - * - * @return string The formatted time string - */ - public function formatTime($timestamp) - { - return $this->format($timestamp, $this->getTimeFormat()); - } - - /** - * Format datetime according to user's format - * - * @param int $timestamp A unix timestamp - * @return string The formatted datetime string - */ - public function formatDateTime($timestamp) - { - return $this->format($timestamp, $this->getDateTimeFormat()); - } - - /** - * Retrieve the user's date format string - * - * @return string - */ - public function getDateFormat() - { - // TODO(mh): Missing localized format (#6077) - return 'd/m/Y'; - } - - /** - * Retrieve the user's time format string - * - * @return string - */ - public function getTimeFormat() - { - // TODO(mh): Missing localized format (#6077) - return 'g:i A'; - } - - /** - * Retrieve the user's datetime format string - * - * @return string - */ - public function getDateTimeFormat() - { - return $this->getDateFormat() . ' ' . $this->getTimeFormat(); - } -} diff --git a/doc/authentication.md b/doc/authentication.md index 13a821441..39e0caf3c 100644 --- a/doc/authentication.md +++ b/doc/authentication.md @@ -32,7 +32,7 @@ If your web server is not configured for authentication though the `autologin` s ### Active Directory or LDAP Authentication If you want to authenticate against Active Directory or LDAP, you have to define a -[LDAP resource](#resources-configuration-ldap) which will be referenced as data source for the Active Directory +[LDAP resource](resources.md#resources-configuration-ldap) which will be referenced as data source for the Active Directory or LDAP configuration method. #### LDAP @@ -40,7 +40,7 @@ or LDAP configuration method. Directive | Description ------------------------|------------ **backend** | `ldap` -**resource** | The name of the LDAP resource defined in [resources.ini](#resources). +**resource** | The name of the LDAP resource defined in [resources.ini](resources.md#resources). **user_class** | LDAP user class. **user_name_attribute** | LDAP attribute which contains the username. @@ -63,7 +63,7 @@ with Icinga Web 2 (e.g. an alias) no matter what the primary user id might actua Directive | Description ------------------------|------------ **backend** | `ad` -**resource** | The name of the LDAP resource defined in [resources.ini](#resources). +**resource** | The name of the LDAP resource defined in [resources.ini](resources.md#resources). **Example:** @@ -76,19 +76,19 @@ resource = my_ad ### Database Authentication If you want to authenticate against a MySQL or a PostgreSQL database, you have to define a -[database resource](#resources-configuration-database) which will be referenced as data source for the database +[database resource](resources.md#resources-configuration-database) which will be referenced as data source for the database authentication method. Directive | Description ------------------------|------------ **backend** | `db` -**resource** | The name of the database resource defined in [resources.ini](#resources). +**resource** | The name of the database resource defined in [resources.ini](resources.md#resources). **Example:** ``` -[auth_ad] -backend = ad +[auth_db] +backend = db resource = icingaweb-mysql ``` @@ -99,7 +99,7 @@ For authenticating against a database, you have to import one of the following d * **etc/schema/preferences.mysql.sql** (for **MySQL** database) * **etc/schema/preferences.pgsql.sql** (for **PostgreSQL** databases) -After that you have to define the [database resource](#resources-configuration-database). +After that you have to define the [database resource](resources.md#resources-configuration-database). **Manually Creating Users** diff --git a/doc/preferences.md b/doc/preferences.md index 4ece5edf6..ca26b66b0 100644 --- a/doc/preferences.md +++ b/doc/preferences.md @@ -27,13 +27,13 @@ type = ini ### Store Preferences in a Database In order to be more flexible in distributed setups you can store preferences in a MySQL or in a PostgreSQL database. -For storing preferences in a database, you have to define a [database resource](#resources-configuration-database) +For storing preferences in a database, you have to define a [database resource](resources.md#resources-configuration-database) which will be referenced as resource for the preferences storage. Directive | Description ------------------------|------------ **type** | `db` -**resource** | The name of the database resource defined in [resources.ini](resources). +**resource** | The name of the database resource defined in [resources.ini](resources.md#resources). **Example:** @@ -50,4 +50,4 @@ For storing preferences in a database, you have to import one of the following d * **etc/schema/preferences.mysql.sql** (for **MySQL** database) * **etc/schema/preferences.pgsql.sql** (for **PostgreSQL** databases) -After that you have to define the [database resource](#resources-configuration-database). +After that you have to define the [database resource](resources.md#resources-configuration-database). diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index 070edb0cb..e265b91ee 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -12,7 +12,6 @@ use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; use Icinga\Exception\NotReadableError; use Icinga\Application\Logger; -use Icinga\Util\DateTimeFactory; use Icinga\Util\Translator; use Icinga\Exception\IcingaException; @@ -568,7 +567,6 @@ abstract class ApplicationBootstrap date_default_timezone_set($timezone); } } - DateTimeFactory::setConfig(array('timezone' => $timezone)); return $this; } diff --git a/library/Icinga/Chart/Unit/CalendarUnit.php b/library/Icinga/Chart/Unit/CalendarUnit.php index 5f4c6979c..0b0fe834f 100644 --- a/library/Icinga/Chart/Unit/CalendarUnit.php +++ b/library/Icinga/Chart/Unit/CalendarUnit.php @@ -4,7 +4,7 @@ namespace Icinga\Chart\Unit; -use Icinga\Util\DateTimeFactory; +use DateTime; /** * Calendar Axis Unit that transforms timestamps into user-readable values @@ -81,7 +81,7 @@ class CalendarUnit extends LinearUnit */ private function calculateLabels($unit) { - $fac = DateTimeFactory::create(); + $fac = new DateTime(); $duration = $this->getMax() - $this->getMin(); diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index ee0128608..c284f0e86 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -164,10 +164,12 @@ class DbQuery extends SimpleQuery $parts[] = $filterPart; } } - if ($level > 0) { - $str .= ' (' . implode($op, $parts) . ') '; - } else { - $str .= implode($op, $parts); + if (! empty($parts)) { + if ($level > 0) { + $str .= ' (' . implode($op, $parts) . ') '; + } else { + $str .= implode($op, $parts); + } } } } else { diff --git a/library/Icinga/Date/DateFormatter.php b/library/Icinga/Date/DateFormatter.php new file mode 100644 index 000000000..6d98efe8d --- /dev/null +++ b/library/Icinga/Date/DateFormatter.php @@ -0,0 +1,255 @@ + 3600 * 24 * 3) { + $type = static::DATE; + if (date('Y') === date('Y', $time)) { + $formatted = date('M j', $time); + } else { + $formatted = date('Y-m', $time); + } + } else { + $minutes = floor($diff / 60); + if ($minutes < 60) { + $type = static::RELATIVE; + $formatted = sprintf('%dm %ds', $minutes, $diff % 60); + } else { + $hours = floor($minutes / 60); + if ($hours < 24) { + if (date('d') === date('d', $time)) { + $type = static::TIME; + $formatted = date('H:i', $time); + } else { + $type = static::DATE; + $formatted = date('M j H:i', $time); + } + } else { + $type = static::RELATIVE; + $formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24); + } + } + } + return array($type, $formatted, $invert); + } + + /** + * Format date + * + * @param int|float $date + * + * @return string + */ + public static function formatDate($date) + { + return date('Y-m-d', (float) $date); + } + + /** + * Format date and time + * + * @param int|float $dateTime + * + * @return string + */ + public static function formatDateTime($dateTime) + { + return date('Y-m-d H:i:s', (float) $dateTime); + } + + /** + * Format a duration + * + * @param int|float $seconds Duration in seconds + * + * @return string + */ + public static function formatDuration($seconds) + { + $minutes = floor((float) $seconds / 60); + if ($minutes < 60) { + $formatted = sprintf('%dm %ds', $minutes, $seconds % 60); + } else { + $hours = floor($minutes / 60); + if ($hours < 24) { + $formatted = sprintf('%dh %dm', $hours, $minutes % 60); + } else { + $formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24); + } + } + return $formatted; + } + + /** + * Format time + * + * @param int|float $time + * + * @return string + */ + public static function formatTime($time) + { + return date('H:i:s', (float) $time); + } + + /** + * Format time as time ago + * + * @param int|float $time + * @param bool $timeOnly + * + * @return string + */ + public static function timeAgo($time, $timeOnly = false) + { + list($type, $ago, $invert) = static::diff($time); + if ($timeOnly) { + return $ago; + } + switch ($type) { + case static::DATE: + // Move to next case + case static::DATETIME: + $formatted = sprintf( + t('on %s', 'An event happened on the given date or date and time'), + $ago + ); + break; + case static::RELATIVE: + $formatted = sprintf( + t('%s ago', 'An event that happened the given time interval ago'), + $ago + ); + break; + case static::TIME: + $formatted = sprintf(t('at %s', 'An event happened at the given time'), $ago); + break; + } + return $formatted; + } + + /** + * Format time as time since + * + * @param int|float $time + * @param bool $timeOnly + * + * @return string + */ + public static function timeSince($time, $timeOnly = false) + { + list($type, $since, $invert) = static::diff($time); + if ($timeOnly) { + return $since; + } + switch ($type) { + case static::RELATIVE: + $formatted = sprintf( + t('for %s', 'A status is lasting for the given time interval'), + $since + ); + break; + case static::DATE: + // Move to next case + case static::DATETIME: + // Move to next case + case static::TIME: + $formatted = sprintf( + t('since %s', 'A status is lasting since the given time, date or date and time'), + $since + ); + break; + } + return $formatted; + } + + /** + * Format time as time until + * + * @param int|float $time + * @param bool $timeOnly + * + * @return string + */ + public static function timeUntil($time, $timeOnly = false) + { + list($type, $until, $invert) = static::diff($time); + if ($invert && $type === static::RELATIVE) { + $until = '-' . $until; + } + if ($timeOnly) { + return $until; + } + switch ($type) { + case static::DATE: + // Move to next case + case static::DATETIME: + $formatted = sprintf( + t('on %s', 'An event will happen on the given date or date and time'), + $until + ); + break; + case static::RELATIVE: + $formatted = sprintf( + t('in %s', 'An event will happen after the given time interval has elapsed'), + $until + ); + break; + case static::TIME: + $formatted = sprintf(t('at %s', 'An event will happen at the given time'), $until); + break; + } + return $formatted; + } +} diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php index 542c493f1..9fdc72a57 100644 --- a/library/Icinga/Test/BaseTestCase.php +++ b/library/Icinga/Test/BaseTestCase.php @@ -25,7 +25,6 @@ namespace Icinga\Test { use Mockery; use PHPUnit_Framework_TestCase; use Icinga\Application\Icinga; - use Icinga\Util\DateTimeFactory; use Icinga\Data\ConfigObject; use Icinga\Data\ResourceFactory; use Icinga\Data\Db\DbConnection; @@ -104,12 +103,11 @@ namespace Icinga\Test { ); /** - * Setup the default timezone and pass it to DateTimeFactory::setConfig + * Setup the default timezone */ public static function setupTimezone() { date_default_timezone_set('UTC'); - DateTimeFactory::setConfig(array('timezone' => 'UTC')); } /** diff --git a/library/Icinga/Util/DateTimeFactory.php b/library/Icinga/Util/DateTimeFactory.php deleted file mode 100644 index 3a532552b..000000000 --- a/library/Icinga/Util/DateTimeFactory.php +++ /dev/null @@ -1,92 +0,0 @@ -= ~PHP_INT_MAX); - } -} diff --git a/library/Icinga/Util/Format.php b/library/Icinga/Util/Format.php index b999626b9..ba536e443 100644 --- a/library/Icinga/Util/Format.php +++ b/library/Icinga/Util/Format.php @@ -4,6 +4,7 @@ namespace Icinga\Util; use DateTime; +use Icinga\Date\DateFormatter; use Icinga\Exception\ProgrammingError; class Format @@ -58,86 +59,13 @@ class Format if ($value < 60) { return self::formatForUnits($value, self::$secondPrefix, self::$secondBase); } elseif ($value < 3600) { - return sprintf('0.2f m', $value / 60); + return sprintf('%0.2f m', $value / 60); } elseif ($value < 86400) { - return sprintf('0.2f h', $value / 3600); + return sprintf('%0.2f h', $value / 3600); } // TODO: Do we need weeks, months and years? - return sprintf('0.2f d', $value / 86400); - } - - public static function duration($duration) - { - if ($duration === null || $duration === false) { - return '-'; - } - return self::showHourMin($duration); - } - - protected static function showHourMin($sec, $includePrefix = false) - { - $min = floor($sec / 60); - if ($min < 60) { - return ($includePrefix ? t('for') . ' ' : '') . $min . 'm ' . ($sec % 60) . 's'; - } - $hour = floor($min / 60); - if ($hour < 24) { - return ($includePrefix ? t('since') . ' ' : '') . date('H:i', time() - $sec); - } - return ($includePrefix ? t('for') . ' ' : '') . floor($hour / 24) . 'd ' . ($hour % 24) . 'h'; - } - - protected static function smartTimeDiff($diff, $timestamp, $includePrefix = false) - { - if ($timestamp === null || $timestamp === false) { - return '-'; - } - if (! preg_match('~^\d+$~', $timestamp)) { - throw new ProgrammingError( - '"%s" is not a number', - $timestamp - ); - } - $prefix = ''; - if ($diff < 0) { - $prefix = '-'; - } - if (abs($diff) > 3600 * 24 * 3) { - if (date('Y') === date('Y', $timestamp)) { - return ($includePrefix ? t('since') . ' ' : '') . date('d.m.', $timestamp); - } - return ($includePrefix ? t('since') . ' ' : '') . date('m.Y', $timestamp); - } - return $prefix . self::showHourMin(abs($diff), $includePrefix); - } - - public static function timeSince($timestamp) - { - return self::smartTimeDiff(time() - $timestamp, $timestamp); - } - - public static function prefixedTimeSince($timestamp, $ucfirst = false) - { - $result = self::smartTimeDiff(time() - $timestamp, $timestamp, true); - if ($ucfirst) { - $result = ucfirst($result); - } - return $result; - } - - public static function timeUntil($timestamp) - { - return self::smartTimeDiff($timestamp - time(), $timestamp); - } - - public static function prefixedTimeUntil($timestamp, $ucfirst) - { - $result = self::smartTimeDiff($timestamp - time(), $timestamp, true); - if ($ucfirst) { - $result = ucfirst($result); - } - return $result; + return sprintf('%0.2f d', $value / 86400); } protected static function formatForUnits($value, & $units, $base) diff --git a/library/Icinga/Web/Form/Validator/DateTimeValidator.php b/library/Icinga/Web/Form/Validator/DateTimeValidator.php index 576ed36f8..c0abfc481 100644 --- a/library/Icinga/Web/Form/Validator/DateTimeValidator.php +++ b/library/Icinga/Web/Form/Validator/DateTimeValidator.php @@ -5,7 +5,6 @@ namespace Icinga\Web\Form\Validator; use DateTime; use Zend_Validate_Abstract; -use Icinga\Util\DateTimeFactory; /** * Validator for date-and-time input controls @@ -68,7 +67,7 @@ class DateTimeValidator extends Zend_Validate_Abstract } if ($dateTime === false || $dateTime->format($format) !== $value) { - $this->_error(self::INVALID_DATETIME_FORMAT, DateTimeFactory::create()->format($baseFormat)); + $this->_error(self::INVALID_DATETIME_FORMAT, $baseFormat); return false; } } diff --git a/library/Icinga/Web/View/DateTimeRenderer.php b/library/Icinga/Web/View/DateTimeRenderer.php deleted file mode 100644 index 058f07ad8..000000000 --- a/library/Icinga/Web/View/DateTimeRenderer.php +++ /dev/null @@ -1,204 +0,0 @@ -future = $future; - $this->now = new DateTime(); - $this->dateTime = $this->normalize($dateTime); - $this->detectType(); - } - - /** - * Creates a new DateTimeRenderer - * - * @param DateTime|int $dateTime - * @param bool $future - * - * @return DateTimeRenderer - */ - public static function create($dateTime, $future = false) - { - return new static($dateTime, $future); - } - - /** - * Detects the DateTime context - */ - protected function detectType() - { - if ($this->now->format('Y-m-d') !== $this->dateTime->format('Y-m-d')) { - $this->type = self::TYPE_DATETIME; - return; - } - - if ( - $this->now->format('Y-m-d') === $this->dateTime->format('Y-m-d') && - (abs($this->now->getTimestamp() - $this->dateTime->getTimestamp()) >= self::HOUR) - ) { - $this->type = self::TYPE_TIME; - return; - } - - if ( - $this->now->format('Y-m-d') === $this->dateTime->format('Y-m-d') && - (abs($this->now->getTimestamp() - $this->dateTime->getTimestamp()) < self::HOUR) - ) { - $this->type = self::TYPE_TIMESPAN; - return; - } - } - - /** - * Normalizes the given DateTime - * - * @param DateTime|int $dateTime - * - * @return DateTime - */ - public static function normalize($dateTime) - { - if (! ($dt = $dateTime) instanceof DateTime) { - $dt = new DateTime(); - $dt->setTimestamp($dateTime); - } - return $dt; - } - - /** - * Checks whether DateTime is a date with time - * - * @return bool - */ - public function isDateTime() - { - return $this->type === self::TYPE_DATETIME; - } - - /** - * Checks whether DateTime is a time of the current day - * - * @return bool - */ - public function isTime() - { - return $this->type === self::TYPE_TIME; - } - - /** - * Checks whether DateTime is in a defined interval - * - * @return bool - */ - public function isTimespan() - { - return $this->type === self::TYPE_TIMESPAN; - } - - /** - * Returns the type of the DateTime - * - * @return mixed - */ - public function getType() - { - return $this->type; - } - - /** - * Renders the DateTime on the basis of the type and returns suited text - * - * @param string $dateTimeText - * @param string $timeText - * @param string $timespanText - * - * @return string - */ - public function render($dateTimeText, $timeText, $timespanText) - { - if ($this->isDateTime()) { - return sprintf($dateTimeText, $this); - } elseif ($this->isTime()) { - return sprintf($timeText, $this); - } elseif ($this->isTimespan()) { - return sprintf($timespanText, $this); - } - - return $dateTimeText; - } - - /** - * Returns a rendered html wrapped text - * - * @return string - */ - public function __toString() - { - switch ($this->type) { - case self::TYPE_DATETIME: - $format = $this->dateTime->format('d.m.Y - H:i:s'); - break; - case self::TYPE_TIME: - $format = $this->dateTime->format('H:i:s'); - break; - case self::TYPE_TIMESPAN: - $format = $this->dateTime->diff($this->now)->format(t('%im %ss', 'timespan')); - break; - default: - $format = $this->dateTime->format('d.m.Y - H:i:s'); - break; - } - - $css = ''; - if ($this->type === self::TYPE_TIMESPAN) { - $css = $this->future === true ? 'timeuntil' : 'timesince'; - } - - return sprintf( - '%s', - $css, - $this->dateTime->format('d.m.Y - H:i:s'), - $format - ); - } -} diff --git a/library/Icinga/Web/View/helpers/format.php b/library/Icinga/Web/View/helpers/format.php index e9d8e23bc..73257d079 100644 --- a/library/Icinga/Web/View/helpers/format.php +++ b/library/Icinga/Web/View/helpers/format.php @@ -3,47 +3,70 @@ namespace Icinga\Web\View; -use Icinga\Web\Url; +use Icinga\Date\DateFormatter; use Icinga\Util\Format; $this->addHelperFunction('format', function () { return Format::getInstance(); }); -$this->addHelperFunction('timeSince', function ($timestamp) { +$this->addHelperFunction('formatDate', function ($date) { + if (! $date) { + return ''; + } + return DateFormatter::formatDate($date); +}); + +$this->addHelperFunction('formatDateTime', function ($dateTime) { + if (! $dateTime) { + return ''; + } + return DateFormatter::formatDateTime($dateTime); +}); + +$this->addHelperFunction('formatDuration', function ($seconds) { + if (! $seconds) { + return ''; + } + return DateFormatter::formatDuration($seconds); +}); + +$this->addHelperFunction('formatTime', function ($time) { + if (! $time) { + return ''; + } + return DateFormatter::formatTime($time); +}); + +$this->addHelperFunction('timeAgo', function ($time, $timeOnly = false) { + if (! $time) { + return ''; + } return sprintf( - '%s', - date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format - Format::timeSince($timestamp) + '%s', + DateFormatter::formatDateTime($time), + DateFormatter::timeAgo($time, $timeOnly) ); }); -$this->addHelperFunction('prefixedTimeSince', function ($timestamp, $ucfirst = false) { +$this->addHelperFunction('timeSince', function ($time, $timeOnly = false) { + if (! $time) { + return ''; + } return sprintf( - '%s', - date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format - Format::prefixedTimeSince($timestamp, $ucfirst) + '%s', + DateFormatter::formatDateTime($time), + DateFormatter::timeSince($time, $timeOnly) ); }); -$this->addHelperFunction('timeUntil', function ($timestamp) { - if (! $timestamp) return ''; +$this->addHelperFunction('timeUntil', function ($time, $timeOnly = false) { + if (! $time) { + return ''; + } return sprintf( - '%s', - date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format - Format::timeUntil($timestamp) + '%s', + DateFormatter::formatDateTime($time), + DateFormatter::timeUntil($time, $timeOnly) ); }); - -$this->addHelperFunction('prefixedTimeUntil', function ($timestamp, $ucfirst = false) { - if (! $timestamp) return ''; - return sprintf( - '%s', - date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format - Format::prefixedTimeUntil($timestamp, $ucfirst) - ); -}); - -$this->addHelperFunction('dateTimeRenderer', function ($dateTimeOrTimestamp, $future = false) { - return DateTimeRenderer::create($dateTimeOrTimestamp, $future); -}); diff --git a/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php b/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php index 8ffd3ea00..0eb41c574 100644 --- a/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php +++ b/library/Icinga/Web/Widget/Chart/HistoryColorGrid.php @@ -3,10 +3,10 @@ namespace Icinga\Web\Widget\Chart; -use Icinga\Util\DateTimeFactory; +use DateInterval; +use DateTime; use Icinga\Util\Color; use Icinga\Web\Widget\AbstractWidget; -use DateInterval; /** * Display a colored grid that visualizes a set of values for each day @@ -313,7 +313,7 @@ class HistoryColorGrid extends AbstractWidget { private function monthName($month, $year) { // TODO: find a way to render years without messing up the layout - $dt = DateTimeFactory::create($year . '-' . $month . '-01'); + $dt = new DateTime($year . '-' . $month . '-01'); return $dt->format('M'); } @@ -324,7 +324,7 @@ class HistoryColorGrid extends AbstractWidget { */ private function weekdayName($weekday) { - $sun = DateTimeFactory::create('last Sunday'); + $sun = new DateTime('last Sunday'); $interval = new DateInterval('P' . $weekday . 'D'); $sun->add($interval); return substr($sun->format('D'), 0, 2); diff --git a/modules/monitoring/application/clicommands/ListCommand.php b/modules/monitoring/application/clicommands/ListCommand.php index 57a1afecf..9fd892652 100644 --- a/modules/monitoring/application/clicommands/ListCommand.php +++ b/modules/monitoring/application/clicommands/ListCommand.php @@ -299,7 +299,7 @@ class ListCommand extends Command $leaf, $screen->underline($row->service_description), $screen->colorize($utils->objectStateFlags('service', $row) . $perf, 'lightblue'), - Format::prefixedTimeSince($row->service_last_state_change, true) + ucfirst(Format::timeSince($row->service_last_state_change)) ); if ($this->isVerbose) { $out .= $emptyLine . preg_replace( diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 78c8eaa7e..20ae71e6b 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -46,7 +46,7 @@ class Monitoring_HostsController extends Controller 'icon' => 'host' ) )->extend(new DashboardAction())->activate('show'); - + $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts')->setQueryString($filterString); } @@ -78,11 +78,6 @@ class Monitoring_HostsController extends Controller $this->view->form = $form; $this->view->objects = $this->hostList; $this->view->stats = $this->hostList->getStateSummary(); - $this->view->hostStatesPieChart = InlinePie::createFromStateSummary( - $this->view->stats, - $this->translate('Host State'), - InlinePie::$colorsHostStatesHandledUnhandled - ); $this->_helper->viewRenderer('partials/command/objects-command-form', null, true); return $form; } diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 25827c766..6d313083f 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -1,11 +1,8 @@ _request->getParam('start'); $startTimestamp = is_numeric($startParam) ? intval($startParam) : strtotime($startParam); if ($startTimestamp !== false) { @@ -271,8 +268,7 @@ class Monitoring_TimelineController extends Controller */ private function getTimeFormat() { - // TODO(mh): Missing localized format (#6077) - return 'g:i A'; + return 'H:i'; } /** @@ -282,7 +278,6 @@ class Monitoring_TimelineController extends Controller */ private function getDateFormat() { - // TODO(mh): Missing localized format (#6077) - return 'd/m/Y'; + return 'Y-m-d'; } } diff --git a/modules/monitoring/application/views/scripts/comment/show.phtml b/modules/monitoring/application/views/scripts/comment/show.phtml index 8216a9c70..17e72e7c9 100644 --- a/modules/monitoring/application/views/scripts/comment/show.phtml +++ b/modules/monitoring/application/views/scripts/comment/show.phtml @@ -1,4 +1,4 @@ -
+
compact): ?> tabs; ?> @@ -8,13 +8,13 @@
- +

translate('Comment detail information') ?>

- +
comment->objecttype === 'service'): ?> - + - + + @@ -42,29 +42,29 @@ - + - + - + - + - + @@ -73,7 +73,7 @@ - +
translate('Service') ?> translate('Service') ?> icon('service', $this->translate('Service')); ?> link()->service( @@ -26,7 +26,7 @@ ?> translate('Host') ?> translate('Host') ?> icon('host', $this->translate('Host')); ?> link()->host( @@ -34,7 +34,7 @@ $this->comment->host_display_name ); ?> -
translate('Author') ?> icon('user', $this->translate('User')) ?> escape($this->comment->author) ?>
translate('Persistent') ?> escape($this->comment->persistent) ? $this->translate('Yes') : $this->translate('No') ?>
translate('Created') ?>escape($this->comment->timestamp)) ?>formatDateTime($this->comment->timestamp) ?>
translate('Expires') ?> comment->expiration ? sprintf( $this->translate('This comment expires on %s at %s.'), - date('d.m.y', $this->comment->expiration), - date('H:i', $this->comment->expiration) + $this->formatDate($this->comment->expiration), + $this->formatTime($this->comment->expiration) ) : $this->translate('This comment does not expire.'); ?>
translate('Commands') ?>
diff --git a/modules/monitoring/application/views/scripts/downtime/show.phtml b/modules/monitoring/application/views/scripts/downtime/show.phtml index aed35b9ac..4a3583363 100644 --- a/modules/monitoring/application/views/scripts/downtime/show.phtml +++ b/modules/monitoring/application/views/scripts/downtime/show.phtml @@ -1,13 +1,13 @@ -
+
compact): ?> tabs; ?> - + render('partials/downtime/downtime-header.phtml'); ?>

translate('Downtime detail information') ?>

- +
- + @@ -44,19 +44,19 @@ - + @@ -66,14 +66,14 @@ . 'this refers to the earliest possible time that the downtime' . ' can start'); ?>"> - + - + downtime->is_flexible): ?> - + - + - + - + - + diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index f8c4383bd..551d0cbac 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -36,7 +36,7 @@ if (count($comments) === 0) {
@@ -15,17 +15,17 @@ isService): ?> - link()->service( - $downtime->service_description, + $downtime->service_description, $downtime->service_display_name, $downtime->host_name, $downtime->host_display_name ); - $icon = $this->icon('service', $this->translate('Service')); + $icon = $this->icon('service', $this->translate('Service')); ?> - icon('host', $this->translate('Host')); $link = $this->link()->host($downtime->host_name, $downtime->host_display_name) ?> @@ -33,7 +33,7 @@
translate('Author') ?> icon('user', $this->translate('User')) ?> escape($this->downtime->author_name) ?>
translate('Entry Time') ?> escape($this->downtime->entry_time)) ?>formatDateTime($this->downtime->entry_time) ?>
escape( - $this->downtime->is_flexible ? + $this->downtime->is_flexible ? $this->translate('Flexible') : $this->translate('Fixed') ); ?> escape( - $this->downtime->is_flexible ? - $this->translate('Flexible downtimes have a hard start and end time,' - . ' but also an additional restriction on the duration in which ' - . ' the host or service may actually be down.') : + $this->downtime->is_flexible ? + $this->translate('Flexible downtimes have a hard start and end time,' + . ' but also an additional restriction on the duration in which ' + . ' the host or service may actually be down.') : $this->translate('Fixed downtimes have a static start and end time.') ); ?> translate('Scheduled start') ?>downtime->scheduled_start) ?>formatDateTime($this->downtime->scheduled_start) ?>
translate('Scheduled end') ?>downtime->scheduled_end) ?>formatDateTime($this->downtime->scheduled_end) ?>
translate('Duration') ?>format()->duration($this->escape($this->downtime->duration)); ?>formatDuration($this->downtime->duration) ?>
translate('Actual start time') ?>start); ?>formatDateTime($downtime->start) ?>
translate('Actual end time') ?>end); ?>formatDateTime($downtime->end) ?>
translate('In effect') ?> escape( - $this->downtime->is_in_effect ? + $this->downtime->is_in_effect ? $this->translate('Yes') : $this->translate('No') - ); + ); ?>
translate('Commands') ?> objecttype === 'service'): ?> icon('service', $this->translate('Service')); ?> - + qlink( sprintf( $this->translate('%s on %s', 'Service running on host'), @@ -52,7 +52,7 @@ if (count($comments) === 0) { ))) ?> icon('host', $this->translate('Host')); ?> - + qlink( $comment->host_display_name, 'monitoring/comment/show', @@ -74,10 +74,9 @@ if (count($comments) === 0) { ?>
expiration ? sprintf( - $this->translate('This comment expires on %s at %s.'), - date('d.m.y', $comment->expiration), - date('H:i', $comment->expiration) - ) : $this->translate('This comment does not expire.'); ?> + $this->translate('This comment expires %s.'), + $this->timeUntil($comment->expiration) + ) : $this->translate('This comment does not expire.'); ?>
diff --git a/modules/monitoring/application/views/scripts/list/downtimes.phtml b/modules/monitoring/application/views/scripts/list/downtimes.phtml index 79a0e1b92..d062274e7 100644 --- a/modules/monitoring/application/views/scripts/list/downtimes.phtml +++ b/modules/monitoring/application/views/scripts/list/downtimes.phtml @@ -26,8 +26,8 @@ if (count($downtimes) === 0) { return; } ?> - @@ -45,24 +45,15 @@ if (count($downtimes) === 0) { diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index c49f5fc3f..3d1598a69 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -32,11 +32,7 @@ if (count($notifications) === 0) { ?> services_unknown_last_state_change_unhandled): ?> services_warning_last_state_change_unhandled): ?> services_critical_last_state_change_handled): ?> services_unknown_last_state_change_handled): ?> services_warning_last_state_change_handled): ?> services_ok_last_state_change): ?> - + - + - + @@ -66,7 +66,10 @@ if (! $this->compact): ?> programStatus->is_currently_running === true): ?>
translate('Backend %s has been up and running with PID %d since %s'), + $this->translate( + '%1$s has been up and running with PID %2$d %3$s', + 'Last format parameter represents the time running' + ), $this->backendName, $this->programStatus->process_id, $this->timeSince($this->programStatus->program_start_time)) ?> diff --git a/modules/monitoring/application/views/scripts/show/components/checkstatistics.phtml b/modules/monitoring/application/views/scripts/show/components/checkstatistics.phtml index 18fbdb82f..415b66b76 100644 --- a/modules/monitoring/application/views/scripts/show/components/checkstatistics.phtml +++ b/modules/monitoring/application/views/scripts/show/components/checkstatistics.phtml @@ -20,7 +20,7 @@ if ($object->getType() === $object::TYPE_HOST) { - timeSince($object->last_check) ?> + timeAgo($object->last_check) ?>
@@ -54,7 +54,8 @@ if ($object->getType() === $object::TYPE_HOST) { ) ); } - } ?> timeUntil($object->next_check) ?> + } ?> + timeUntil($object->next_check) ?> diff --git a/modules/monitoring/application/views/scripts/show/components/comments.phtml b/modules/monitoring/application/views/scripts/show/components/comments.phtml index 478b1e7f3..c4b947e3c 100644 --- a/modules/monitoring/application/views/scripts/show/components/comments.phtml +++ b/modules/monitoring/application/views/scripts/show/components/comments.phtml @@ -44,7 +44,7 @@ foreach ($object->comments as $comment) { ?> - + - + diff --git a/modules/monitoring/application/views/scripts/show/components/notifications.phtml b/modules/monitoring/application/views/scripts/show/components/notifications.phtml index af57eb934..5fea60cc1 100644 --- a/modules/monitoring/application/views/scripts/show/components/notifications.phtml +++ b/modules/monitoring/application/views/scripts/show/components/notifications.phtml @@ -1,59 +1,66 @@ - - + + // We are not interested in notifications for OK or pending objects + if (! in_array((int) $object->state, array(0, 99))) { + if ($object->current_notification_number > 0) { + if ((int) $object->current_notification_number === 1) { + $msg = sprintf( + $this->translate('A notification has been sent for this issue %s.'), + $this->timeAgo($object->last_notification) + ); + } else { + $msg = sprintf( + $this->translate('%d notifications have been sent for this issue.'), + $object->current_notification_number + ) . '
' . sprintf( + $this->translate('The last one was sent %s.'), + $this->timeAgo($object->last_notification) + ); + } + } else { + $msg = $this->translate('No notification has been sent for this issue.'); + } + echo $msg; + } + ?> + diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index 357948373..c64f24b84 100644 --- a/modules/monitoring/public/css/module.less +++ b/modules/monitoring/public/css/module.less @@ -234,3 +234,11 @@ div.backend-not-running { text-align: center; padding: 0.1em; } + +td.state { + .time-ago, + .time-since, + .time-until { + text-transform: capitalize; + } +} diff --git a/public/css/icinga/monitoring-colors.less b/public/css/icinga/monitoring-colors.less index 020db57cd..2b2b70b27 100644 --- a/public/css/icinga/monitoring-colors.less +++ b/public/css/icinga/monitoring-colors.less @@ -445,8 +445,9 @@ div.box.contents.zero { div.box.contents.zero span { font-weight: bold; + line-height: 2em; - color: white; + color: #666; } div.box.contents.zero h3 { @@ -454,7 +455,7 @@ div.box.contents.zero h3 { font-size: 12em; line-height: 1em; - color: white; + color: #666; } div.box.ok_hosts.state_up { diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index 3bfb87c61..b9e63aa11 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -577,70 +577,60 @@ ); }, + /** + * Refresh partial time counters + * + * This function runs every second. + */ refreshTimeSince: function () { - - $('.timesince').each(function (idx, el) { - - // todo remove after replace timeSince - var mp = el.innerHTML.match(/^(.*?)(-?\d+)d\s(-?\d+)h/); - if (mp !== null) { - return true; - } - - var m = el.innerHTML.match(/^(.*?)(-?\d+)(.+\s)(-?\d+)(.+)/); - if (m !== null) { - var nm = parseInt(m[2]); - var ns = parseInt(m[4]); - if (ns < 59) { - ns++; + $('.time-ago, .time-since').each(function (idx, el) { + var partialTime = /(\d{1,2})m (\d{1,2})s/.exec(el.innerHTML); + if (partialTime !== null) { + var minute = parseInt(partialTime[1], 10), + second = parseInt(partialTime[2], 10); + if (second < 59) { + ++second; } else { - ns = 0; - nm++; + ++minute; + second = 0; } - $(el).html(m[1] + nm + m[3] + ns + m[5]); + el.innerHTML = el.innerHTML.substr(0, partialTime.index) + minute.toString() + 'm ' + + second.toString() + 's' + el.innerHTML.substr(partialTime.index + partialTime[0].length); } }); - $('.timeuntil').each(function (idx, el) { - - // todo remove after replace timeUntil - var mp = el.innerHTML.match(/^(.*?)(-?\d+)d\s(-?\d+)h/); - if (mp !== null) { - return true; - } - - var m = el.innerHTML.match(/^(.*?)(-?\d+)(.+\s)(-?\d+)(.+)/); - if (m !== null) { - var nm = parseInt(m[2]); - var ns = parseInt(m[4]); - var signed = ''; - var sec = 0; - - if (nm < 0) { - signed = '-'; - nm = nm * -1; - sec = nm * 60 + ns; - sec++; - } else if (nm == 0 && ns == 0) { - signed = '-'; - sec = 1; - } else if (nm == 0 && m[2][0] == '-') { - signed = '-'; - sec = ns; - sec++; - } else if (nm == 0 && m[2][0] != '-') { - sec = ns; - sec--; + $('.time-until').each(function (idx, el) { + var partialTime = /(-?)(\d{1,2})m (\d{1,2})s/.exec(el.innerHTML); + if (partialTime !== null) { + var minute = parseInt(partialTime[2], 10), + second = parseInt(partialTime[3], 10), + invert = partialTime[1]; + if (invert.length) { + // Count up because partial time is negative + if (second < 59) { + ++second; + } else { + ++minute; + second = 0; + } } else { - signed = ''; - sec = nm * 60 + ns; - sec--; + // Count down because partial time is positive + if (second === 0) { + if (minute === 0) { + // Invert counter + minute = 0; + second = 1; + invert = '-'; + } else { + --minute; + second = 59; + } + } else { + --second; + } } - - nm = Math.floor(sec/60); - ns = sec - nm * 60; - - $(el).html(m[1] + signed + nm + m[3] + ns + m[5]); + el.innerHTML = el.innerHTML.substr(0, partialTime.index) + invert + minute.toString() + 'm ' + + second.toString() + 's' + el.innerHTML.substr(partialTime.index + partialTime[0].length); } }); }, diff --git a/test/php/library/Icinga/Util/DateTimeFactoryTest.php b/test/php/library/Icinga/Util/DateTimeFactoryTest.php deleted file mode 100644 index 2e8e097eb..000000000 --- a/test/php/library/Icinga/Util/DateTimeFactoryTest.php +++ /dev/null @@ -1,69 +0,0 @@ - 'invalid')); - } - - public function testWhetherParseWorksWithASpecificTimezone() - { - $dt = DateTimeFactory::parse('17-04-14 17:00', 'd-m-y H:i', new DateTimeZone('Europe/Berlin')); - $dt->setTimezone(new DateTimeZone('UTC')); - - $this->assertEquals( - '15', - $dt->format('H'), - 'DateTimeFactory::parse does not properly parse a given datetime or does not respect the given timezone' - ); - } - - public function testWhetherParseWorksWithoutASpecificTimezone() - { - $this->assertEquals( - '15', - DateTimeFactory::parse('17-04-14 15:00', 'd-m-y H:i')->format('H'), - 'DateTimeFactory::parse does not properly parse a given datetime' - ); - } - - public function testWhetherCreateWorksWithASpecificTimezone() - { - $dt = DateTimeFactory::create('2014-04-17 5PM', new DateTimeZone('Europe/Berlin')); - $dt->setTimezone(new DateTimeZone('UTC')); - - $this->assertEquals( - '15', - $dt->format('H'), - 'DateTimeFactory::create does not properly parse a given datetime or does not respect the given timezone' - ); - } - - public function testWhetherCreateWorksWithoutASpecificTimezone() - { - $this->assertEquals( - '15', - DateTimeFactory::create('2014-04-17 3PM')->format('H'), - 'DateTimeFactory::create does not properly parse a given datetime' - ); - } -} diff --git a/test/php/library/Icinga/Web/View/DateTimeRendererTest.php b/test/php/library/Icinga/Web/View/DateTimeRendererTest.php deleted file mode 100644 index 279c18ba1..000000000 --- a/test/php/library/Icinga/Web/View/DateTimeRendererTest.php +++ /dev/null @@ -1,101 +0,0 @@ -assertInstanceOf( - 'Icinga\Web\View\DateTimeRenderer', - $dt, - 'Dashboard::create() could not create DateTimeRenderer' - ); - } - - /** - * @depends testWhetherCreateCreatesDateTimeRenderer - */ - public function testWhetherIsDateTimeReturnsRightType() - { - $dateTime = new DateTime('+1 day'); - $dt = DateTimeRenderer::create($dateTime); - - $this->assertTrue( - $dt->isDateTime(), - 'Dashboard::isDateTime() returns wrong type' - ); - } - - /** - * @depends testWhetherCreateCreatesDateTimeRenderer - */ - public function testWhetherIsTimeReturnsRightType() - { - $dateTime = new DateTime('+1 hour'); - $dt = DateTimeRenderer::create($dateTime); - - $this->assertTrue( - $dt->isTime(), - 'Dashboard::isTime() returns wrong type' - ); - } - - /** - * @depends testWhetherCreateCreatesDateTimeRenderer - */ - public function testWhetherIsTimespanReturnsRightType() - { - $dateTime = new DateTime('+1 minute'); - $dt = DateTimeRenderer::create($dateTime); - - $this->assertTrue( - $dt->isTimespan(), - 'Dashboard::isTimespan() returns wrong type' - ); - } - - /** - * @depends testWhetherCreateCreatesDateTimeRenderer - */ - public function testWhetherNormalizeReturnsNormalizedDateTime() - { - $dateTime = time(); - $dt = DateTimeRenderer::normalize($dateTime); - - $this->assertInstanceOf( - 'DateTime', - $dt, - 'Dashboard::normalize() returns wrong instance' - ); - } - - /** - * @depends testWhetherCreateCreatesDateTimeRenderer - */ - public function testWhetherRenderReturnsRightText() - { - $dateTime = new DateTime('+1 minute'); - $dt = DateTimeRenderer::create($dateTime); - - $text = $dt->render( - '#1 The service is down since %s', - '#2 The service is down since %s o\'clock.', - '#3 The service is down for %s.' - ); - - $this->assertRegExp( - '/#3/', - $text, - 'Dashboard::render() returns wrong text' - ); - } -}
is_in_effect ? $this->translate('Expires') : $this->translate('Starts'); ?>
- dateTimeRenderer( - ($downtime->is_in_effect ? $downtime->end : $downtime->start), - true - )->render( - $this->translate('on %s', 'datetime'), - $this->translate('at %s', 'time'), - $this->translate('in %s', 'timespan') - ); - ?> + timeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start, $this->compact) ?>
- icon('service'); } else { echo $this->icon('host'); - } + } ?> qlink( sprintf($this->translate('%s on %s', 'Service running on host'), $downtime->service_display_name, $downtime->host_display_name), @@ -83,20 +74,20 @@ if (count($downtimes) === 0) { $isService ? $this->translate('This flexible service downtime was started on %s at %s and lasts for %s until %s at %s.') : $this->translate('This flexible host downtime was started on %s at %s and lasts for %s until %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - $this->format()->duration($downtime->duration), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDuration($downtime->duration), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> translate('This flexible service downtime has been scheduled to start between %s - %s and to last for %s.') : $this->translate('This flexible host downtime has been scheduled to start between %s - %s and to last for %s.'), - date('d.m.y H:i', $downtime->scheduled_start), - date('d.m.y H:i', $downtime->scheduled_end), - $this->format()->duration($downtime->duration) + $this->formatDateTime($downtime->scheduled_start), + $this->formatDateTime($downtime->scheduled_end), + $this->formatDuration($downtime->duration) ); ?> @@ -105,20 +96,20 @@ if (count($downtimes) === 0) { $isService ? $this->translate('This fixed service downtime was started on %s at %s and expires on %s at %s.') : $this->translate('This fixed host downtime was started on %s at %s and expires on %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> translate('This fixed service downtime has been scheduled to start on %s at %s and to end on %s at %s.') : $this->translate('This fixed host downtime has been scheduled to start on %s at %s and to end on %s at %s.'), - date('d.m.y', $downtime->scheduled_start), - date('H:i', $downtime->scheduled_start), - date('d.m.y', $downtime->scheduled_end), - date('H:i', $downtime->scheduled_end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> diff --git a/modules/monitoring/application/views/scripts/list/eventgrid.phtml b/modules/monitoring/application/views/scripts/list/eventgrid.phtml index 6936e9063..20016f9f4 100644 --- a/modules/monitoring/application/views/scripts/list/eventgrid.phtml +++ b/modules/monitoring/application/views/scripts/list/eventgrid.phtml @@ -75,7 +75,7 @@ foreach ($summary as $entry) { $caption = sprintf( $settings[$column]['tooltip'], $value, - $this->dateFormat()->formatDate(strtotime($day)) + $this->formatDate(strtotime($day)) ); $linkFilter = Filter::matchAll( Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')), diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index 9ab581d59..491dee8ff 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -85,7 +85,7 @@ if (count($history) === 0) { escape($title); ?>
- timestamp); ?> + timeAgo($event->timestamp, $this->compact); ?>
diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 23d031b3f..f1a3e2004 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -60,7 +60,7 @@ if (count($hostgroups) === 0) {
- prefixedTimeSince($lastStateChange); ?> + timeSince($lastStateChange, $this->compact); ?>
qlink( diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index a83f3bb8a..5535d14fa 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -40,13 +40,14 @@ if (count($hosts) === 0) {
- host_state, true); ?>
+ host_state, true); ?> host_state !== 99): ?> - prefixedTimeSince($host->host_last_state_change, true) ?> - host_state > 0 && (int) $host->host_state_type === 0): ?> -
- Soft host_attempt ?> - +
+ timeSince($host->host_last_state_change, $this->compact) ?> + host_state > 0 && (int) $host->host_state_type === 0): ?> +
+ Soft host_attempt ?> +
- dateTimeRenderer($notification->notification_start_time)->render( - $this->translate('on %s', 'datetime'), - $this->translate('at %s', 'time'), - $this->translate('%s ago', 'timespan') - ) ?> + timeAgo($notification->notification_start_time, $this->compact) ?> diff --git a/modules/monitoring/application/views/scripts/list/servicegroups.phtml b/modules/monitoring/application/views/scripts/list/servicegroups.phtml index 9fb8d0e08..ba160af42 100644 --- a/modules/monitoring/application/views/scripts/list/servicegroups.phtml +++ b/modules/monitoring/application/views/scripts/list/servicegroups.phtml @@ -29,49 +29,49 @@ if (count($servicegroups) === 0) { translate('CRITICAL'); ?>
- prefixedTimeSince($s->services_critical_last_state_change_unhandled); ?> + timeSince($s->services_critical_last_state_change_unhandled); ?>
translate('UNKNOWN'); ?>
- prefixedTimeSince($s->services_unknown_last_state_change_unhandled); ?> + timeSince($s->services_unknown_last_state_change_unhandled); ?>
translate('WARNING'); ?>
- prefixedTimeSince($s->services_warning_last_state_change_unhandled); ?> + timeSince($s->services_warning_last_state_change_unhandled); ?>
translate('CRITICAL'); ?>
- prefixedTimeSince($s->services_critical_last_state_change_handled); ?> + timeSince($s->services_critical_last_state_change_handled); ?>
translate('UNKNOWN'); ?>
- prefixedTimeSince($s->services_unknown_last_state_change_handled); ?> + timeSince($s->services_unknown_last_state_change_handled); ?>
translate('WARNING'); ?>
- prefixedTimeSince($s->services_warning_last_state_change_handled); ?> + timeSince($s->services_warning_last_state_change_handled); ?>
translate('OK'); ?>
- prefixedTimeSince($s->services_ok_last_state_change); ?> + timeSince($s->services_ok_last_state_change); ?>
translate('PENDING'); ?>
- prefixedTimeSince($s->services_pending_last_state_change); ?> + timeSince($s->services_pending_last_state_change); ?>
diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 964a0e982..9f87e7c60 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -48,12 +48,15 @@ if (count($services) === 0) { ?>
- service_state, true); ?>
- compact): ?>prefixedTimeSince($service->service_last_state_change); ?>timeSince($service->service_last_state_change); ?> - service_state > 0 && (int) $service->service_state_type === 0): ?> -
- Soft service_attempt ?> - + service_state, true); ?> + service_state !== 99): ?> +
+ timeSince($service->service_last_state_change, $this->compact) ?> + service_state > 0 && (int) $service->service_state_type === 0): ?> +
+ Soft service_attempt ?> + +
diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml index 2c5f07133..87a7308fc 100644 --- a/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml @@ -24,4 +24,4 @@ ?> escape($title); ?>
icon($icon, $tooltip) ?> -prefixedTimeSince($comment->timestamp); ?> +timeAgo($comment->timestamp, $this->compact); ?> diff --git a/modules/monitoring/application/views/scripts/partials/downtime/downtime-header.phtml b/modules/monitoring/application/views/scripts/partials/downtime/downtime-header.phtml index 92759a12a..85bd06b5c 100644 --- a/modules/monitoring/application/views/scripts/partials/downtime/downtime-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/downtime/downtime-header.phtml @@ -3,16 +3,7 @@
is_in_effect ? $this->translate('Expires') : $this->translate('Starts'); ?>
- dateTimeRenderer( - ($downtime->is_in_effect ? $downtime->end : $downtime->start), - true - )->render( - $this->translate('on %s', 'datetime'), - $this->translate('at %s', 'time'), - $this->translate('in %s', 'timespan') - ); - ?> + timeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start, $this->compact) ?>
@@ -22,20 +13,20 @@ $this->isService ? $this->translate('This flexible service downtime was started on %s at %s and lasts for %s until %s at %s.') : $this->translate('This flexible host downtime was started on %s at %s and lasts for %s until %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - $this->format()->duration($downtime->duration), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDuration($downtime->duration), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> isService ? $this->translate('This flexible service downtime has been scheduled to start between %s - %s and to last for %s.') : $this->translate('This flexible host downtime has been scheduled to start between %s - %s and to last for %s.'), - date('d.m.y H:i', $downtime->scheduled_start), - date('d.m.y H:i', $downtime->scheduled_end), - $this->format()->duration($downtime->duration) + $this->formatDateTime($downtime->scheduled_start), + $this->formatDateTime($downtime->scheduled_end), + $this->formatDuration($downtime->duration) ); ?> @@ -44,20 +35,20 @@ $this->isService ? $this->translate('This fixed service downtime was started on %s at %s and expires on %s at %s.') : $this->translate('This fixed host downtime was started on %s at %s and expires on %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> isService ? $this->translate('This fixed service downtime has been scheduled to start on %s at %s and to end on %s at %s.') : $this->translate('This fixed host downtime has been scheduled to start on %s at %s and to end on %s at %s.'), - date('d.m.y', $downtime->scheduled_start), - date('H:i', $downtime->scheduled_start), - date('d.m.y', $downtime->scheduled_end), - date('H:i', $downtime->scheduled_end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> diff --git a/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml b/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml index 5518e5022..d3dc665a9 100644 --- a/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml @@ -8,16 +8,7 @@ is_in_effect ? $this->translate('Expires') : $this->translate('Starts'); ?>
- dateTimeRenderer( - ($downtime->is_in_effect ? $downtime->end : $downtime->start), - true - )->render( - $this->translate('on %s', 'datetime'), - $this->translate('at %s', 'time'), - $this->translate('in %s', 'timespan') - ); - ?> + timeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start, $this->compact) ?>
isService): ?> @@ -27,27 +18,27 @@ icon('host', $this->translate('Host')) ?> host_name ?>. - + is_flexible): ?> is_in_effect): ?> isService ? $this->translate('This flexible service downtime was started on %s at %s and lasts for %s until %s at %s.') : $this->translate('This flexible host downtime was started on %s at %s and lasts for %s until %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - $this->format()->duration($downtime->duration), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDuration($downtime->duration), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> isService ? $this->translate('This flexible service downtime has been scheduled to start between %s - %s and to last for %s.') : $this->translate('This flexible host downtime has been scheduled to start between %s - %s and to last for %s.'), - date('d.m.y H:i', $downtime->scheduled_start), - date('d.m.y H:i', $downtime->scheduled_end), - $this->format()->duration($downtime->duration) + $this->formatDateTime($downtime->scheduled_start), + $this->formatDateTime($downtime->scheduled_end), + $this->formatDuration($downtime->duration) ); ?> @@ -56,20 +47,20 @@ $this->isService ? $this->translate('This fixed service downtime was started on %s at %s and expires on %s at %s.') : $this->translate('This fixed host downtime was started on %s at %s and expires on %s at %s.'), - date('d.m.y', $downtime->start), - date('H:i', $downtime->start), - date('d.m.y', $downtime->end), - date('H:i', $downtime->end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> isService ? $this->translate('This fixed service downtime has been scheduled to start on %s at %s and to end on %s at %s.') : $this->translate('This fixed host downtime has been scheduled to start on %s at %s and to end on %s at %s.'), - date('d.m.y', $downtime->scheduled_start), - date('H:i', $downtime->scheduled_start), - date('d.m.y', $downtime->scheduled_end), - date('H:i', $downtime->scheduled_end) + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) ); ?> @@ -91,4 +82,4 @@ ) ) ?> -

\ No newline at end of file +

diff --git a/modules/monitoring/application/views/scripts/partials/host/object-header.phtml b/modules/monitoring/application/views/scripts/partials/host/object-header.phtml index ed7edae79..1a2fc356d 100644 --- a/modules/monitoring/application/views/scripts/partials/host/object-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/host/object-header.phtml @@ -6,7 +6,7 @@ use Icinga\Module\Monitoring\Object\Host;
host_state, true); ?>
- prefixedTimeSince($object->host_last_state_change, true); ?> + timeSince($object->host_last_state_change); ?>
iconImage()->host($object) ?> diff --git a/modules/monitoring/application/views/scripts/partials/service/object-header.phtml b/modules/monitoring/application/views/scripts/partials/service/object-header.phtml index c6dbb4730..c3df4044b 100644 --- a/modules/monitoring/application/views/scripts/partials/service/object-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/service/object-header.phtml @@ -7,7 +7,7 @@ use Icinga\Module\Monitoring\Object\Service;
host_state, true); ?>
- prefixedTimeSince($object->host_last_state_change, true); ?> + timeSince($object->host_last_state_change) ?>
iconImage()->service($object) ?> @@ -25,7 +25,7 @@ use Icinga\Module\Monitoring\Object\Service;
service_state, true); ?>
- prefixedTimeSince($object->service_last_state_change, true); ?> + timeSince($object->service_last_state_change) ?>
iconImage()->host($object) ?> diff --git a/modules/monitoring/application/views/scripts/process/info.phtml b/modules/monitoring/application/views/scripts/process/info.phtml index 5ebecce4d..85e576116 100644 --- a/modules/monitoring/application/views/scripts/process/info.phtml +++ b/modules/monitoring/application/views/scripts/process/info.phtml @@ -27,15 +27,15 @@ if (! $this->compact): ?>
translate('Program Start Time') ?>dateFormat()->formatDateTime($this->programStatus->program_start_time) ?>formatDateTime($this->programStatus->program_start_time) ?>
translate('Last Status Update'); ?>translate('%s ago'), $this->timeSince($this->programStatus->status_update_time)); ?>timeAgo($this->programStatus->status_update_time); ?>
translate('Last External Command Check'); ?>translate('%s ago'), $this->timeSince($this->programStatus->last_command_check)); ?>timeAgo($this->programStatus->last_command_check); ?>
translate('Last Log File Rotation'); ?>
escape($comment->author); ?> (timeSince($comment->timestamp); ?>)escape($comment->author); ?> (timeAgo($comment->timestamp); ?>) downtimes as $downtime) { ) : $this->escape($downtime->comment); if ((bool) $downtime->is_in_effect) { - $state = 'in downtime since '; - $time = $this->timeSince($downtime->start); + $state = sprintf( + $this->translate('in downtime %s', 'Last format parameter represents the time in downtime'), + $this->timeSince($downtime->start) + ); } else { if ((bool) $downtime->is_fixed) { - $state = 'scheduled '; - $time = $this->timeUntil($downtime->start); + $state = sprintf( + $this->translate('scheduled %s', 'Last format parameter represents the time scheduled'), + $this->timeUntil($downtime->start) + ); } else { - $state = 'scheduled flexible '; - $time = $this->timeUntil($downtime->start); + $state = sprintf( + $this->translate('scheduled flexible %s', 'Last format parameter represents the time scheduled'), + $this->timeUntil($downtime->start) + ); } } ?>
escape($downtime->author_name); ?>escape($downtime->author_name); ?> (timeAgo($downtime->entry_time); ?>) downtimes as $downtime) { ); echo $delDowntimeForm; } ?> - translate('Downtime'); ?> - qlink( - $state, - 'monitoring/downtime/show', - array('downtime_id' => $downtime->id), - array('data-base-target' => '_next') - ) . $time ; ?> - ', $commentText); ?> + translate('Downtime'); ?> - ', $commentText); ?>
translate('Notifications') ?> - hasPermission('monitoring/command/send-custom-notification')) { - if ($object->getType() === $object::TYPE_HOST) { - $ackLink = $this->href( - 'monitoring/host/send-custom-notification', - array('host' => $object->getName()) - ); - } else { - $ackLink = $this->href( - 'monitoring/service/send-custom-notification', - array('host' => $object->getHost()->getName(), 'service' => $object->getName()) - ); - } - ?> - qlink( - $this->translate('Send notification'), - $ackLink, - null, - array( - 'icon' => 'bell', - 'data-base-target' => '_self', - 'title' => $this->translate( - 'Send a custom notification, share information about the' - . ' object to contacts.' - ) - ) - ) ?>
- -state, array(0, 99))) { - - if ($object->current_notification_number > 0) { - if ((int) $object->current_notification_number === 1) { - $msg = sprintf( - $this->translate('A notication has been sent for this issue %s ago'), - $this->timeSince($object->last_notification) - ); - } else { - $msg = sprintf( - $this->translate('%s notications have been sent for this issue'), - $object->current_notification_number - ) . '
' . sprintf( - $this->translate('The last one occured %s ago'), - $this->timeSince($object->last_notification) - ); +
translate('Notifications') ?> + hasPermission('monitoring/command/send-custom-notification')) { + if ($object->getType() === $object::TYPE_HOST) { + /** @var \Icinga\Module\Monitoring\Object\Host $object */ + echo $this->qlink( + $this->translate('Send notification'), + 'monitoring/host/send-custom-notification', + array('host_name' => $object->getName()), + array( + 'icon' => 'bell', + 'data-base-target' => '_self', + 'title' => $this->translate( + 'Send a custom notification to contacts responsible for this host' + ) + ) + ); + } else { + /** @var \Icinga\Module\Monitoring\Object\Service $object */ + echo $this->qlink( + $this->translate('Send notification'), + 'monitoring/service/send-custom-notification', + array('host_name' => $object->getHost()->getName(), 'service_description' => $object->getName()), + array( + 'icon' => 'bell', + 'data-base-target' => '_self', + 'title' => $this->translate( + 'Send a custom notification to contacts responsible for this service' + ) + ) + ); + } + if (! in_array((int) $object->state, array(0, 99))) { + echo '
'; + } + } elseif (in_array((int) $object->state, array(0, 99))) { + echo '-'; } - echo $msg; - } else { - echo '(' - . $this->translate('No notification has been sent for this issue') - . ')'; - } -} -?> -