Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Call to a member function toString() when navigating to service templates from rendered previews #2554

Closed
mocdaniel opened this issue Jun 23, 2022 · 1 comment
Assignees
Labels
Milestone

Comments

@mocdaniel
Copy link

Expected Behavior

When navigating to a service template from a rendered preview (e.g. of a service set or apply rule), the Modify tab of said service template should open.

Current Behavior

When navigating to a service template from a rendered preview (e.g. of a service set or apply rule) by clicking the linked

import "this-template-crashes"

the following stack trace is displayed:

Uncaught Error: Call to a member function toString() on null in /usr/share/icingaweb2/modules/director/application/controllers/ServiceController.php:254
Stack trace:
#0 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectController.php(497): Icinga\Module\Director\Controllers\ServiceController->loadObject()
#1 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectController.php(90): Icinga\Module\Director\Web\Controller\ObjectController->loadOptionalObject()
#2 /usr/share/icingaweb2/modules/director/application/controllers/ServiceController.php(46): Icinga\Module\Director\Web\Controller\ObjectController->init()
#3 /usr/share/php/Icinga/Web/Controller/ActionController.php(170): Icinga\Module\Director\Controllers\ServiceController->init()
#4 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(59): Icinga\Web\Controller\ActionController->__construct()
#5 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch()
#6 /usr/share/php/Icinga/Application/Web.php(304): Zend_Controller_Front->dispatch()
#7 /usr/share/php/Icinga/Application/webrouter.php(109): Icinga\Application\Web->dispatch()
#8 /usr/share/icingaweb2/public/index.php(4): require_once('...')
#9 {main}
thrown

#0 [internal function]: Icinga\Application\Web->Icinga\Application\{closure}()
#1 {main}

Possible Solution

From my observations, it's probably some bug connected to the recently introduced UUIDs - when editing a service template 'the normal way', the URL looks like this:

http://10.77.14.179/icingaweb2/director/services/templates#!/icingaweb2/director/service/edit?uuid=fc11b6b9-5e88-4fed-b9f0-a7320f00bdce

While the navigation process described above leads to a URL like this:

http://10.77.14.179/icingaweb2/director/services/applyrules#!/icingaweb2/director/service?name=generic-service

Steps to Reproduce (for bugs)

  1. Create a generic service template with arbitrary configuration
  2. Create a new apply rule or service (within a service set or standalone)
  3. Open the 'preview' tab of this service
  4. Click the linked template

Your Environment

  • Director version (System - About): v1.9.1
  • Icinga Web 2 version and modules (System - About): v2.9.6 / v2.10.1
  • Icinga 2 version (icinga2 --version): v2.13.3
  • Operating System and version: RHEL8.5
  • Webserver, PHP versions: httpd, PHP v7.4.19 / v8.0.13
@Thomas-Gelf
Copy link
Contributor

Thanks for reporting this, it is related to #2487. As a workaround please use the following patch:

diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php
index ec9545ef..34d698a6 100644
--- a/application/controllers/ServiceController.php
+++ b/application/controllers/ServiceController.php
@@ -251,6 +251,11 @@ class ServiceController extends ObjectController
 
         $key = $this->getLegacyKey();
         $uuid = UuidLookup::findServiceUuid($this->db(), $this->getBranch(), 'object', $key, $this->host, $this->set);
+        foreach (['apply', 'template'] as $type) {
+            if ($uuid === null) {
+                $uuid = UuidLookup::findServiceUuid($this->db(), $this->getBranch(), $type, $key, $this->host, $this->set);
+            }
+        }
         $this->params->set('uuid', $uuid->toString());
         parent::loadObject();
     }

The final fix might differ.

@Thomas-Gelf Thomas-Gelf self-assigned this Jun 24, 2022
@Thomas-Gelf Thomas-Gelf added this to the 1.10.0 milestone Jun 24, 2022
Thomas-Gelf added a commit that referenced this issue Jun 24, 2022
...when looking up uuid for legacy key

refs #2487
refs #2554
yhabteab pushed a commit that referenced this issue Oct 6, 2022
yhabteab pushed a commit that referenced this issue Oct 6, 2022
...when looking up uuid for legacy key

refs #2487
refs #2554
Thomas-Gelf added a commit that referenced this issue Oct 6, 2022
Thomas-Gelf added a commit that referenced this issue Oct 6, 2022
...when looking up uuid for legacy key

refs #2487
refs #2554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants