From 429b16b74edc0f5028229acf15e9054f82db8212 Mon Sep 17 00:00:00 2001 From: ayoubabid Date: Mon, 8 Dec 2014 17:31:17 +0100 Subject: [PATCH 01/13] Update LocalInstanceForm.php Wrong path to icinga2 command Signed-off-by: Eric Lippmann --- .../application/forms/Config/Instance/LocalInstanceForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php index ac1139268..daabe7e02 100644 --- a/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php +++ b/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php @@ -29,7 +29,7 @@ class LocalInstanceForm extends Form array( 'required' => true, 'label' => mt('monitoring', 'Command File'), - 'value' => '/usr/local/icinga/var/rw/icinga.cmd', + 'value' => '/var/run/icinga2/cmd/icinga2.cmd', 'description' => mt('monitoring', 'Path to the local Icinga command file') ) ); From e0bec56d2330c0a54a9d81891d8d3359531c90c1 Mon Sep 17 00:00:00 2001 From: ayoubabid Date: Mon, 8 Dec 2014 17:32:52 +0100 Subject: [PATCH 02/13] Update RemoteInstanceForm.php Wrong path to icinga2 command. Signed-off-by: Eric Lippmann --- .../application/forms/Config/Instance/RemoteInstanceForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php index c93436ab2..7c55f655a 100644 --- a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php +++ b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php @@ -63,7 +63,7 @@ class RemoteInstanceForm extends Form array( 'required' => true, 'label' => mt('monitoring', 'Command File'), - 'value' => '/usr/local/icinga/var/rw/icinga.cmd', + 'value' => '/var/run/icinga2/cmd/icinga2.cmd', 'description' => mt('monitoring', 'Path to the Icinga command file on the remote Icinga instance') ) ) From dc0f396fbfadd9b7d3eafb82e3cd6d60fdcff9fe Mon Sep 17 00:00:00 2001 From: Tom Ford Date: Fri, 28 Nov 2014 14:50:03 +0000 Subject: [PATCH 03/13] Check LDAP username in case insensitive way Signed-off-by: Eric Lippmann refs #7991 --- library/Icinga/Authentication/Backend/LdapUserBackend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php index 519dd3c48..a9ffba0c5 100644 --- a/library/Icinga/Authentication/Backend/LdapUserBackend.php +++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php @@ -150,7 +150,7 @@ class LdapUserBackend extends UserBackend public function hasUser(User $user) { $username = $user->getUsername(); - return $this->conn->fetchOne($this->selectUser($username)) === $username; + return strtolower($this->conn->fetchOne($this->selectUser($username))) === strtolower($username); } /** From 73f9328f12a4f3c41c138e77ad2e92a588f1ca59 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 10:54:58 +0100 Subject: [PATCH 04/13] Highlight hovered state rows even if there is no href fixes #8024 --- public/css/icinga/monitoring-colors.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/css/icinga/monitoring-colors.less b/public/css/icinga/monitoring-colors.less index 52154c24e..538d82a3a 100644 --- a/public/css/icinga/monitoring-colors.less +++ b/public/css/icinga/monitoring-colors.less @@ -194,7 +194,7 @@ tr.state.handled td.state { } /* HOVER colors */ -tr[href]:hover { +tr.state:hover, tr[href]:hover { color: black; background-color: #eee; } From 8779e802913e7e90b8658984aa4f6a6a4686611e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 10:56:47 +0100 Subject: [PATCH 05/13] Add a link to a service's event when showing the host's history --- .../application/views/scripts/show/history.phtml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/show/history.phtml b/modules/monitoring/application/views/scripts/show/history.phtml index dfc1cbf0e..c28c59762 100644 --- a/modules/monitoring/application/views/scripts/show/history.phtml +++ b/modules/monitoring/application/views/scripts/show/history.phtml @@ -13,6 +13,7 @@ getType() === 'host'; function contactsLink($match, $view) { $links = array(); foreach (preg_split('/,\s/', $match[1]) as $contact) { @@ -132,7 +133,13 @@ $output = $this->tickets ? preg_replace_callback( ?> - escape($event->service_description) . ' ' . $this->translate('on') . ' ' . $this->escape($event->host_name); ?> + qlink( + $this->escape($event->service_description), + 'monitoring/show/service', + array( + 'host' => $event->host_name, + 'service' => $event->service_description) + ) : $this->escape($event->service_description); ?> translate('on') . ' ' . $this->escape($event->host_name); ?> escape($event->host_name); ?> From 60feed55b759422e5729c9c49ce948cbaed50570 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 11 Dec 2014 13:15:33 +0100 Subject: [PATCH 06/13] Update Icinga 2 config for 2.3 refs #7883 --- .../files/etc/icinga2/conf.d/test-config.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf b/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf index 2dde681bf..a0abd4c20 100644 --- a/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf +++ b/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf @@ -47,7 +47,7 @@ object HostGroup "all-hosts" { local host_types = ["ok", "random", "down", "up", "unreachable", "pending"] -__for (host_type in host_types) { +for (host_type in host_types) { object HostGroup "all-" + host_type use (host_type) { display_name = "All " + host_type + " hosts" assign where host.vars.check_type == host_type @@ -57,7 +57,7 @@ __for (host_type in host_types) { local service_types = ["ok", "warning", "critical", "unknown", "flapping", "pending"] // Servicegroups -__for (service_type in service_types) { +for (service_type in service_types) { object ServiceGroup "service-" + service_type use (service_type) { display_name = "All " + service_type + " services" assign where service.vars.check_type == service_type @@ -68,7 +68,7 @@ __for (service_type in service_types) { // Services // --------------------------------------------------------------------------------------------------------------------- -__function createService(service_type, num) { +function createService(service_type, num) { apply Service "service-" + service_type + "-" + string(num + 1) use (service_type) { import "generic-service" @@ -80,8 +80,8 @@ __function createService(service_type, num) { } } -__for (num in range(4)) { - __for (service_type in service_types) { +for (num in range(4)) { + for (service_type in service_types) { createService(service_type, num) } } @@ -90,7 +90,7 @@ __for (num in range(4)) { // Hosts // --------------------------------------------------------------------------------------------------------------------- -__function createHost(checkType, checkConfig, num, checkEnabled) { +function createHost(checkType, checkConfig, num, checkEnabled) { object Host "test-" + checkType + "-" + string(num + 1) use (checkEnabled, checkType, checkConfig) { import "generic-host" address = "127.0.0.1" @@ -101,7 +101,7 @@ __function createHost(checkType, checkConfig, num, checkEnabled) { } } -__for (num in range(10)) { +for (num in range(10)) { createHost("ok", [ "ok" ], num, true) createHost("random", [ "random", "flapping" ], num, true) createHost("down", [ "warning", "critical" ], num, true) From ddc121d1ccab73e991273a77936c2af690ec3716 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 15:52:23 +0100 Subject: [PATCH 07/13] Add ProcessCheckResultCommandForm refs #6854 --- .../controllers/HostController.php | 10 ++ .../controllers/HostsController.php | 11 ++ .../controllers/ServiceController.php | 10 ++ .../controllers/ServicesController.php | 13 ++ .../Object/ProcessCheckResultCommandForm.php | 123 ++++++++++++++++++ .../views/scripts/hosts/show.phtml | 7 + .../views/scripts/services/show.phtml | 7 + .../scripts/show/components/command.phtml | 16 ++- 8 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 0a4a727ed..184e05a4c 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -2,6 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; @@ -76,4 +77,13 @@ class Monitoring_HostController extends MonitoredObjectController $this->view->title = $this->translate('Schedule Host Downtime'); $this->handleCommandForm(new ScheduleHostDowntimeCommandForm()); } + + /** + * Submit a passive host check result + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Host Check Result'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index fe34c1d6f..4aa090572 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -4,6 +4,7 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; @@ -103,6 +104,7 @@ class Monitoring_HostsController extends Controller $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts'); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/hosts/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/hosts/schedule-downtime'); + $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/hosts/process-check-result'); $this->view->hostStates = $hostStates; $this->view->objects = $this->hostList; $this->view->unhandledObjects = $unhandledObjects; @@ -161,4 +163,13 @@ class Monitoring_HostsController extends Controller $this->view->title = $this->translate('Schedule Host Downtimes'); $this->handleCommandForm(new ScheduleHostDowntimeCommandForm()); } + + /** + * Submit passive host check results + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Host Check Results'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index c6d0e4e2f..70aa9e519 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -2,6 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm; @@ -76,4 +77,13 @@ class Monitoring_ServiceController extends MonitoredObjectController $this->view->title = $this->translate('Schedule Service Downtime'); $this->handleCommandForm(new ScheduleServiceDowntimeCommandForm()); } + + /** + * Submit a passive service check result + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Service Check Result'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 56813180d..bbe2024d7 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -4,6 +4,7 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; @@ -117,6 +118,9 @@ class Monitoring_ServicesController extends Controller $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services'); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime'); + $this->view->processCheckResultAllLink = Url::fromRequest()->setPath( + 'monitoring/services/process-check-result' + ); $this->view->hostStates = $hostStates; $this->view->serviceStates = $serviceStates; $this->view->objects = $this->serviceList; @@ -181,4 +185,13 @@ class Monitoring_ServicesController extends Controller $this->view->title = $this->translate('Schedule Service Downtimes'); $this->handleCommandForm(new ScheduleServiceDowntimeCommandForm()); } + + /** + * Submit passive service check results + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Service Check Results'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php new file mode 100644 index 000000000..48ee00ab3 --- /dev/null +++ b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php @@ -0,0 +1,123 @@ +objects) + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Module\Monitoring\Forms\Command\CommandForm::getHelp() For the method documentation. + */ + public function getHelp() + { + return mt( + 'monitoring', + 'This command is used to submit passive host or service check results.' + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Web\Form::createElements() For the method documentation. + */ + public function createElements(array $formData) + { + foreach ($this->getObjects() as $object) { + /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ + // Nasty, but as getObjects() returns everything but an object with a real + // iterator interface this is the only way to fetch just the first element + break; + } + + $this->addElement( + 'select', + 'status', + array( + 'required' => true, + 'label' => mt('monitoring', 'Status'), + 'description' => mt('monitoring', 'The state this check result should report'), + 'multiOptions' => $object->getType() === $object::TYPE_HOST ? array( + ProcessCheckResultCommand::HOST_UP => mt('monitoring', 'UP', 'icinga.state'), + ProcessCheckResultCommand::HOST_DOWN => mt('monitoring', 'DOWN', 'icinga.state'), + ProcessCheckResultCommand::HOST_UNREACHABLE => mt('monitoring', 'UNREACHABLE', 'icinga.state') + ) : array( + ProcessCheckResultCommand::SERVICE_OK => mt('monitoring', 'OK', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_WARNING => mt('monitoring', 'WARNING', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_CRITICAL => mt('monitoring', 'CRITICAL', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_UNKNOWN => mt('monitoring', 'UNKNOWN', 'icinga.state') + ) + ) + ); + $this->addElement( + 'text', + 'output', + array( + 'required' => true, + 'label' => mt('monitoring', 'Output'), + 'description' => mt('monitoring', 'The plugin output of this check result') + ) + ); + $this->addElement( + 'text', + 'perfdata', + array( + 'allowEmpty' => true, + 'label' => mt('monitoring', 'Performance Data'), + 'description' => mt( + 'monitoring', + 'The performance data of this check result. Leave empty' + . ' if this check result has no performance data' + ) + ) + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Web\Form::onSuccess() For the method documentation. + */ + public function onSuccess() + { + foreach ($this->objects as $object) { + /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ + $command = new ProcessCheckResultCommand(); + $command->setObject($object); + $command->setStatus($this->getValue('status')); + $command->setOutput($this->getValue('output')); + + if ($perfdata = $this->getValue('perfdata')) { + $command->setPerformanceData($perfdata); + } + + $this->getTransport($this->request)->send($command); + } + + Notification::success(mtp( + 'monitoring', + 'Processing check result..', + 'Processing check results..', + count($this->objects) + )); + + return true; + } +} diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index 6adc300d8..6ab717635 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -47,6 +47,13 @@ + +

