Merge branch 'master' into feature/setup-wizard-7163

This commit is contained in:
Johannes Meyer 2014-10-30 10:38:21 +01:00
commit c1bff9a26e
55 changed files with 720 additions and 411 deletions

View File

@ -161,7 +161,6 @@ class AuthenticationController extends ActionController
$isRemoteUser = $auth->getUser()->isRemoteUser(); $isRemoteUser = $auth->getUser()->isRemoteUser();
$auth->removeAuthorization(); $auth->removeAuthorization();
if ($isRemoteUser === true) { if ($isRemoteUser === true) {
$this->_helper->layout->setLayout('login');
$this->_response->setHttpResponseCode(401); $this->_response->setHttpResponseCode(401);
} else { } else {
$this->redirectToLogin(); $this->redirectToLogin();

View File

@ -19,7 +19,7 @@ class IndexController extends ActionController
public function preDispatch() public function preDispatch()
{ {
if ($this->getRequest()->getActionName() !== 'welcome') { if ($this->getRequest()->getActionName() !== 'welcome') {
$this->redirectNow('dashboard'); $this->redirectNow(Url::fromRequest()->setPath('dashboard'));
} }
} }

View File

@ -6,14 +6,15 @@ namespace Icinga\Form;
use Exception; use Exception;
use DateTimeZone; use DateTimeZone;
use Icinga\Web\Form; use Icinga\Logger\Logger;
use Icinga\Web\Request;
use Icinga\Web\Session;
use Icinga\Web\Notification;
use Icinga\Util\Translator;
use Icinga\Util\TimezoneDetect;
use Icinga\User\Preferences; use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore; use Icinga\User\Preferences\PreferencesStore;
use Icinga\Util\TimezoneDetect;
use Icinga\Util\Translator;
use Icinga\Web\Form;
use Icinga\Web\Notification;
use Icinga\Web\Request;
use Icinga\Web\Session;
/** /**
* Form class to adjust user preferences * Form class to adjust user preferences
@ -105,6 +106,7 @@ class PreferenceForm extends Form
$this->save(); $this->save();
Notification::success(t('Preferences successfully saved')); Notification::success(t('Preferences successfully saved'));
} catch (Exception $e) { } catch (Exception $e) {
Logger::error($e);
Notification::error($e->getMessage()); Notification::error($e->getMessage());
} }
} }

View File

@ -29,7 +29,7 @@ $iframeClass = $isIframe ? ' iframe' : '';
<title><?= $this->title ? $this->escape($this->title) : 'Icinga Web' ?></title> <title><?= $this->title ? $this->escape($this->title) : 'Icinga Web' ?></title>
<!-- TODO: viewport and scale settings make no sense for us, fix this --> <!-- TODO: viewport and scale settings make no sense for us, fix this -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<? if ($isIframe): ?> <?php if ($isIframe): ?>
<base target="_parent"/> <base target="_parent"/>
<?php else: ?> <?php else: ?>
<script type="text/javascript"> <script type="text/javascript">
@ -52,7 +52,6 @@ $iframeClass = $isIframe ? ' iframe' : '';
<div id="layout" class="default-layout"> <div id="layout" class="default-layout">
<?= $this->render('body.phtml') ?> <?= $this->render('body.phtml') ?>
</div> </div>
<?php if (! $isIframe): ?>
<!--[if IE 8]> <!--[if IE 8]>
<script type="text/javascript" src="<?= $this->href($ie8jsfile) ?>"></script> <script type="text/javascript" src="<?= $this->href($ie8jsfile) ?>"></script>
<![endif]--> <![endif]-->
@ -64,6 +63,5 @@ var icinga = new Icinga({
baseUrl: '<?= $this->href('/') ?>' baseUrl: '<?= $this->href('/') ?>'
}); });
</script> </script>
<?php endif ?>
</body> </body>
</html> </html>

View File

@ -4,7 +4,7 @@
<div class="content"> <div class="content">
<?php if (! $module): ?> <?php if (! $module): ?>
<?= $this->translate('There is no such module installed.') ?> <?= $this->translate('There is no such module installed.') ?>
<? return; endif ?> <?php return; endif ?>
<?php <?php
$dependencies = $module->getDependencies(); $dependencies = $module->getDependencies();
$restrictions = $module->getProvidedRestrictions(); $restrictions = $module->getProvidedRestrictions();

View File

@ -14,7 +14,7 @@
<?= $this->icon('success.png', $this->translate('Module is enabled')) ?> <?= $this->icon('success.png', $this->translate('Module is enabled')) ?>
<?php else: ?> <?php else: ?>
<?= $this->icon('remove.png', $this->translate('Module is disabled')) ?> <?= $this->icon('remove.png', $this->translate('Module is disabled')) ?>
<? endif ?> <?php endif ?>
<a href="<?= $this->url( <a href="<?= $this->url(
'config/module/', 'config/module/',
array('name' => $module->name) array('name' => $module->name)
@ -23,7 +23,7 @@
?>) ?>)
</td> </td>
</tr> </tr>
<? endforeach ?> <?php endforeach ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -263,7 +263,7 @@ select.input-sm {
.pagination > .active > span:focus { .pagination > .active > span:focus {
background-color: #049baf !important; background-color: #049baf !important;
border-color: fuchsia !mportant; border-color: fuchsia !important;
} }
@ -682,7 +682,7 @@ ul.icinga-subnavigation {
.nav-stacked > li > a:hover, .nav-stacked > li > a:hover,
.icinga-subnavigation > li > a:focus { .icinga-subnavigation > li > a:focus {
/* font-weight: bold;*/ /* font-weight: bold;*/
background-color: transparent; !important; background-color: transparent !important;
display: inline-block; display: inline-block;
} }
@ -781,7 +781,6 @@ background-color: #fff;
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
padding-top: 0; padding-top: 0;
padding-bottom;
margin-left: 2px; margin-left: 2px;
margin-top: -8px; margin-top: -8px;
} }

View File