+ +

translate('Command') ?> - escape($command) ?> + + escape($command) ?> + passive_checks_enabled): ?> + getType() === $object::TYPE_HOST): ?> + icon('reply'); ?> translate('Process check result'); ?> + + icon('reply'); ?> translate('Process check result'); ?> + + Date: Thu, 11 Dec 2014 15:53:12 +0100 Subject: [PATCH 08/13] Fix wrong command being rendered for passive service check results refs #6854 --- .../Command/Renderer/IcingaCommandFileCommandRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php index d2dca183c..2843974ea 100644 --- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php +++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php @@ -126,7 +126,7 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface } else { /** @var \Icinga\Module\Monitoring\Object\Service $object */ $commandString = sprintf( - 'PROCESS_SVC_CHECK_RESULT;%s;%s', + 'PROCESS_SERVICE_CHECK_RESULT;%s;%s', $object->getHost()->getName(), $object->getName() ); From cee68877a9e4938e2f9c4ee82274319d49273a78 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 15:56:23 +0100 Subject: [PATCH 09/13] ProcessCheckResultCommand: Indicate a incompatibility with icinga2 Should be solved by checking the backend's version on runtime --- .../Monitoring/Command/Object/ProcessCheckResultCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php index 9866aeb52..8e3155de5 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php @@ -34,7 +34,7 @@ class ProcessCheckResultCommand extends ObjectCommand /** * Host unreachable */ - const HOST_UNREACHABLE = 2; + const HOST_UNREACHABLE = 2; // TODO: Icinga 2.x does not support submitting results with this state, yet /** * Service ok From e63252cb049816e0fd0960f1159293f5c1649c13 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 18:00:36 +0100 Subject: [PATCH 10/13] Fix that the RuntimeVariables helper cant handle missing information fixes #7905 --- .../views/helpers/RuntimeVariables.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/views/helpers/RuntimeVariables.php b/modules/monitoring/application/views/helpers/RuntimeVariables.php index fa9b639a8..556bd43ad 100644 --- a/modules/monitoring/application/views/helpers/RuntimeVariables.php +++ b/modules/monitoring/application/views/helpers/RuntimeVariables.php @@ -27,12 +27,24 @@ class Zend_View_Helper_RuntimeVariables extends Zend_View_Helper_Abstract public function create(stdClass $result) { $out = new stdClass(); - $out->total_hosts = $result->total_hosts; - $out->total_scheduled_hosts = $result->total_scheduled_hosts; - $out->total_services = $result->total_services; - $out->total_scheduled_services = $result->total_scheduled_services; - $out->average_services_per_host = $result->total_services / $result->total_hosts; - $out->average_scheduled_services_per_host = $result->total_scheduled_services / $result->total_scheduled_hosts; + $out->total_hosts = isset($result->total_hosts) + ? $result->total_hosts + : 0; + $out->total_scheduled_hosts = isset($result->total_scheduled_hosts) + ? $result->total_scheduled_hosts + : 0; + $out->total_services = isset($result->total_services) + ? $result->total_services + : 0; + $out->total_scheduled_services = isset($result->total_scheduled_services) + ? $result->total_scheduled_services + : 0; + $out->average_services_per_host = $out->total_hosts > 0 + ? $out->total_services / $out->total_hosts + : 0; + $out->average_scheduled_services_per_host = $out->total_scheduled_hosts > 0 + ? $out->total_scheduled_services / $out->total_scheduled_hosts + : 0; return $out; } From 87664ffef9414e4344e7037de53a9ac9784be5f8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Dec 2014 10:38:21 +0100 Subject: [PATCH 11/13] Use the Host and Service object class helpers instead of MonitoringState This also ensures that all state names that are shown to the user are properly translated. refs #7996 --- .../application/views/helpers/MonitoringState.php | 9 ++++++--- .../application/views/scripts/list/hosts.phtml | 6 ++++-- .../views/scripts/list/servicegrid.phtml | 7 ++++++- .../application/views/scripts/list/services.phtml | 10 ++++++---- .../views/scripts/show/components/header.phtml | 13 ++++++++++--- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/modules/monitoring/application/views/helpers/MonitoringState.php b/modules/monitoring/application/views/helpers/MonitoringState.php index 4db1a7a91..13bd93ea7 100644 --- a/modules/monitoring/application/views/helpers/MonitoringState.php +++ b/modules/monitoring/application/views/helpers/MonitoringState.php @@ -3,7 +3,7 @@ // {{{ICINGA_LICENSE_HEADER}}} /** - * @deprecated Crap. + * @deprecated Most of these helpers are currently only used in the MultiController, which is probably obsolete */ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract { @@ -11,7 +11,7 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract private $hoststates = array('up', 'down', 'unreachable', 99 => 'pending', null => 'pending'); /** - * @deprecated The host or service object must know it's possible states. + * @deprecated Not used anywhere. */ public function monitoringState($object, $type = 'service') { @@ -22,6 +22,9 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract } } + /** + * @deprecated Not used anywhere. + */ public function monitoringStateById($id, $type = 'service') { if ($type === 'service') { @@ -91,7 +94,7 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract } /** - * @deprecated Not translated. + * @deprecated Not used anywhere. */ public function getStateTitle($object, $type) { diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 588d39712..7f3e73b0b 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -1,4 +1,6 @@ getHelper('MonitoringState'); if ($this->compact): ?> @@ -79,8 +81,8 @@ if ($hosts->count() === 0) { ?> - - monitoringState($host, 'host')) ?>
+ + host_state, true)); ?>
host_state !== 99): ?> prefixedTimeSince($host->host_last_state_change, true) ?> host_state > 0 && (int) $host->host_state_type === 0): ?> diff --git a/modules/monitoring/application/views/scripts/list/servicegrid.phtml b/modules/monitoring/application/views/scripts/list/servicegrid.phtml index 19aef5d64..dd9be0394 100644 --- a/modules/monitoring/application/views/scripts/list/servicegrid.phtml +++ b/modules/monitoring/application/views/scripts/list/servicegrid.phtml @@ -1,3 +1,8 @@ + compact): ?>
tabs; ?> @@ -63,7 +68,7 @@ $hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . ' + )); ?>" title="escape($service->service_output); ?>" class="state_service_state); ?> service_handled ? 'handled' : ''; ?>"> · diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 2ea125527..2922abff5 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -1,4 +1,7 @@ getHelper('MonitoringState'); $selfUrl = 'monitoring/list/services'; @@ -54,9 +57,8 @@ foreach ($services as $service): $serviceStateName = strtolower($this->util()->getServiceStateName($service->service_state)); ?> - - translate(strtoupper($helper->monitoringState($service, 'service'))) ?>
- + + 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): ?>
@@ -106,7 +108,7 @@ foreach ($services as $service): service_display_name ?>showHost): ?> on host_name; ?> host_state != 0): ?> - (monitoringState($service, 'host')); ?>) + (host_state, true)); ?>)