@ -0,0 +1,35 @@
CREATE TABLE `icingaweb_group`(
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`parent` varchar(64) COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`ctime` timestamp NULL DEFAULT NULL,
`mtime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `icingaweb_group_membership`(
`group_name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`username` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`ctime` timestamp NULL DEFAULT NULL,
`mtime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`group_name`,`username`),
CONSTRAINT `fk_icingaweb_group_membership_icingaweb_group` FOREIGN KEY (`group_name`)
REFERENCES `icingaweb_group` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `icingaweb_user`(
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`active` tinyint(1) NOT NULL,
`password_hash` varbinary(255) NOT NULL,
`ctime` timestamp NULL DEFAULT NULL,
`mtime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `icingaweb_user_preference`(
`username` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`value` varchar(255) NOT NULL,
`ctime` timestamp NULL DEFAULT NULL,
`mtime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`username`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -6,6 +6,7 @@ namespace Icinga\Authentication;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
use Icinga\User;
use Icinga\Util\String; use Icinga\Util\String;
/** /**
@ -14,73 +15,97 @@ use Icinga\Util\String;
class AdmissionLoader class AdmissionLoader
{ {
/** /**
* Match against groups
*
* @param string $section
* @param string $username * @param string $username
* @param array $groups * @param array $userGroups
* @param mixed $section
* *
* @return bool * @return bool
*/ */
private function match($section, $username, array $groups) protected function match($username, $userGroups, $section)
{ {
if ($section->users && in_array($username, String::trimSplit($section->users)) === true) { $username = strtolower($username);
if (! empty($section->users)) {
$users = array_map('strtolower', String::trimSplit($section->users));
if (in_array($username, $users)) {
return true; return true;
} }
}
if ($section->groups && count(array_intersect(String::trimSplit($section->groups), $groups)) > 0) { if (! empty($section->groups)) {
$groups = array_map('strtolower', String::trimSplit($section->groups));
foreach ($userGroups as $userGroup) {
if (in_array(strtolower($userGroup), $groups)) {
return true; return true;
} }
}
}
return false; return false;
} }
/** /**
* Retrieve permissions * Get user permissions
* *
* @param string $username * @param User $user
* @param array $groups
* *
* @return array * @return array
*/ */
public function getPermissions($username, array $groups) public function getPermissions(User $user)
{ {
$permissions = array(); $permissions = array();
try { try {
$config = Config::app('permissions'); $config = Config::app('permissions');
} catch (NotReadableError $e) { } catch (NotReadableError $e) {
Logger::error(
'Can\'t get permissions for user \'%s\'. An exception was thrown:',
$user->getUsername(),
$e
);
return $permissions; return $permissions;
} }
$username = $user->getUsername();
$userGroups = $user->getGroups();
foreach ($config as $section) { foreach ($config as $section) {
if ($this->match($section, $username, $groups) && isset($section->permissions)) { if (! empty($section->permissions)
$permissions += String::trimSplit($section->permissions); && $this->match($username, $userGroups, $section)
) {
$permissions = array_merge(
$permissions,
array_diff(String::trimSplit($section->permissions), $permissions)
);
} }
} }
return $permissions; return $permissions;
} }
/** /**
* Retrieve restrictions * Get user restrictions
* *
* @param $username * @param User $user
* @param array $groups
* *
* @return array * @return array
*/ */
public function getRestrictions($username, array $groups) public function getRestrictions(User $user)
{ {
$restrictions = array(); $restrictions = array();
try { try {
$config = Config::app('restrictions'); $config = Config::app('restrictions');
} catch (NotReadableError $e) { } catch (NotReadableError $e) {
Logger::error(
'Can\'t get restrictions for user \'%s\'. An exception was thrown:',
$user->getUsername(),
$e
);
return $restrictions; return $restrictions;
} }
foreach ($config as $name => $section) { $username = $user->getUsername();
if ($this->match($section, $username, $groups)) { $userGroups = $user->getGroups();
if (!array_key_exists($section->name, $restrictions)) { foreach ($config as $section) {
$restrictions[$section->name] = array(); if (! empty($section->restriction)
} && $this->match($username, $userGroups, $section)
$restrictions[$section->name][$name] = $section->restriction; ) {
$restrictions = array_merge(
$restrictions,
array_diff(String::trimSplit($section->restriction), $restrictions)
);
} }
} }
return $restrictions; return $restrictions;

View File

@ -0,0 +1,63 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Authentication\Backend;
use Icinga\Authentication\UserGroupBackend;
use Icinga\Data\Db\DbConnection;
use Icinga\User;
/**
* Database user group backend
*/
class DbUserGroupBackend extends UserGroupBackend
{
/**
* Connection to the database
*
* @var DbConnection
*/
private $conn;
/**
* Create a new database user group backend
*
* @param DbConnection $conn
*/
public function __construct(DbConnection $conn)
{
$this->conn = $conn;
}
/**
* (non-PHPDoc)
* @see UserGroupBackend::getMemberships() For the method documentation.
*/
public function getMemberships(User $user)
{
$groups = array();
$groupsStmt = $this->conn->getDbAdapter()
->select()
->from($this->conn->getTablePrefix() . 'group', array('name', 'parent'))
->query();
foreach ($groupsStmt as $group) {
$groups[$group->name] = $group->parent;
}
$memberships = array();
$membershipsStmt = $this->conn->getDbAdapter()
->select()
->from($this->conn->getTablePrefix() . 'group_membership', array('group_name'))
->where('username = ?', $user->getUsername())
->query();
foreach ($membershipsStmt as $membership) {
$memberships[] = $membership->group_name;
$parent = $groups[$membership->group_name];
while (isset($parent)) {
$memberships[] = $parent;
$parent = $groups[$parent];
}
}
return $memberships;
}
}

View File

@ -0,0 +1,65 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Authentication\Backend;
use Icinga\Application\Config;
use Icinga\Authentication\UserGroupBackend;
use Icinga\Exception\ConfigurationError;
use Icinga\User;
use Icinga\Util\String;
/**
* INI user group backend
*/
class IniUserGroupBackend extends UserGroupBackend
{
/**
* Config
*
* @var Config
*/
private $config;
/**
* Create a new INI user group backend
*
* @param Config $config
*/
public function __construct(Config $config)
{
$this->config = $config;
}
/**
* (non-PHPDoc)
* @see UserGroupBackend::getMemberships() For the method documentation.
*/
public function getMemberships(User $user)
{
$username = strtolower($user->getUsername());
$groups = array();
foreach ($this->config as $name => $section) {
if (empty($section->users)) {
throw new ConfigurationError(
'Membership section \'%s\' in \'%s\' is missing the \'users\' section',
$name,
$this->config->getConfigFile()
);
}
if (empty($section->groups)) {
throw new ConfigurationError(
'Membership section \'%s\' in \'%s\' is missing the \'groups\' section',
$name,
$this->config->getConfigFile()
);
}
$users = array_map('strtolower', String::trimSplit($section->users));
if (in_array($username, $users)) {
$groups = array_merge($groups, array_diff(String::trimSplit($section->groups), $groups));
}
}
return $groups;
}
}

View File

@ -184,7 +184,10 @@ class LdapUserBackend extends UserBackend
$password $password
); );
if ($authenticated) { if ($authenticated) {
$user->setGroups($this->getGroups($userDn)); $groups = $this->getGroups($userDn);
if ($groups !== null) {
$user->setGroups($groups);
}
} }
return $authenticated; return $authenticated;
} catch (LdapException $e) { } catch (LdapException $e) {

View File

@ -6,14 +6,14 @@ namespace Icinga\Authentication;
use Exception; use Exception;
use Zend_Config; use Zend_Config;
use Icinga\User; use Icinga\Application\Config;
use Icinga\Web\Session; use Icinga\Exception\IcingaException;
use Icinga\Logger\Logger;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
use Icinga\Application\Config as IcingaConfig; use Icinga\Logger\Logger;
use Icinga\User;
use Icinga\User\Preferences; use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore; use Icinga\User\Preferences\PreferencesStore;
use Icinga\Exception\IcingaException; use Icinga\Web\Session;
class Manager class Manager
{ {
@ -53,7 +53,7 @@ class Manager
{ {
$username = $user->getUsername(); $username = $user->getUsername();
try { try {
$config = IcingaConfig::app(); $config = Config::app();
} catch (NotReadableError $e) { } catch (NotReadableError $e) {
Logger::error( Logger::error(
new IcingaException( new IcingaException(
@ -85,18 +85,32 @@ class Manager
$preferences = new Preferences(); $preferences = new Preferences();
} }
$user->setPreferences($preferences); $user->setPreferences($preferences);
$membership = new Membership(); $groups = array();
$groups = $membership->getGroupsByUsername($username); foreach (Config::app('groups') as $name => $config) {
try {
$groupBackend = UserGroupBackend::create($name, $config);
$groupsFromBackend = $groupBackend->getMemberships($user);
} catch (Exception $e) {
Logger::error(
'Can\'t get group memberships for user \'%s\' from backend \'%s\'. An exception was thrown:',
$username,
$name,
$e
);
continue;
}
if (empty($groupsFromBackend)) {
continue;
}
$groupsFromBackend = array_values($groupsFromBackend);
$groups = array_merge($groups, array_combine($groupsFromBackend, $groupsFromBackend));
}
$user->setGroups($groups); $user->setGroups($groups);
$admissionLoader = new AdmissionLoader(); $admissionLoader = new AdmissionLoader();
$user->setPermissions( $user->setPermissions($admissionLoader->getPermissions($user));
$admissionLoader->getPermissions($username, $groups) $user->setRestrictions($admissionLoader->getRestrictions($user));
);
$user->setRestrictions(
$admissionLoader->getRestrictions($username, $groups)
);
$this->user = $user; $this->user = $user;
if ($persist == true) { if ($persist) {
$this->persistCurrentUser(); $this->persistCurrentUser();
} }
} }

View File

@ -1,39 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}}
namespace Icinga\Authentication;
use Icinga\Application\Config;
use Icinga\Exception\NotReadableError;
use Icinga\Util\String;
/**
* Retrieve membership information for users and group
*/
class Membership
{
/**
* Return a list of groups for an username
*
* @param string $username
*
* @return array
*/
public function getGroupsByUsername($username)
{
$groups = array();
try {
$config = Config::app('memberships');
} catch (NotReadableError $e) {
return $groups;
}
foreach ($config as $section) {
$users = String::trimSplit($section->users);
if (in_array($username, $users)) {
$groups = array_merge($groups, String::trimSplit($section->groups));
}
}
return $groups;
}
}

View File

@ -0,0 +1,113 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}}
namespace Icinga\Authentication;
use Zend_Config;
use Icinga\Authentication\Backend\DbUserGroupBackend;
use Icinga\Authentication\Backend\IniUserGroupBackend;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\IcingaException;
use Icinga\User;
/**
* Base class and factory for user group backends
*/
abstract class UserGroupBackend
{
/**
* Name of the backend
*
* @var string
*/
protected $name;
/**
* Set the backend name
*
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
/**
* Get the backend name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Create a user group backend
*
* @param string $name
* @param Zend_Config $backendConfig
*
* @return DbUserGroupBackend|IniUserGroupBackend
* @throws ConfigurationError If the backend configuration is invalid
*/
public static function create($name, Zend_Config $backendConfig)
{
if ($backendConfig->name !== null) {
$name = $backendConfig->name;
}
if (($backendType = $backendConfig->backend) === null) {
throw new ConfigurationError(
'Configuration for user group backend \'%s\' is missing the \'backend\' directive',
$name
);
}
$backendType = strtolower($backendType);
if (($resourceName = $backendConfig->resource) === null) {
throw new ConfigurationError(
'Configuration for user group backend \'%s\' is missing the \'resource\' directive',
$name
);
}
$resourceName = strtolower($resourceName);
try {
$resource = ResourceFactory::create($resourceName);
} catch (IcingaException $e) {
throw new ConfigurationError(
'Can\'t create user group backend \'%s\'. An exception was thrown: %s',
$resourceName,
$e
);
}
switch ($backendType) {
case 'db':
$backend = new DbUserGroupBackend($resource);
break;
case 'ini':
$backend = new IniUserGroupBackend($resource);
break;
default:
throw new ConfigurationError(
'Can\'t create user group backend \'%s\'. Invalid backend type \'%s\'.',
$name,
$backendType
);
}
$backend->setName($name);
return $backend;
}
/**
* Get the groups the given user is a member of
*
* @param User $user
*
* @return array
*/
abstract public function getMemberships(User $user);
}

View File

@ -64,6 +64,9 @@ class DbConnection implements Selectable
public function __construct(Zend_Config $config = null) public function __construct(Zend_Config $config = null)
{ {
$this->config = $config; $this->config = $config;
if (isset($config->prefix)) {
$this->tablePrefix = $config->prefix;
}
$this->connect(); $this->connect();
} }

View File

@ -4,8 +4,9 @@
namespace Icinga\Data; namespace Icinga\Data;
use Icinga\Exception\ProgrammingError;
use Zend_Config; use Zend_Config;
use Icinga\Application\Config;
use Icinga\Exception\ProgrammingError;
use Icinga\Util\ConfigAwareFactory; use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\DbConnection; use Icinga\Data\Db\DbConnection;
@ -120,6 +121,9 @@ class ResourceFactory implements ConfigAwareFactory
case 'file': case 'file':
$resource = new FileReader($config); $resource = new FileReader($config);
break; break;
case 'ini':
$resource = Config::fromIni($config->ini);
break;
default: default:
throw new ConfigurationError( throw new ConfigurationError(
'Unsupported resource type "%s"', 'Unsupported resource type "%s"',

View File

@ -84,7 +84,8 @@ class Logger
if (($level = $config->level) !== null) { if (($level = $config->level) !== null) {
if (is_numeric($level)) { if (is_numeric($level)) {
if (! isset(static::$levels[(int) $level])) { $level = (int) $level;
if (! isset(static::$levels[$level])) {
throw new ConfigurationError( throw new ConfigurationError(
'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the' 'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the'
. ' Logger\'s constants.', . ' Logger\'s constants.',
@ -92,7 +93,7 @@ class Logger
implode(', ', array_keys(static::$levels)) implode(', ', array_keys(static::$levels))
); );
} }
$this->level = static::$levels[(int) $level]; $this->level = $level;
} else { } else {
$level = strtoupper($level); $level = strtoupper($level);
$levels = array_flip(static::$levels); $levels = array_flip(static::$levels);
@ -155,7 +156,7 @@ class Logger
*/ */
public function log($level, $message) public function log($level, $message)
{ {
if ($this->writer !== null && $this->level >= $level) { if ($this->writer !== null && $this->level <= $level) {
$this->writer->log($level, $message); $this->writer->log($level, $message);
} }
} }

View File

@ -72,9 +72,11 @@ class DbStore extends PreferencesStore
public function load() public function load()
{ {
try { try {
$select = $this->getStoreConfig()->connection->select(); $select = $this->getStoreConfig()->connection->getDbAdapter()->select();
$result = $select->from($this->table, array(self::COLUMN_PREFERENCE, self::COLUMN_VALUE)) $result = $select
->from($this->table, array(self::COLUMN_PREFERENCE, self::COLUMN_VALUE))
->where(self::COLUMN_USERNAME . ' = ?', $this->getUser()->getUsername()) ->where(self::COLUMN_USERNAME . ' = ?', $this->getUser()->getUsername())
->query()
->fetchAll(); ->fetchAll();
} catch (Exception $e) { } catch (Exception $e) {
throw new NotReadableError( throw new NotReadableError(
@ -132,7 +134,7 @@ class DbStore extends PreferencesStore
*/ */
protected function insert(array $preferences) protected function insert(array $preferences)
{ {
$db = $this->getStoreConfig()->connection->getConnection(); $db = $this->getStoreConfig()->connection->getDbAdapter();
try { try {
foreach ($preferences as $key => $value) { foreach ($preferences as $key => $value) {
@ -163,7 +165,7 @@ class DbStore extends PreferencesStore
*/ */
protected function update(array $preferences) protected function update(array $preferences)
{ {
$db = $this->getStoreConfig()->connection->getConnection(); $db = $this->getStoreConfig()->connection->getDbAdapter();
try { try {
foreach ($preferences as $key => $value) { foreach ($preferences as $key => $value) {
@ -194,7 +196,7 @@ class DbStore extends PreferencesStore
*/ */
protected function delete(array $preferenceKeys) protected function delete(array $preferenceKeys)
{ {
$db = $this->getStoreConfig()->connection->getConnection(); $db = $this->getStoreConfig()->connection->getDbAdapter();
try { try {
$db->delete( $db->delete(

View File

@ -342,7 +342,7 @@ class Monitoring_AlertsummaryController extends Controller
$gridChart = new GridChart(); $gridChart = new GridChart();
$gridChart->alignTopLeft(); $gridChart->alignTopLeft();
$gridChart->setAxisLabel('', t('Notifications')) $gridChart->setAxisLabel('', mt('monitoring', 'Notifications'))
->setXAxis(new StaticAxis()) ->setXAxis(new StaticAxis())
->setAxisMin(null, 0) ->setAxisMin(null, 0)
->setYAxis(new LinearUnit(10)); ->setYAxis(new LinearUnit(10));
@ -470,7 +470,7 @@ class Monitoring_AlertsummaryController extends Controller
$gridChart = new GridChart(); $gridChart = new GridChart();
$gridChart->alignTopLeft(); $gridChart->alignTopLeft();
$gridChart->setAxisLabel('', t('Notifications')) $gridChart->setAxisLabel('', mt('monitoring', 'Notifications'))
->setXAxis(new StaticAxis()) ->setXAxis(new StaticAxis())
->setAxisMin(null, 0) ->setAxisMin(null, 0)
->setYAxis(new LinearUnit(10)); ->setYAxis(new LinearUnit(10));
@ -530,12 +530,12 @@ class Monitoring_AlertsummaryController extends Controller
$box = new SelectBox( $box = new SelectBox(
'intervalBox', 'intervalBox',
array( array(
'1d' => t('One day'), '1d' => mt('monitoring', 'One day'),
'1w' => t('One week'), '1w' => mt('monitoring', 'One week'),
'1m' => t('One month'), '1m' => mt('monitoring', 'One month'),
'1y' => t('One year') '1y' => mt('monitoring', 'One year')
), ),
t('Report interval'), mt('monitoring', 'Report interval'),
'interval' 'interval'
); );
$box->applyRequest($this->getRequest()); $box->applyRequest($this->getRequest());

View File

@ -143,35 +143,35 @@ class Monitoring_ChartController extends Controller
} }
$this->view->chart = new GridChart(); $this->view->chart = new GridChart();
$this->view->chart->alignTopLeft(); $this->view->chart->alignTopLeft();
$this->view->chart->setAxisLabel('', t('Services')) $this->view->chart->setAxisLabel('', mt('monitoring', 'Services'))
->setXAxis(new StaticAxis()) ->setXAxis(new StaticAxis())
->setAxisMin(null, 0); ->setAxisMin(null, 0);
$tooltip = t('<b>{title}:</b><br>{value} of {sum} services are {label}'); $tooltip = mt('monitoring', '<b>{title}:</b><br>{value} of {sum} services are {label}');
$this->view->chart->drawBars( $this->view->chart->drawBars(
array( array(
'label' => t('Ok'), 'label' => mt('monitoring', 'Ok'),
'color' => '#44bb77', 'color' => '#44bb77',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $okBars, 'data' => $okBars,
'tooltip' => $tooltip 'tooltip' => $tooltip
), ),
array( array(
'label' => t('Warning'), 'label' => mt('monitoring', 'Warning'),
'color' => '#ffaa44', 'color' => '#ffaa44',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $warningBars, 'data' => $warningBars,
'tooltip' => $tooltip 'tooltip' => $tooltip
), ),
array( array(
'label' => t('Critical'), 'label' => mt('monitoring', 'Critical'),
'color' => '#ff5566', 'color' => '#ff5566',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $critBars, 'data' => $critBars,
'tooltip' => $tooltip 'tooltip' => $tooltip
), ),
array( array(
'label' => t('Unknown'), 'label' => mt('monitoring', 'Unknown'),
'color' => '#dd66ff', 'color' => '#dd66ff',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $unknownBars, 'data' => $unknownBars,
@ -199,29 +199,29 @@ class Monitoring_ChartController extends Controller
$hostgroup->hosts_unreachable_unhandled $hostgroup->hosts_unreachable_unhandled
); );
} }
$tooltip = t('<b>{title}:</b><br> {value} of {sum} hosts are {label}'); $tooltip = mt('monitoring', '<b>{title}:</b><br> {value} of {sum} hosts are {label}');
$this->view->chart = new GridChart(); $this->view->chart = new GridChart();
$this->view->chart->alignTopLeft(); $this->view->chart->alignTopLeft();
$this->view->chart->setAxisLabel('', t('Hosts')) $this->view->chart->setAxisLabel('', mt('monitoring', 'Hosts'))
->setXAxis(new StaticAxis()) ->setXAxis(new StaticAxis())
->setAxisMin(null, 0); ->setAxisMin(null, 0);
$this->view->chart->drawBars( $this->view->chart->drawBars(
array( array(
'label' => t('Up'), 'label' => mt('monitoring', 'Up'),
'color' => '#44bb77', 'color' => '#44bb77',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $upBars, 'data' => $upBars,
'tooltip' => $tooltip 'tooltip' => $tooltip
), ),
array( array(
'label' => t('Down'), 'label' => mt('monitoring', 'Down'),
'color' => '#ff5566', 'color' => '#ff5566',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $downBars, 'data' => $downBars,
'tooltip' => $tooltip 'tooltip' => $tooltip
), ),
array( array(
'label' => t('Unreachable'), 'label' => mt('monitoring', 'Unreachable'),
'color' => '#dd66ff', 'color' => '#dd66ff',
'stack' => 'stack1', 'stack' => 'stack1',
'data' => $unreachableBars, 'data' => $unreachableBars,
@ -248,13 +248,13 @@ class Monitoring_ChartController extends Controller
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'), 'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'),
'labels'=> array( 'labels'=> array(
$query->services_ok . ' Up Services', $query->services_ok . ' Up Services',
$query->services_warning_handled . t(' Warning Services (Handled)'), $query->services_warning_handled . mt('monitoring', ' Warning Services (Handled)'),
$query->services_warning_unhandled . t(' Warning Services (Unhandled)'), $query->services_warning_unhandled . mt('monitoring', ' Warning Services (Unhandled)'),
$query->services_critical_handled . t(' Down Services (Handled)'), $query->services_critical_handled . mt('monitoring', ' Down Services (Handled)'),
$query->services_critical_unhandled . t(' Down Services (Unhandled)'), $query->services_critical_unhandled . mt('monitoring', ' Down Services (Unhandled)'),
$query->services_unknown_handled . t(' Unreachable Services (Handled)'), $query->services_unknown_handled . mt('monitoring', ' Unreachable Services (Handled)'),
$query->services_unknown_unhandled . t(' Unreachable Services (Unhandled)'), $query->services_unknown_unhandled . mt('monitoring', ' Unreachable Services (Unhandled)'),
$query->services_pending . t(' Pending Services') $query->services_pending . mt('monitoring', ' Pending Services')
) )
)); ));
} }
@ -274,12 +274,12 @@ class Monitoring_ChartController extends Controller
), ),
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#E066FF', '#f099FF', '#fefefe'), 'colors' => array('#44bb77', '#ff4444', '#ff0000', '#E066FF', '#f099FF', '#fefefe'),
'labels'=> array( 'labels'=> array(
(int) $query->hosts_up . t(' Up Hosts'), (int) $query->hosts_up . mt('monitoring', ' Up Hosts'),
(int) $query->hosts_down_handled . t(' Down Hosts (Handled)'), (int) $query->hosts_down_handled . mt('monitoring', ' Down Hosts (Handled)'),
(int) $query->hosts_down_unhandled . t(' Down Hosts (Unhandled)'), (int) $query->hosts_down_unhandled . mt('monitoring', ' Down Hosts (Unhandled)'),
(int) $query->hosts_unreachable_handled . t(' Unreachable Hosts (Handled)'), (int) $query->hosts_unreachable_handled . mt('monitoring', ' Unreachable Hosts (Handled)'),
(int) $query->hosts_unreachable_unhandled . t(' Unreachable Hosts (Unhandled)'), (int) $query->hosts_unreachable_unhandled . mt('monitoring', ' Unreachable Hosts (Unhandled)'),
(int) $query->hosts_pending . t(' Pending Hosts') (int) $query->hosts_pending . mt('monitoring', ' Pending Hosts')
) )
), array( ), array(
'data' => array( 'data' => array(
@ -294,14 +294,14 @@ class Monitoring_ChartController extends Controller
), ),
'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'), 'colors' => array('#44bb77', '#ff4444', '#ff0000', '#ffff00', '#ffff33', '#E066FF', '#f099FF', '#fefefe'),
'labels'=> array( 'labels'=> array(
$query->services_ok . t(' Up Services'), $query->services_ok . mt('monitoring', ' Up Services'),
$query->services_warning_handled . t(' Warning Services (Handled)'), $query->services_warning_handled . mt('monitoring', ' Warning Services (Handled)'),
$query->services_warning_unhandled . t(' Warning Services (Unhandled)'), $query->services_warning_unhandled . mt('monitoring', ' Warning Services (Unhandled)'),
$query->services_critical_handled . t(' Down Services (Handled)'), $query->services_critical_handled . mt('monitoring', ' Down Services (Handled)'),
$query->services_critical_unhandled . t(' Down Services (Unhandled)'), $query->services_critical_unhandled . mt('monitoring', ' Down Services (Unhandled)'),
$query->services_unknown_handled . t(' Unreachable Services (Handled)'), $query->services_unknown_handled . mt('monitoring', ' Unreachable Services (Handled)'),
$query->services_unknown_unhandled . t(' Unreachable Services (Unhandled)'), $query->services_unknown_unhandled . mt('monitoring', ' Unreachable Services (Unhandled)'),
$query->services_pending . t(' Pending Services') $query->services_pending . mt('monitoring', ' Pending Services')
) )
)); ));
} }

View File

@ -73,7 +73,7 @@ class Monitoring_ConfigController extends ModuleActionController
} }
if ($configForm->save()) { if ($configForm->save()) {
Notification::success(sprintf(t('Backend "%s" successfully removed.'), $backendName)); Notification::success(sprintf(mt('monitoring', 'Backend "%s" successfully removed.'), $backendName));
} else { } else {
return false; return false;
} }
@ -105,7 +105,7 @@ class Monitoring_ConfigController extends ModuleActionController
} }
if ($configForm->save()) { if ($configForm->save()) {
Notification::success(sprintf(t('Instance "%s" successfully removed.'), $instanceName)); Notification::success(sprintf(mt('monitoring', 'Instance "%s" successfully removed.'), $instanceName));
} else { } else {
return false; return false;
} }

View File

@ -46,7 +46,7 @@ class Monitoring_HostsController extends Controller
$this->getTabs()->add( $this->getTabs()->add(
'show', 'show',
array( array(
'title' => t('Hosts'), 'title' => mt('monitoring', 'Hosts'),
'url' => Url::fromRequest() 'url' => Url::fromRequest()
) )
)->activate('show'); )->activate('show');

View File

@ -395,10 +395,10 @@ class Monitoring_ListController extends Controller
$orientationBox = new SelectBox( $orientationBox = new SelectBox(
'orientation', 'orientation',
array( array(
'0' => t('Vertical'), '0' => mt('monitoring', 'Vertical'),
'1' => t('Horizontal') '1' => mt('monitoring', 'Horizontal')
), ),
t('Orientation'), mt('monitoring', 'Orientation'),
'horizontal' 'horizontal'
); );
$orientationBox->applyRequest($this->getRequest()); $orientationBox->applyRequest($this->getRequest());

View File

@ -54,7 +54,7 @@ class Monitoring_MultiController extends Controller
$this->view->pie = $this->createPie( $this->view->pie = $this->createPie(
$this->view->states, $this->view->states,
$this->view->getHelper('MonitoringState')->getHostStateColors(), $this->view->getHelper('MonitoringState')->getHostStateColors(),
t('Host State') mt('monitoring', 'Host State')
); );
// Handle configuration changes // Handle configuration changes
@ -117,12 +117,12 @@ class Monitoring_MultiController extends Controller
$this->view->service_pie = $this->createPie( $this->view->service_pie = $this->createPie(
$this->view->service_states, $this->view->service_states,
$this->view->getHelper('MonitoringState')->getServiceStateColors(), $this->view->getHelper('MonitoringState')->getServiceStateColors(),
t('Service State') mt('monitoring', 'Service State')
); );
$this->view->host_pie = $this->createPie( $this->view->host_pie = $this->createPie(
$this->view->host_states, $this->view->host_states,
$this->view->getHelper('MonitoringState')->getHostStateColors(), $this->view->getHelper('MonitoringState')->getHostStateColors(),
t('Host State') mt('monitoring', 'Host State')
); );
$this->view->errors = $errors; $this->view->errors = $errors;

View File

@ -46,7 +46,7 @@ class Monitoring_ServicesController extends Controller
$this->getTabs()->add( $this->getTabs()->add(
'show', 'show',
array( array(
'title' => t('Services'), 'title' => mt('monitoring', 'Services'),
'url' => Url::fromRequest() 'url' => Url::fromRequest()
) )
)->activate('show'); )->activate('show');

View File

@ -35,32 +35,32 @@ class Monitoring_TimelineController extends Controller
array( array(
'notify' => array( 'notify' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Notifications'), 'label' => mt('monitoring', 'Notifications'),
'color' => '#3a71ea' 'color' => '#3a71ea'
), ),
'hard_state' => array( 'hard_state' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Hard state changes'), 'label' => mt('monitoring', 'Hard state changes'),
'color' => '#ff7000' 'color' => '#ff7000'
), ),
'comment' => array( 'comment' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Comments'), 'label' => mt('monitoring', 'Comments'),
'color' => '#79bdba' 'color' => '#79bdba'
), ),
'ack' => array( 'ack' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Acknowledgements'), 'label' => mt('monitoring', 'Acknowledgements'),
'color' => '#a2721d' 'color' => '#a2721d'
), ),
'dt_start' => array( 'dt_start' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Started downtimes'), 'label' => mt('monitoring', 'Started downtimes'),
'color' => '#8e8e8e' 'color' => '#8e8e8e'
), ),
'dt_end' => array( 'dt_end' => array(
'detailUrl' => $detailUrl, 'detailUrl' => $detailUrl,
'label' => t('Ended downtimes'), 'label' => mt('monitoring', 'Ended downtimes'),
'color' => '#d5d6ad' 'color' => '#d5d6ad'
) )
) )
@ -88,13 +88,13 @@ class Monitoring_TimelineController extends Controller
$box = new SelectBox( $box = new SelectBox(
'intervalBox', 'intervalBox',
array( array(
'4h' => t('4 Hours'), '4h' => mt('monitoring', '4 Hours'),
'1d' => t('One day'), '1d' => mt('monitoring', 'One day'),
'1w' => t('One week'), '1w' => mt('monitoring', 'One week'),
'1m' => t('One month'), '1m' => mt('monitoring', 'One month'),
'1y' => t('One year') '1y' => mt('monitoring', 'One year')
), ),
t('TimeLine interval'), mt('monitoring', 'TimeLine interval'),
'interval' 'interval'
); );
$box->applyRequest($this->getRequest()); $box->applyRequest($this->getRequest());

View File

@ -29,7 +29,7 @@ class BackendConfigForm extends ConfigForm
public function init() public function init()
{ {
$this->setName('form_config_monitoring_backends'); $this->setName('form_config_monitoring_backends');
$this->setSubmitLabel(t('Save Changes')); $this->setSubmitLabel(mt('monitoring', 'Save Changes'));
} }
/** /**
@ -51,7 +51,7 @@ class BackendConfigForm extends ConfigForm
} }
if (empty($resources)) { if (empty($resources)) {
throw new ConfigurationError(t('Could not find any valid monitoring backend resources')); throw new ConfigurationError(mt('monitoring', 'Could not find any valid monitoring backend resources'));
} }
$this->resources = $resources; $this->resources = $resources;
@ -73,9 +73,9 @@ class BackendConfigForm extends ConfigForm
{ {
$name = isset($values['name']) ? $values['name'] : ''; $name = isset($values['name']) ? $values['name'] : '';
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Monitoring backend name missing')); throw new InvalidArgumentException(mt('monitoring', 'Monitoring backend name missing'));
} elseif ($this->config->get($name) !== null) { } elseif ($this->config->get($name) !== null) {
throw new InvalidArgumentException(t('Monitoring backend already exists')); throw new InvalidArgumentException(mt('monitoring', 'Monitoring backend already exists'));
} }
unset($values['name']); unset($values['name']);
@ -96,11 +96,11 @@ class BackendConfigForm extends ConfigForm
public function edit($name, array $values) public function edit($name, array $values)
{ {
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Old monitoring backend name missing')); throw new InvalidArgumentException(mt('monitoring', 'Old monitoring backend name missing'));
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) { } elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
throw new InvalidArgumentException(t('New monitoring backend name missing')); throw new InvalidArgumentException(mt('monitoring', 'New monitoring backend name missing'));
} elseif (($backendConfig = $this->config->get($name)) === null) { } elseif (($backendConfig = $this->config->get($name)) === null) {
throw new InvalidArgumentException(t('Unknown monitoring backend provided')); throw new InvalidArgumentException(mt('monitoring', 'Unknown monitoring backend provided'));
} }
unset($values['name']); unset($values['name']);
@ -121,9 +121,9 @@ class BackendConfigForm extends ConfigForm
public function remove($name) public function remove($name)
{ {
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Monitoring backend name missing')); throw new InvalidArgumentException(mt('monitoring', 'Monitoring backend name missing'));
} elseif (($backendConfig = $this->config->get($name)) === null) { } elseif (($backendConfig = $this->config->get($name)) === null) {
throw new InvalidArgumentException(t('Unknown monitoring backend provided')); throw new InvalidArgumentException(mt('monitoring', 'Unknown monitoring backend provided'));
} }
unset($this->config->{$name}); unset($this->config->{$name});
@ -141,10 +141,10 @@ class BackendConfigForm extends ConfigForm
try { try {
if ($monitoringBackend === null) { // create new backend if ($monitoringBackend === null) { // create new backend
$this->add($this->getValues()); $this->add($this->getValues());
$message = t('Monitoring backend "%s" has been successfully created'); $message = mt('monitoring', 'Monitoring backend "%s" has been successfully created');
} else { // edit existing backend } else { // edit existing backend
$this->edit($monitoringBackend, $this->getValues()); $this->edit($monitoringBackend, $this->getValues());
$message = t('Monitoring backend "%s" has been successfully changed'); $message = mt('monitoring', 'Monitoring backend "%s" has been successfully changed');
} }
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Notification::error($e->getMessage()); Notification::error($e->getMessage());
@ -170,9 +170,9 @@ class BackendConfigForm extends ConfigForm
$monitoringBackend = $request->getQuery('backend'); $monitoringBackend = $request->getQuery('backend');
if ($monitoringBackend !== null) { if ($monitoringBackend !== null) {
if ($monitoringBackend === '') { if ($monitoringBackend === '') {
throw new ConfigurationError(t('Monitoring backend name missing')); throw new ConfigurationError(mt('monitoring', 'Monitoring backend name missing'));
} elseif (false === isset($this->config->{$monitoringBackend})) { } elseif (false === isset($this->config->{$monitoringBackend})) {
throw new ConfigurationError(t('Unknown monitoring backend provided')); throw new ConfigurationError(mt('monitoring', 'Unknown monitoring backend provided'));
} }
$backendConfig = $this->config->{$monitoringBackend}->toArray(); $backendConfig = $this->config->{$monitoringBackend}->toArray();
@ -201,7 +201,7 @@ class BackendConfigForm extends ConfigForm
'disabled', 'disabled',
array( array(
'required' => true, 'required' => true,
'label' => t('Disable This Backend') 'label' => mt('monitoring', 'Disable This Backend')
) )
); );
$this->addElement( $this->addElement(
@ -209,8 +209,8 @@ class BackendConfigForm extends ConfigForm
'name', 'name',
array( array(
'required' => true, 'required' => true,
'label' => t('Backend Name'), 'label' => mt('monitoring', 'Backend Name'),
'description' => t('The identifier of this backend') 'description' => mt('monitoring', 'The identifier of this backend')
) )
); );
$this->addElement( $this->addElement(
@ -219,8 +219,8 @@ class BackendConfigForm extends ConfigForm
array( array(
'required' => true, 'required' => true,
'autosubmit' => true, 'autosubmit' => true,
'label' => t('Backend Type'), 'label' => mt('monitoring', 'Backend Type'),
'description' => t('The data source used for retrieving monitoring information'), 'description' => mt('monitoring', 'The data source used for retrieving monitoring information'),
'multiOptions' => $resourceTypes, 'multiOptions' => $resourceTypes,
'value' => $resourceType 'value' => $resourceType
) )
@ -230,8 +230,8 @@ class BackendConfigForm extends ConfigForm
'resource', 'resource',
array( array(
'required' => true, 'required' => true,
'label' => t('Resource'), 'label' => mt('monitoring', 'Resource'),
'description' => t('The resource to use'), 'description' => mt('monitoring', 'The resource to use'),
'multiOptions' => $this->resources[$resourceType] 'multiOptions' => $this->resources[$resourceType]
) )
); );

View File

@ -9,7 +9,8 @@ use Icinga\Web\Form;
class LocalInstanceForm extends Form class LocalInstanceForm extends Form
{ {
/** /**
* Initialize this form * (non-PHPDoc)
* @see Form::init() For the method documentation.
*/ */
public function init() public function init()
{ {
@ -17,21 +18,21 @@ class LocalInstanceForm extends Form
} }
/** /**
* @see Form::createElements() * (non-PHPDoc)
* @see Form::createElements() For the method documentation.
*/ */
public function createElements(array $formData) public function createElements(array $formData = array())
{ {
$this->addElement( $this->addElement(
'text', 'text',
'path', 'path',
array( array(
'required' => true, 'required' => true,
'label' => t('Local Filepath'), 'label' => mt('monitoring', 'Command File'),
'value' => '/usr/local/icinga/var/rw/icinga.cmd', 'value' => '/usr/local/icinga/var/rw/icinga.cmd',
'description' => t('The file path where the icinga commandpipe can be found') 'description' => mt('monitoring', 'Path to the local Icinga command file')
) )
); );
return $this; return $this;
} }
} }

View File

@ -9,60 +9,65 @@ use Icinga\Web\Form\Element\Number;
class RemoteInstanceForm extends Form class RemoteInstanceForm extends Form
{ {
/**
* (non-PHPDoc)
* @see Form::init() For the method documentation.
*/
public function init() public function init()
{ {
$this->setName('form_config_monitoring_instance_remote'); $this->setName('form_config_monitoring_instance_remote');
} }
/** /**
* @see Form::createElements() * (non-PHPDoc)
* @see Form::createElements() For the method documentation.
*/ */
public function createElements(array $formData) public function createElements(array $formData = array())
{ {
$this->addElement( $this->addElements(array(
array(
'text', 'text',
'host', 'host',
array( array(
'required' => true, 'required' => true,
'label' => t('Remote Host'), 'label' => mt('monitoring', 'Host'),
'description' => t( 'description' => mt('monitoring',
'Enter the hostname or address of the machine on which the icinga instance is running' 'Hostname or address of the remote Icinga instance'
) )
) )
); ),
$this->addElement(
new Number( new Number(
array( array(
'required' => true, 'required' => true,
'name' => 'port', 'name' => 'port',
'label' => t('Remote SSH Port'), 'label' => mt('monitoring', 'Port'),
'description' => t('Enter the ssh port to use for connecting to the remote icinga instance'), 'description' => mt('monitoring', 'SSH port to connect to on the remote Icinga instance'),
'value' => 22 'value' => 22
) )
) ),
); array(
$this->addElement(
'text', 'text',
'user', 'user',
array( array(
'required' => true, 'required' => true,
'label' => t('Remote SSH User'), 'label' => mt('monitoring', 'User'),
'description' => t( 'description' => mt('monitoring',
'Enter the username to use for connecting to the remote machine or leave blank for default' 'User to log in as on the remote Icinga instance. Please note that key-based SSH login must be'
. ' possible for this user'
) )
) )
); ),
$this->addElement( array(
'text', 'text',
'path', 'path',
array( array(
'required' => true, 'required' => true,
'label' => t('Remote Filepath'), 'label' => mt('monitoring', 'Command File'),
'value' => '/usr/local/icinga/var/rw/icinga.cmd', 'value' => '/usr/local/icinga/var/rw/icinga.cmd',
'description' => t('The file path where the icinga commandpipe can be found') 'description' => mt('monitoring', 'Path to the Icinga command file on the remote Icinga instance')
) )
); )
));
return $this; return $this;
} }
} }

View File

@ -5,12 +5,14 @@
namespace Icinga\Module\Monitoring\Form\Config; namespace Icinga\Module\Monitoring\Form\Config;
use InvalidArgumentException; use InvalidArgumentException;
use Icinga\Web\Request;
use Icinga\Form\ConfigForm;
use Icinga\Web\Notification;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Form\ConfigForm;
use Icinga\Module\Monitoring\Command\Transport\LocalCommandFile;
use Icinga\Module\Monitoring\Command\Transport\RemoteCommandFile;
use Icinga\Module\Monitoring\Form\Config\Instance\LocalInstanceForm; use Icinga\Module\Monitoring\Form\Config\Instance\LocalInstanceForm;
use Icinga\Module\Monitoring\Form\Config\Instance\RemoteInstanceForm; use Icinga\Module\Monitoring\Form\Config\Instance\RemoteInstanceForm;
use Icinga\Web\Notification;
use Icinga\Web\Request;
/** /**
* Form for modifying/creating monitoring instances * Form for modifying/creating monitoring instances
@ -18,32 +20,39 @@ use Icinga\Module\Monitoring\Form\Config\Instance\RemoteInstanceForm;
class InstanceConfigForm extends ConfigForm class InstanceConfigForm extends ConfigForm
{ {
/** /**
* Initialize this form * (non-PHPDoc)
* @see Form::init() For the method documentation.
*/ */
public function init() public function init()
{ {
$this->setName('form_config_monitoring_instance'); $this->setName('form_config_monitoring_instance');
$this->setSubmitLabel(t('Save Changes')); $this->setSubmitLabel(mt('monitoring', 'Save Changes'));
} }
/** /**
* Return a form object for the given instance type * Get a form object for the given instance type
* *
* @param string $type The instance type for which to return a form * @param string $type The instance type for which to return a form
* *
* @return Form * @return LocalInstanceForm|RemoteInstanceForm
* *
* @throws InvalidArgumentException In case the given instance type is invalid * @throws InvalidArgumentException In case the given instance type is invalid
*/ */
public function getInstanceForm($type) public function getInstanceForm($type)
{ {
if ($type === 'local') { switch (strtolower($type)) {
return new LocalInstanceForm(); case LocalCommandFile::TRANSPORT:
} elseif ($type === 'remote') { $form = new LocalInstanceForm();
return new RemoteInstanceForm(); break;
} else { case RemoteCommandFile::TRANSPORT;
throw new InvalidArgumentException(sprintf(t('Invalid instance type "%s" provided'), $type)); $form = new RemoteInstanceForm();
break;
default:
throw new InvalidArgumentException(
sprintf(mt('monitoring', 'Invalid instance type "%s" given'), $type)
);
} }
return $form;
} }
/** /**
@ -61,9 +70,10 @@ class InstanceConfigForm extends ConfigForm
{ {
$name = isset($values['name']) ? $values['name'] : ''; $name = isset($values['name']) ? $values['name'] : '';
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Instance name missing')); throw new InvalidArgumentException(mt('monitoring', 'Instance name missing'));
} elseif ($this->config->get($name) !== null) { }
throw new InvalidArgumentException(t('Instance already exists')); if (isset($this->config->{$name})) {
throw new InvalidArgumentException(mt('monitoring', 'Instance already exists'));
} }
unset($values['name']); unset($values['name']);
@ -84,16 +94,16 @@ class InstanceConfigForm extends ConfigForm
public function edit($name, array $values) public function edit($name, array $values)
{ {
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Old instance name missing')); throw new InvalidArgumentException(mt('monitoring', 'Old instance name missing'));
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) { } elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
throw new InvalidArgumentException(t('New instance name missing')); throw new InvalidArgumentException(mt('monitoring', 'New instance name missing'));
} elseif (! ($instanceConfig = $this->config->get($name))) { } elseif (! ($instanceConfig = $this->config->get($name))) {
throw new InvalidArgumentException(t('Unknown instance name provided')); throw new InvalidArgumentException(mt('monitoring', 'Unknown instance name provided'));
} }
unset($values['name']); unset($values['name']);
unset($this->config->{$name}); unset($this->config->{$name});
$this->config->{$newName} = array_merge($instanceConfig->toArray(), $values); $this->config->{$newName} = $values;
return $this->config->{$newName}; return $this->config->{$newName};
} }
@ -102,16 +112,16 @@ class InstanceConfigForm extends ConfigForm
* *
* @param string $name The name of the resource to remove * @param string $name The name of the resource to remove
* *
* @return array The removed resource confguration * @return array The removed resource configuration
* *
* @throws InvalidArgumentException In case the resource name is missing or invalid * @throws InvalidArgumentException In case the resource name is missing or invalid
*/ */
public function remove($name) public function remove($name)
{ {
if (! $name) { if (! $name) {
throw new InvalidArgumentException(t('Instance name missing')); throw new InvalidArgumentException(mt('monitoring', 'Instance name missing'));
} elseif (! ($instanceConfig = $this->config->get($name))) { } elseif (! ($instanceConfig = $this->config->get($name))) {
throw new InvalidArgumentException(t('Unknown instance name provided')); throw new InvalidArgumentException(mt('monitoring', 'Unknown instance name provided'));
} }
unset($this->config->{$name}); unset($this->config->{$name});
@ -119,19 +129,40 @@ class InstanceConfigForm extends ConfigForm
} }
/** /**
* @see Form::onSuccess() * @see Form::onRequest() For the method documentation.
* @throws ConfigurationError In case the instance name is missing or invalid
*/
public function onRequest(Request $request)
{
$instanceName = $request->getQuery('instance');
if ($instanceName !== null) {
if (! $instanceName) {
throw new ConfigurationError(mt('monitoring', 'Instance name missing'));
}
if (! isset($this->config->{$instanceName})) {
throw new ConfigurationError(mt('monitoring', 'Unknown instance name given'));
}
$instanceConfig = $this->config->{$instanceName}->toArray();
$instanceConfig['name'] = $instanceName;
$this->populate($instanceConfig);
}
}
/**
* (non-PHPDoc)
* @see Form::onSuccess() For the method documentation.
*/ */
public function onSuccess(Request $request) public function onSuccess(Request $request)
{ {
$instanceName = $request->getQuery('instance'); $instanceName = $request->getQuery('instance');
try { try {
if ($instanceName === null) { // create new instance if ($instanceName === null) { // create new instance
$this->add($this->getValues()); $this->add($this->getValues());
$message = t('Instance "%s" created successfully.'); $message = mt('monitoring', 'Instance "%s" created successfully.');
} else { // edit existing instance } else { // edit existing instance
$this->edit($instanceName, $this->getValues()); $this->edit($instanceName, $this->getValues());
$message = t('Instance "%s" edited successfully.'); $message = mt('monitoring', 'Instance "%s" edited successfully.');
} }
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Notification::error($e->getMessage()); Notification::error($e->getMessage());
@ -146,63 +177,37 @@ class InstanceConfigForm extends ConfigForm
} }
/** /**
* @see Form::onRequest() * (non-PHPDoc)
* * @see Form::createElements() For the method documentation.
* @throws ConfigurationError In case the instance name is missing or invalid
*/ */
public function onRequest(Request $request) public function createElements(array $formData = array())
{ {
$instanceName = $request->getQuery('instance'); $instanceType = isset($formData['transport']) ? $formData['transport'] : LocalCommandFile::TRANSPORT;
if ($instanceName !== null) {
if (! $instanceName) {
throw new ConfigurationError(t('Instance name missing'));
} elseif (false === isset($this->config->{$instanceName})) {
throw new ConfigurationError(t('Unknown instance name provided'));
}
$instanceConfig = $this->config->{$instanceName}->toArray(); $this->addElements(array(
$instanceConfig['name'] = $instanceName; array(
if (isset($instanceConfig['host'])) {
// Necessary as we have no config directive for setting the instance's type
$instanceConfig['type'] = 'remote';
}
$this->populate($instanceConfig);
}
}
/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
$instanceType = isset($formData['type']) ? $formData['type'] : 'local';
$this->addElement(
'text', 'text',
'name', 'name',
array( array(
'required' => true, 'required' => true,
'label' => t('Instance Name') 'label' => mt('monitoring', 'Instance Name')
) )
); ),
$this->addElement( array(
'select', 'select',
'type', 'transport',
array( array(
'required' => true, 'required' => true,
'ignore' => true,
'autosubmit' => true, 'autosubmit' => true,
'label' => t('Instance Type'), 'label' => mt('monitoring', 'Instance Type'),
'description' => t(
'When configuring a remote host, you need to setup passwordless key authentication'
),
'multiOptions' => array( 'multiOptions' => array(
'local' => t('Local Command Pipe'), LocalCommandFile::TRANSPORT => mt('monitoring', 'Local Command File'),
'remote' => t('Remote Command Pipe') RemoteCommandFile::TRANSPORT => mt('monitoring', 'Remote Command File')
), ),
'value' => $instanceType 'value' => $instanceType
) )
); )
));
$this->addElements($this->getInstanceForm($instanceType)->createElements($formData)->getElements()); $this->addElements($this->getInstanceForm($instanceType)->createElements($formData)->getElements());
} }

View File

@ -19,7 +19,7 @@ class SecurityConfigForm extends ConfigForm
public function init() public function init()
{ {
$this->setName('form_config_monitoring_security'); $this->setName('form_config_monitoring_security');
$this->setSubmitLabel(t('Save Changes')); $this->setSubmitLabel(mt('monitoring', 'Save Changes'));
} }
/** /**
@ -30,7 +30,7 @@ class SecurityConfigForm extends ConfigForm
$this->config->security = $this->getValues(); $this->config->security = $this->getValues();
if ($this->save()) { if ($this->save()) {
Notification::success(t('New security configuration has successfully been stored')); Notification::success(mt('monitoring', 'New security configuration has successfully been stored'));
} else { } else {
return false; return false;
} }
@ -56,8 +56,8 @@ class SecurityConfigForm extends ConfigForm
'protected_customvars', 'protected_customvars',
array( array(
'required' => true, 'required' => true,
'label' => t('Protected Custom Variables'), 'label' => mt('monitoring', 'Protected Custom Variables'),
'description' => t( 'description' => mt('monitoring',
'Comma separated case insensitive list of protected custom variables.' 'Comma separated case insensitive list of protected custom variables.'
. ' Use * as a placeholder for zero or more wildcard characters.' . ' Use * as a placeholder for zero or more wildcard characters.'
. ' Existance of those custom variables will be shown, but their values will be masked.' . ' Existance of those custom variables will be shown, but their values will be masked.'

View File

@ -56,14 +56,14 @@ class StatehistoryForm extends Form
'select', 'select',
'from', 'from',
array( array(
'label' => t('From'), 'label' => mt('monitoring', 'From'),
'value' => $this->getRequest()->getParam('from', strtotime('3 months ago')), 'value' => $this->getRequest()->getParam('from', strtotime('3 months ago')),
'multiOptions' => array( 'multiOptions' => array(
strtotime('midnight 3 months ago') => t('3 Months'), strtotime('midnight 3 months ago') => mt('monitoring', '3 Months'),
strtotime('midnight 4 months ago') => t('4 Months'), strtotime('midnight 4 months ago') => mt('monitoring', '4 Months'),
strtotime('midnight 8 months ago') => t('8 Months'), strtotime('midnight 8 months ago') => mt('monitoring', '8 Months'),
strtotime('midnight 12 months ago') => t('1 Year'), strtotime('midnight 12 months ago') => mt('monitoring', '1 Year'),
strtotime('midnight 24 months ago') => t('2 Years') strtotime('midnight 24 months ago') => mt('monitoring', '2 Years')
), ),
'class' => 'autosubmit' 'class' => 'autosubmit'
) )
@ -72,10 +72,10 @@ class StatehistoryForm extends Form
'select', 'select',
'to', 'to',
array( array(
'label' => t('To'), 'label' => mt('monitoring', 'To'),
'value' => $this->getRequest()->getParam('to', time()), 'value' => $this->getRequest()->getParam('to', time()),
'multiOptions' => array( 'multiOptions' => array(
time() => t('Today') time() => mt('monitoring', 'Today')
), ),
'class' => 'autosubmit' 'class' => 'autosubmit'
) )
@ -86,11 +86,11 @@ class StatehistoryForm extends Form
'select', 'select',
'objecttype', 'objecttype',
array( array(
'label' => t('Object type'), 'label' => mt('monitoring', 'Object type'),
'value' => $objectType, 'value' => $objectType,
'multiOptions' => array( 'multiOptions' => array(
'services' => t('Services'), 'services' => mt('monitoring', 'Services'),
'hosts' => t('Hosts') 'hosts' => mt('monitoring', 'Hosts')
), ),
'class' => 'autosubmit' 'class' => 'autosubmit'
) )
@ -104,13 +104,13 @@ class StatehistoryForm extends Form
'select', 'select',
'state', 'state',
array( array(
'label' => t('State'), 'label' => mt('monitoring', 'State'),
'value' => $serviceState, 'value' => $serviceState,
'multiOptions' => array( 'multiOptions' => array(
'cnt_critical_hard' => t('Critical'), 'cnt_critical_hard' => mt('monitoring', 'Critical'),
'cnt_warning_hard' => t('Warning'), 'cnt_warning_hard' => mt('monitoring', 'Warning'),
'cnt_unknown_hard' => t('Unknown'), 'cnt_unknown_hard' => mt('monitoring', 'Unknown'),
'cnt_ok' => t('Ok') 'cnt_ok' => mt('monitoring', 'Ok')
), ),
'class' => 'autosubmit' 'class' => 'autosubmit'
) )
@ -124,12 +124,12 @@ class StatehistoryForm extends Form
'select', 'select',
'state', 'state',
array( array(
'label' => t('State'), 'label' => mt('monitoring', 'State'),
'value' => $hostState, 'value' => $hostState,
'multiOptions' => array( 'multiOptions' => array(
'cnt_up' => t('Up'), 'cnt_up' => mt('monitoring', 'Up'),
'cnt_down_hard' => t('Down'), 'cnt_down_hard' => mt('monitoring', 'Down'),
'cnt_unreachable_hard' => t('Unreachable') 'cnt_unreachable_hard' => mt('monitoring', 'Unreachable')
), ),
'class' => 'autosubmit' 'class' => 'autosubmit'
) )
@ -143,7 +143,7 @@ class StatehistoryForm extends Form
'escape' => false, 'escape' => false,
'value' => '1', 'value' => '1',
'class' => 'btn btn-cta btn-common', 'class' => 'btn btn-cta btn-common',
'label' => t('Apply') 'label' => mt('monitoring', 'Apply')
) )
); );
} }

View File

@ -1,4 +1,4 @@
<h4><?= t('List Of Supported Commands'); ?></h4> <h4><?= mt('monitoring', 'List Of Supported Commands'); ?></h4>
<ul> <ul>
<?php foreach($this->commands as $command): ?> <?php foreach($this->commands as $command): ?>
<li> <li>

View File

@ -3,7 +3,7 @@
</div> </div>
<div class="content" data-base-target="_next"> <div class="content" data-base-target="_next">
<h1>Monitoring Backends</h1> <h1><?= $this->translate('Monitoring Backends') ?></h1>
<p> <p>
<a href="<?= $this->href('/monitoring/config/createbackend'); ?>"> <a href="<?= $this->href('/monitoring/config/createbackend'); ?>">
<?= $this->icon('create.png'); ?> <?= $this->translate('Create New Monitoring Backend'); ?> <?= $this->icon('create.png'); ?> <?= $this->translate('Create New Monitoring Backend'); ?>
@ -15,7 +15,7 @@
<th style="width: 5em"><?= $this->translate('Remove'); ?></th> <th style="width: 5em"><?= $this->translate('Remove'); ?></th>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($this->backendsConfig as $backendName => $config): ?> <?php foreach ($this->backendsConfig as $backendName => $config): ?>
<tr> <tr>
<td> <td>
<a href="<?= $this->href('/monitoring/config/editbackend', array('backend' => $backendName)); ?>"> <a href="<?= $this->href('/monitoring/config/editbackend', array('backend' => $backendName)); ?>">
@ -32,10 +32,10 @@
</a> </a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<h1>Monitoring Instances</h1> <h1><?= $this->translate('Monitoring Instances') ?></h1>
<p> <p>
<a href="<?= $this->href('/monitoring/config/createinstance'); ?>"> <a href="<?= $this->href('/monitoring/config/createinstance'); ?>">
<?= $this->icon('create.png'); ?> <?= $this->translate('Create New Instance'); ?> <?= $this->icon('create.png'); ?> <?= $this->translate('Create New Instance'); ?>
@ -47,7 +47,7 @@
<th style="width: 5em"><?= $this->translate('Remove'); ?></th> <th style="width: 5em"><?= $this->translate('Remove'); ?></th>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($this->instancesConfig as $instanceName => $config): ?> <?php foreach ($this->instancesConfig as $instanceName => $config): ?>
<tr> <tr>
<td> <td>
<a href="<?= $this->href('/monitoring/config/editinstance', array('instance' => $instanceName)); ?>"> <a href="<?= $this->href('/monitoring/config/editinstance', array('instance' => $instanceName)); ?>">
@ -64,7 +64,7 @@
</a> </a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -8,7 +8,7 @@
<?php <?php
if (count($groupData) === 0) { if (count($groupData) === 0) {
echo t('No contacts matching the filter'); echo mt('monitoring', 'No contacts matching the filter');
} }
foreach ($groupData as $groupName => $groupInfo): ?> foreach ($groupData as $groupName => $groupInfo): ?>

View File

@ -13,7 +13,7 @@ $contactHelper = $this->getHelper('ContactFlags');
<div data-base-target="_next" class="content contacts"> <div data-base-target="_next" class="content contacts">
<?php <?php
if (count($contacts) === 0) { if (count($contacts) === 0) {
echo t('No contacts matching the filter'); echo mt('monitoring', 'No contacts matching the filter');
return; return;
} }
foreach ($contacts as $contact): ?> foreach ($contacts as $contact): ?>
@ -25,12 +25,12 @@ $contactHelper = $this->getHelper('ContactFlags');
) ?>"><strong><?= $contact->contact_name ?></strong></a> (<?= $contact->contact_alias ?>) ) ?>"><strong><?= $contact->contact_name ?></strong></a> (<?= $contact->contact_alias ?>)
<div><?= sprintf( <div><?= sprintf(
'%1$s: <a href="mailto:%2$s">%2$s</a>', '%1$s: <a href="mailto:%2$s">%2$s</a>',
t('Email'), mt('monitoring', 'Email'),
$this->escape($contact->contact_email) $this->escape($contact->contact_email)
) ?></div> ) ?></div>
<?php if ($contact->contact_pager): ?> <?php if ($contact->contact_pager): ?>
<div> <div>
<?= t('Pager') ?>: <?= mt('monitoring', 'Pager') ?>:
<?= $this->escape($contact->contact_pager) ?> <?= $this->escape($contact->contact_pager) ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
@ -38,13 +38,13 @@ $contactHelper = $this->getHelper('ContactFlags');
<div class="notification-periods"> <div class="notification-periods">
<?php if ($contact->contact_notify_service_timeperiod): ?> <?php if ($contact->contact_notify_service_timeperiod): ?>
<div> <div>
<?= t('Service notification period') ?>: <?= mt('monitoring', 'Service notification period') ?>:
<?= $this->escape($contact->contact_notify_service_timeperiod) ?> <?= $this->escape($contact->contact_notify_service_timeperiod) ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if ($contact->contact_notify_host_timeperiod): ?> <?php if ($contact->contact_notify_host_timeperiod): ?>
<div> <div>
<?= t('Host notification period') ?>: <?= mt('monitoring', 'Host notification period') ?>:
<?= $this->escape($contact->contact_notify_host_timeperiod) ?> <?= $this->escape($contact->contact_notify_host_timeperiod) ?>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@ -109,7 +109,7 @@
</div> </div>
</td> </td>
</tr> </tr>
<? endforeach ?> <?php endforeach ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -8,7 +8,7 @@
<?php <?php
if (count($hostgroups) === 0) { if (count($hostgroups) === 0) {
echo t('No host groups matching the filter'); echo mt('monitoring', 'No host groups matching the filter');
} }
?> ?>
<?php foreach($hostgroups as $h): ?> <?php foreach($hostgroups as $h): ?>

View File

@ -26,7 +26,7 @@ if (empty($this->notifications)) {
<?php <?php
if (count($notifications) === 0) { if (count($notifications) === 0) {
echo t('No notifications matching the filter'); echo mt('monitoring', 'No notifications matching the filter');
} }
foreach ($notifications as $notification): foreach ($notifications as $notification):

View File

@ -8,7 +8,7 @@
<?php <?php
if (count($servicegroups) === 0) { if (count($servicegroups) === 0) {
echo t('No service groups matching the filter'); echo mt('monitoring', 'No service groups matching the filter');
} }
?> ?>
<?php foreach($servicegroups as $servicegroup): ?> <?php foreach($servicegroups as $servicegroup): ?>

View File

@ -36,7 +36,7 @@ if (!$this->compact): ?>
<?php <?php
if (count($services) === 0) { if (count($services) === 0) {
echo t('No services matching the filter'); echo mt('monitoring', 'No services matching the filter');
} }
foreach ($services as $service): foreach ($services as $service):
$serviceLink = $this->href( $serviceLink = $this->href(

View File

@ -23,39 +23,39 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
$settings = array( $settings = array(
'cnt_up' => array( 'cnt_up' => array(
'tooltip' => t('%d ok on %s'), 'tooltip' => mt('monitoring', '%d ok on %s'),
'color' => '#49DF96', 'color' => '#49DF96',
'opacity' => '0.55' 'opacity' => '0.55'
), ),
'cnt_unreachable_hard' => array( 'cnt_unreachable_hard' => array(
'tooltip' => t('%d unreachable on %s'), 'tooltip' => mt('monitoring', '%d unreachable on %s'),
'color' => '#77AAFF', 'color' => '#77AAFF',
'opacity' => '0.55' 'opacity' => '0.55'
), ),
'cnt_critical_hard' => array( 'cnt_critical_hard' => array(
'tooltip' => t('%d critical on %s'), 'tooltip' => mt('monitoring', '%d critical on %s'),
'color' => '#ff5566', 'color' => '#ff5566',
'opacity' => '0.9' 'opacity' => '0.9'
), ),
'cnt_warning_hard' => array( 'cnt_warning_hard' => array(
'tooltip' => t('%d warning on %s'), 'tooltip' => mt('monitoring', '%d warning on %s'),
'color' => '#ffaa44', 'color' => '#ffaa44',
'opacity' => '1.0' 'opacity' => '1.0'
), ),
'cnt_down_hard' => array( 'cnt_down_hard' => array(
'tooltip' => t('%d down on %s'), 'tooltip' => mt('monitoring', '%d down on %s'),
'color' => '#ff5566', 'color' => '#ff5566',
'opacity' => '0.9' 'opacity' => '0.9'
), ),
'cnt_unknown_hard' => array( 'cnt_unknown_hard' => array(
'tooltip' => t('%d unknown on %s'), 'tooltip' => mt('monitoring', '%d unknown on %s'),
'color' => '#cc77ff', 'color' => '#cc77ff',
'opacity' => '0.7' 'opacity' => '0.7'
), ),
'cnt_ok' => array( 'cnt_ok' => array(
'tooltip' => t('%d ok on %s'), 'tooltip' => mt('monitoring', '%d ok on %s'),
'color' => '#49DF96', 'color' => '#49DF96',
'opacity' => '0.55' 'opacity' => '0.55'
) )
@ -71,7 +71,7 @@ if ($to - $from > 315360000) {
$data = array(); $data = array();
if (count($summary) === 0) { if (count($summary) === 0) {
echo t('No state changes in the selected time period.'); echo mt('monitoring', 'No state changes in the selected time period.');
} }
foreach ($summary as $entry) { foreach ($summary as $entry) {
$day = $entry->day; $day = $entry->day;

View File

@ -10,7 +10,7 @@ $this->target = array('host' => $this->hostquery);
<div class="content"> <div class="content">
<?php if (count($objects) === 0): ?> <?php if (count($objects) === 0): ?>
<?= t('No hosts matching the filter'); ?> <?= mt('monitoring', 'No hosts matching the filter'); ?>
<?php else: ?> <?php else: ?>
<h1> Summary for <?= count($objects) ?> hosts </h1> <h1> Summary for <?= count($objects) ?> hosts </h1>
<?= $this->render('multi/components/objectlist.phtml'); ?> <?= $this->render('multi/components/objectlist.phtml'); ?>

View File

@ -14,7 +14,7 @@ $this->target = array(
<div class="content"> <div class="content">
<?php if (count($objects) === 0): ?> <?php if (count($objects) === 0): ?>
<?= t('No services matching the filter'); ?> <?= mt('monitoring', 'No services matching the filter'); ?>
<?php else: ?> <?php else: ?>
<h1> Summary for <?= count($objects) ?> services </h1> <h1> Summary for <?= count($objects) ?> services </h1>

View File

@ -19,23 +19,23 @@
</tr> </tr>
<?php if ($contact->contact_email): ?> <?php if ($contact->contact_email): ?>
<tr> <tr>
<th><?= t('Email') ?></th> <th><?= mt('monitoring', 'Email') ?></th>
<td><?= sprintf('<a href="mailto:%1$s">%1$s</a>', $this->escape($contact->contact_email)) ?></td> <td><?= sprintf('<a href="mailto:%1$s">%1$s</a>', $this->escape($contact->contact_email)) ?></td>
</tr> </tr>
<?php endif ?> <?php endif ?>
<?php if ($contact->contact_pager): ?> <?php if ($contact->contact_pager): ?>
<tr> <tr>
<th><?= t('Pager') ?></th> <th><?= mt('monitoring', 'Pager') ?></th>
<td><?= $this->escape($contact->contact_pager) ?></td> <td><?= $this->escape($contact->contact_pager) ?></td>
</tr> </tr>
<?php endif ?> <?php endif ?>
<tr> <tr>
<th><?= t('Hosts') ?></th> <th><?= mt('monitoring', 'Hosts') ?></th>
<td><?= $this->escape($contactHelper->contactFlags($contact, 'host')) ?><br /> <td><?= $this->escape($contactHelper->contactFlags($contact, 'host')) ?><br />
<?= $this->escape($contact->contact_notify_host_timeperiod) ?></td> <?= $this->escape($contact->contact_notify_host_timeperiod) ?></td>
</tr> </tr>
<tr> <tr>
<th><?= t('Services') ?></th> <th><?= mt('monitoring', 'Services') ?></th>
<td><?= $this->escape($contactHelper->contactFlags($contact, 'service')) ?><br /> <td><?= $this->escape($contactHelper->contactFlags($contact, 'service')) ?><br />
<?= $this->escape($contact->contact_notify_service_timeperiod) ?></td> <?= $this->escape($contact->contact_notify_service_timeperiod) ?></td>
</tr> </tr>

View File

@ -142,7 +142,7 @@ $output = $this->tickets ? preg_replace_callback(
</div> </div>
</td> </td>
</tr> </tr>
<? endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -71,7 +71,7 @@ class Backend implements Selectable, Queryable, ConnectionInterface
{ {
$config = IcingaConfig::module('monitoring', 'backends'); $config = IcingaConfig::module('monitoring', 'backends');
if ($config->count() === 0) { if ($config->count() === 0) {
throw new ConfigurationError(t('No backend has been configured')); throw new ConfigurationError(mt('monitoring', 'No backend has been configured'));
} }
if ($backendName !== null) { if ($backendName !== null) {
$backendConfig = $config->get($backendName); $backendConfig = $config->get($backendName);
@ -80,7 +80,7 @@ class Backend implements Selectable, Queryable, ConnectionInterface
} }
if ((bool) $backendConfig->get('disabled', false) === true) { if ((bool) $backendConfig->get('disabled', false) === true) {
throw new ConfigurationError( throw new ConfigurationError(
t('Configuration for backend %s available but backend is disabled'), mt('monitoring', 'Configuration for backend %s available but backend is disabled'),
$backendName $backendName
); );
} }
@ -92,7 +92,7 @@ class Backend implements Selectable, Queryable, ConnectionInterface
} }
} }
if ($backendName === null) { if ($backendName === null) {
throw new ConfigurationError(t('All backends are disabled')); throw new ConfigurationError(mt('monitoring', 'All backends are disabled'));
} }
} }
$resource = ResourceFactory::create($backendConfig->resource); $resource = ResourceFactory::create($backendConfig->resource);

View File

@ -33,7 +33,10 @@ abstract class CommandTransport
if (! isset(self::$config)) { if (! isset(self::$config)) {
self::$config = Config::module('monitoring', 'instances'); self::$config = Config::module('monitoring', 'instances');
if (self::$config->count() === 0) { if (self::$config->count() === 0) {
throw new ConfigurationError; throw new ConfigurationError(
'No instances have been configured in \'%s\'.',
self::$config->getConfigFile()
);
} }
} }
return self::$config; return self::$config;
@ -50,15 +53,22 @@ abstract class CommandTransport
public static function fromConfig(Zend_Config $config) public static function fromConfig(Zend_Config $config)
{ {
switch (strtolower($config->transport)) { switch (strtolower($config->transport)) {
case 'remote': case RemoteCommandFile::TRANSPORT:
$transport = new RemoteCommandFile(); $transport = new RemoteCommandFile();
break; break;
case 'local': case LocalCommandFile::TRANSPORT:
case '': // Casting null to string is the empty string case '': // Casting null to string is the empty string
$transport = new LocalCommandFile(); $transport = new LocalCommandFile();
break; break;
default: default:
throw new ConfigurationError(); throw new ConfigurationError(
'Can\'t create command transport \'%s\'. Invalid transport defined in \'%s\'.'
. ' Use one of \'%s\' or \'%s\'.',
$config->transport,
self::$config->getConfigFile(),
LocalCommandFile::TRANSPORT,
RemoteCommandFile::TRANSPORT
);
} }
unset($config->transport); unset($config->transport);
foreach ($config as $key => $value) { foreach ($config as $key => $value) {

View File

@ -17,6 +17,11 @@ use Icinga\Util\File;
*/ */
class LocalCommandFile implements CommandTransportInterface class LocalCommandFile implements CommandTransportInterface
{ {
/**
* Transport identifier
*/
const TRANSPORT = 'local';
/** /**
* Path to the icinga command file * Path to the icinga command file
* *
@ -104,15 +109,13 @@ class LocalCommandFile implements CommandTransportInterface
public function send(IcingaCommand $command, $now = null) public function send(IcingaCommand $command, $now = null)
{ {
if (! isset($this->path)) { if (! isset($this->path)) {
throw new LogicException; throw new LogicException('Can\'t send external Icinga Command. Path to the local command file is missing');
} }
$commandString = $this->renderer->render($command, $now); $commandString = $this->renderer->render($command, $now);
Logger::debug( Logger::debug(
sprintf( 'Sending external Icinga command "%s" to the local command file "%s"',
mt('monitoring', 'Sending external Icinga command "%s" to the local command file "%s"'),
$commandString, $commandString,
$this->path $this->path
)
); );
try { try {
$file = new File($this->path, $this->openMode); $file = new File($this->path, $this->openMode);
@ -120,10 +123,7 @@ class LocalCommandFile implements CommandTransportInterface
$file->fflush(); $file->fflush();
} catch (Exception $e) { } catch (Exception $e) {
throw new TransportException( throw new TransportException(
mt( 'Can\'t send external Icinga command "%s" to the local command file "%s": %s',
'monitoring',
'Can\'t send external Icinga command "%s" to the local command file "%s": %s'
),
$commandString, $commandString,
$this->path, $this->path,
$e $e

View File

@ -17,6 +17,11 @@ use Icinga\Module\Monitoring\Command\Renderer\IcingaCommandFileCommandRenderer;
*/ */
class RemoteCommandFile implements CommandTransportInterface class RemoteCommandFile implements CommandTransportInterface
{ {
/**
* Transport identifier
*/
const TRANSPORT = 'remote';
/** /**
* Remote host * Remote host
* *
@ -168,20 +173,18 @@ class RemoteCommandFile implements CommandTransportInterface
public function send(IcingaCommand $command, $now = null) public function send(IcingaCommand $command, $now = null)
{ {
if (! isset($this->path)) { if (! isset($this->path)) {
throw new LogicException; throw new LogicException('Can\'t send external Icinga Command. Path to the remote command file is missing');
} }
if (! isset($this->host)) { if (! isset($this->host)) {
throw new LogicException; throw new LogicException('Can\'t send external Icinga Command. Remote host is missing');
} }
$commandString = $this->renderer->render($command, $now); $commandString = $this->renderer->render($command, $now);
Logger::debug( Logger::debug(
sprintf( 'Sending external Icinga command "%s" to the remote command file "%s:%u%s"',
mt('monitoring', 'Sending external Icinga command "%s" to the remote command file "%s:%u%s"'),
$commandString, $commandString,
$this->host, $this->host,
$this->port, $this->port,
$this->path $this->path
)
); );
$ssh = sprintf('ssh -o BatchMode=yes -p %u', $this->port); $ssh = sprintf('ssh -o BatchMode=yes -p %u', $this->port);
// -o BatchMode=yes for disabling interactive authentication methods // -o BatchMode=yes for disabling interactive authentication methods
@ -197,10 +200,7 @@ class RemoteCommandFile implements CommandTransportInterface
exec($ssh, $output, $status); exec($ssh, $output, $status);
if ($status !== 0) { if ($status !== 0) {
throw new TransportException( throw new TransportException(
mt( 'Can\'t send external Icinga command "%s": %s',
'monitoring',
'Can\'t send external Icinga command "%s": %s'
),
$ssh, $ssh,
implode(' ', $output) implode(' ', $output)
); );

View File

@ -245,7 +245,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
foreach ($sortColumns['columns'] as $column) { foreach ($sortColumns['columns'] as $column) {
if (! $this->isValidFilterTarget($column)) { if (! $this->isValidFilterTarget($column)) {
throw new QueryException( throw new QueryException(
t('The sort column "%s" is not allowed in "%s".'), mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
$column, $column,
get_class($this) get_class($this)
); );
@ -336,7 +336,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
if ($filter instanceof FilterMatch) { if ($filter instanceof FilterMatch) {
if (! $this->isValidFilterTarget($filter->getColumn())) { if (! $this->isValidFilterTarget($filter->getColumn())) {
throw new QueryException( throw new QueryException(
t('The filter column "%s" is not allowed here.'), mt('monitoring', 'The filter column "%s" is not allowed here.'),
$filter->getColumn() $filter->getColumn()
); );
} }

View File

@ -164,6 +164,7 @@ class Host extends MonitoredObject
*/ */
public static function getStateText($state, $translate = false) public static function getStateText($state, $translate = false)
{ {
$translate = (bool) $translate;
switch ((int) $state) { switch ((int) $state) {
case self::STATE_UP: case self::STATE_UP:
$text = $translate ? mt('monitoring', 'up') : 'up'; $text = $translate ? mt('monitoring', 'up') : 'up';
@ -179,7 +180,6 @@ class Host extends MonitoredObject
break; break;
default: default:
throw new InvalidArgumentException('Invalid host state \'%s\'', $state); throw new InvalidArgumentException('Invalid host state \'%s\'', $state);
break;
} }
return $text; return $text;
} }

View File

@ -199,34 +199,35 @@ class Service extends MonitoredObject
} }
/** /**
* Get the translated textual representation of a service state * Get the optional translated textual representation of a service state
* *
* @param int $state * @param int $state
* @param bool $translate
* *
* @return string * @return string
* @throws InvalidArgumentException If the service state is not valid * @throws InvalidArgumentException If the service state is not valid
*/ */
public static function getStateText($state) public static function getStateText($state, $translate = false)
{ {
$translate = (bool) $translate;
switch ((int) $state) { switch ((int) $state) {
case self::STATE_OK: case self::STATE_OK:
$text = mt('monitoring', 'ok'); $text = $translate ? mt('monitoring', 'ok') : 'ok';
break; break;
case self::STATE_WARNING: case self::STATE_WARNING:
$text = mt('monitoring', 'warning'); $text = $translate ? mt('monitoring', 'warning') : 'warning';
break; break;
case self::STATE_CRITICAL: case self::STATE_CRITICAL:
$text = mt('monitoring', 'critical'); $text = $translate ? mt('monitoring', 'critical') : 'critical';
break; break;
case self::STATE_UNKNOWN: case self::STATE_UNKNOWN:
$text = mt('monitoring', 'unknown'); $text = $translate ? mt('monitoring', 'unknown') : 'unknown';
break; break;
case self::STATE_PENDING: case self::STATE_PENDING:
$text = mt('monitoring', 'pending'); $text = $translate ? mt('monitoring', 'pending') : 'pending';
break; break;
default: default:
throw new InvalidArgumentException('Invalid service state \'%s\'', $state); throw new InvalidArgumentException('Invalid service state \'%s\'', $state);
break;
} }
return $text; return $text;
} }

View File

@ -167,7 +167,7 @@ class DbStoreTest extends BaseTestCase
return new DbStoreWithSetPreferences( return new DbStoreWithSetPreferences(
new Zend_Config( new Zend_Config(
array( array(
'connection' => Mockery::mock(array('getConnection' => $dbMock)) 'connection' => Mockery::mock(array('getDbAdapter' => $dbMock))
) )
), ),
Mockery::mock('Icinga\User', array('getUsername' => 'unittest')) Mockery::mock('Icinga\User', array('getUsername' => 'unittest'))