escape(substr(strip_tags($service->service_output), 0, 10000)); ?>

diff --git a/modules/monitoring/application/views/scripts/show/components/header.phtml b/modules/monitoring/application/views/scripts/show/components/header.phtml index a2c835e4a..c44602260 100644 --- a/modules/monitoring/application/views/scripts/show/components/header.phtml +++ b/modules/monitoring/application/views/scripts/show/components/header.phtml @@ -1,9 +1,16 @@ -getType() === $object::TYPE_SERVICE ?> +getType() === $object::TYPE_SERVICE; + +?> compact): ?> - + - + diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index c765b41be..a9516aab1 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -1,3 +1,10 @@ + + compact): ?>
tabs ?> @@ -62,22 +69,22 @@ case 'hard_state': $icon = $isService ? 'service' : 'host'; $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output; - $stateName = ( + $stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); + $title = strtoupper( $isService - ? strtolower($this->util()->getServiceStateName($event->state)) - : strtolower($this->util()->getHostStateName($event->state)) + ? Service::getStateText($event->state, true) + : Host::getStateText($event->state, true) ); - $title = strtoupper($stateName); // TODO: Should be translatable! break; case 'soft_state': $icon = 'lightbulb'; $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output; - $stateName = ( + $stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); + $title = strtoupper( $isService - ? strtolower($this->util()->getServiceStateName($event->state)) - : strtolower($this->util()->getHostStateName($event->state)) + ? Service::getStateText($event->state, true) + : Host::getStateText($event->state, true) ); - $title = strtoupper($stateName); // TODO: Should be translatable! break; case 'dt_start': $icon = 'starttime'; diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 7f3e73b0b..debef375c 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -43,7 +43,7 @@ if ($hosts->count() === 0) {
util()->getHostStateName($host->host_state)); + $hostStateName = Host::getStateText($host->host_state); $hostLink = $this->href('monitoring/host/show', array('host' => $host->host_name)); $icons = array(); diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index 365d32f56..845effbc5 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -1,3 +1,10 @@ + + compact): ?>
tabs ?> @@ -36,13 +43,13 @@ foreach ($notifications as $notification): 'host' => $notification->host, 'service' => $notification->service )); - $stateName = strtolower($this->util()->getServiceStateName($notification->notification_state)); + $stateName = Service::getStateText($notification->notification_state); } else { $isService = false; $href = $this->href('monitoring/show/host', array( 'host' => $notification->host )); - $stateName = strtolower($this->util()->getHostStateName($notification->notification_state)); + $stateName = Host::getStateText($notification->notification_state); } ?>
diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 2922abff5..bb2953e73 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -54,7 +54,7 @@ foreach ($services as $service): 'host' => $service->host_name, ) ); - $serviceStateName = strtolower($this->util()->getServiceStateName($service->service_state)); + $serviceStateName = Service::getStateText($service->service_state); ?>
> translate($this->util()->getHostStateName($object->host_state)) ?>
prefixedTimeSince($object->host_last_state_change, true) ?> @@ -15,7 +22,7 @@
translate($this->util()->getServiceStateName($object->service_state)) ?>
prefixedTimeSince($object->service_last_state_change, true) ?> From 7987fb3f5a9f4f8728d15038b6682b078bc4097f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Dec 2014 12:22:20 +0100 Subject: [PATCH 12/13] Use the Host and Service object class helpers instead of the Util view helper This also ensures that all state names that are shown to the user are properly translated. refs #7996 --- application/views/helpers/Util.php | 60 ------------------- .../views/scripts/list/downtimes.phtml | 11 +++- .../views/scripts/list/eventhistory.phtml | 23 ++++--- .../views/scripts/list/hosts.phtml | 2 +- .../views/scripts/list/notifications.phtml | 11 +++- .../views/scripts/list/services.phtml | 2 +- .../scripts/show/components/header.phtml | 4 +- .../views/scripts/show/history.phtml | 33 +++++----- 8 files changed, 55 insertions(+), 91 deletions(-) diff --git a/application/views/helpers/Util.php b/application/views/helpers/Util.php index ccc3e8e1c..f3e41244f 100644 --- a/application/views/helpers/Util.php +++ b/application/views/helpers/Util.php @@ -63,64 +63,4 @@ class Zend_View_Helper_Util extends Zend_View_Helper_Abstract } return date('H:i d.m.Y', $timestamp); } - - /** - * @deprecated Not used. This is monitoring module stuff. - */ - public static function getHostStateClassName($state) - { - $class = 'unknown'; - switch ($state) { - case null: - $class = 'error'; - break; - case 0: - $class = 'ok'; - break; - case 1: - case 2: - $class = 'error'; - break; - } - return $class; - } - - /** - * @deprecated Crap. This is monitoring module stuff. - */ - public static function getHostStateName($state) - { - $states = array( - 0 => 'UP', - 1 => 'DOWN', - 2 => 'UNREACHABLE', - 3 => 'UNKNOWN', - 4 => 'PENDING', // fake - 99 => 'PENDING' // fake - ); - if (isset($states[$state])) { - return $states[$state]; - } - return sprintf('OUT OF BOUNDS (%s)', var_export($state, 1)); - } - - /** - * @deprecated Crap. This is monitoring module stuff. - */ - public static function getServiceStateName($state) - { - if ($state === null) { $state = 3; } // really? - $states = array( - 0 => 'OK', - 1 => 'WARNING', - 2 => 'CRITICAL', - 3 => 'UNKNOWN', - 4 => 'PENDING', // fake - 99 => 'PENDING' // fake - ); - if (isset($states[$state])) { - return $states[$state]; - } - return sprintf('OUT OF BOUND (%d)' . $state, (int) $state); - } } diff --git a/modules/monitoring/application/views/scripts/list/downtimes.phtml b/modules/monitoring/application/views/scripts/list/downtimes.phtml index a1aba403d..37b34fe5e 100644 --- a/modules/monitoring/application/views/scripts/list/downtimes.phtml +++ b/modules/monitoring/application/views/scripts/list/downtimes.phtml @@ -1,3 +1,10 @@ + + compact): ?>
tabs->render($this); ?> @@ -24,9 +31,9 @@ service)) { - $stateName = strtolower($this->util()->getServiceStateName($downtime->service_state)); + $stateName = Service::getStateText($downtime->service_state); } else { - $stateName = strtolower($this->util()->getHostStateName($downtime->host_state)); + $stateName = Host::getStateText($downtime->host_state); } ?>
diff --git a/modules/monitoring/application/views/scripts/show/components/header.phtml b/modules/monitoring/application/views/scripts/show/components/header.phtml index c44602260..ccf7d2d5e 100644 --- a/modules/monitoring/application/views/scripts/show/components/header.phtml +++ b/modules/monitoring/application/views/scripts/show/components/header.phtml @@ -12,7 +12,7 @@ $showService = $object->getType() === $object::TYPE_SERVICE;
> - translate($this->util()->getHostStateName($object->host_state)) ?>
+ host_state, true)); ?>
prefixedTimeSince($object->host_last_state_change, true) ?>
escape($object->host_name) ?>getType() === $object::TYPE_SERVICE;
- translate($this->util()->getServiceStateName($object->service_state)) ?>
+ service_state, true)); ?>
prefixedTimeSince($object->service_last_state_change, true) ?>
translate('Service') ?>: escape($object->service_description) ?> diff --git a/modules/monitoring/application/views/scripts/show/history.phtml b/modules/monitoring/application/views/scripts/show/history.phtml index c28c59762..5b922d4a0 100644 --- a/modules/monitoring/application/views/scripts/show/history.phtml +++ b/modules/monitoring/application/views/scripts/show/history.phtml @@ -1,3 +1,10 @@ + +
render('show/components/header.phtml'); ?>

translate('This Object\'s Event History'); ?>

@@ -33,11 +40,7 @@ function contactsLink($match, $view) { case 'notify': $icon = 'notification'; $title = $this->translate('Notification'); - $stateClass = ( - $isService - ? strtolower($this->util()->getServiceStateName($event->state)) - : strtolower($this->util()->getHostStateName($event->state)) - ); + $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $msg = preg_replace_callback( '/^\[([^\]]+)\]/', @@ -87,23 +90,23 @@ function contactsLink($match, $view) { break; case 'hard_state': $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); - $stateClass = ( - $isService - ? strtolower($this->util()->getServiceStateName($event->state)) - : strtolower($this->util()->getHostStateName($event->state)) - ); + $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $icon = 'attention-alt'; - $title = strtoupper($stateClass); // TODO: Should be translatable! + $title = strtoupper( + $isService + ? Service::getStateText($event->state) + : Host::getStateText($event->state) + ); break; case 'soft_state': $icon = 'spinner'; $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); - $stateClass = ( + $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); + $title = strtoupper( $isService - ? strtolower($this->util()->getServiceStateName($event->state)) - : strtolower($this->util()->getHostStateName($event->state)) + ? Service::getStateText($event->state) + : Host::getStateText($event->state) ); - $title = strtoupper($stateClass); // TODO: Should be translatable! break; case 'dt_start': $icon = 'downtime_start'; From b307fe27913a8cf587c9fd498810f4da43c7fa75 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Dec 2014 12:44:31 +0100 Subject: [PATCH 13/13] Reorder use statements to be in alphabetical order --- modules/monitoring/application/controllers/HostController.php | 2 +- modules/monitoring/application/controllers/HostsController.php | 2 +- .../monitoring/application/controllers/ServiceController.php | 2 +- .../monitoring/application/controllers/ServicesController.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 184e05a4c..ab62c3756 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -2,9 +2,9 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm; use Icinga\Module\Monitoring\Object\Host; diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 4aa090572..4944cc237 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -4,10 +4,10 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm; diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index 70aa9e519..06417cc6e 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -2,9 +2,9 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm; use Icinga\Module\Monitoring\Object\Service; diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index bbe2024d7..cdf86f460 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -4,10 +4,10 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;