Icinga2: Icinga 2.11.0 RC1/Icingaweb 2.6.3: Icinga Web 2 does not properly detect Icinga 2

Created on 27 Jul 2019  路  4Comments  路  Source: Icinga/icinga2

Same setup as in #7366 (CentOS 7.6, Icinga 2.11.0 RC1) with Icinga Web 2.6.3.

Works fine in general, but in the "Feature Commands" panel there are checkboxes for "Obsessing over Hosts"/"Obsessing over Services" (and some other features that weren't there before) that result in PHP stack dumps:

#0 /usr/share/icingaweb2/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php(269): Icinga\Module\Monitoring\Command\Transport\CommandTransport->send(Object(Icinga\Module\Monitoring\Command\Instance\ToggleInstanceFeatureCommand))
#1 /usr/share/php/Icinga/Web/Form.php(1161): Icinga\Module\Monitoring\Forms\Command\Instance\ToggleInstanceFeaturesCommandForm->onSuccess()
#2 /usr/share/icingaweb2/modules/monitoring/application/controllers/HealthController.php(99): Icinga\Web\Form->handleRequest()
#3 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Monitoring\Controllers\HealthController->infoAction()
#4 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch(String)
#5 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#6 /usr/share/php/Icinga/Application/Web.php(300): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#7 /usr/share/php/Icinga/Application/webrouter.php(104): Icinga\Application\Web->dispatch()
#8 /usr/share/icingaweb2/public/index.php(4): require_once(String)
#9 {main}
aredb-ido aresetup

Most helpful comment

Had a look at the PHP code that leads to the old features being displayed. This is the part where it goes wrong in ToggleInstanceFeaturesCommandForm.php:

    public function createElements(array $formData = array())
    {
        $notificationDescription = null;
        $isIcinga2 = $this->getBackend()->isIcinga2($this->status->program_version);

        if (! $isIcinga2) {
            if ((bool) $this->status->notifications_enabled) {
                if ($this->hasPermission('monitoring/command/feature/instance')) {

So the observed behaviour happens when $this->getBackend()->isIcinga2($this->status->program_version) does not resolve to true. This is defined in MonitoringBackend.php as

    public function isIcinga2($programVersion = null)
    {
        if ($programVersion === null) {
            $programVersion = $this->select()->from('programstatus', array('program_version'))->fetchOne();
        }
        return (bool) preg_match(
            '/^[vr]2\.\d+\.\d+.*$/',
            $programVersion
        );
    }

Where the regex match expects either a v or an r in the first character of the version string. And the version string in the IDO DB is r2.10.5-1 for 2.10.5 and 2.11.0-0.rc1.1 in 2.11.0 RC1, lacking the first character v or r.

The change that caused this happened in CMakeLists.txt in commit 9f82faa:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ddfa2649..7ad1c95b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,9 +27,6 @@ option (USE_SYSTEMD

 set(HAVE_SYSTEMD ${USE_SYSTEMD})

-file(STRINGS VERSION VERSION_LINE REGEX "^Version: ")
-string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
-
 include(GNUInstallDirs)
 include(InstallConfig)
 include(SetFullDir)
@@ -104,10 +101,17 @@ else()
     string(SUBSTRING ${SPEC_REVISION} 10 ${SPEC_REVISION_LENGTH} SPEC_REVISION)

     set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
+    set(ICINGA2_VERSION "${SPEC_VERSION}")
+  else()
+    # use GIT version as ICINGA2_VERSION
+    string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}")
   endif()
   configure_file(icinga-version.h.cmake icinga-version.h)
 endif()

+# NuGet on Windows requires a semantic versioning, example: 2.10.4.123 (only 4 element, only numeric)
+string(REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION}")
+
 if(WIN32)
   set(Boost_USE_STATIC_LIBS ON)
   # Disabled for linking issues for newer Boost versions, they link against Windows SDKs
@@ -391,7 +395,7 @@ endif()

 set(CPACK_PACKAGE_NAME "Icinga 2")
 set(CPACK_PACKAGE_VENDOR "Icinga GmbH")
-set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
+set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION_SAFE})
 set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")

So I see three ways to fix it:

  • Revert the change in 9f82faa (probably not intended, as the change was there for a reason I assume)
  • Modify lib/db_ido/dbconnection.cpp so that the r (or v) gets inserted when the version string is written to the IDO (might have unwanted side effects I currently can't overview)
  • Modify MonitoringBackend.php in Icinga Web 2 so the prefix character is treated as optional (probably the cleanest way to fix it, with the exception that a new version of Icinga Web 2 is required when Icinga 2.11 in the final version is released).

For a quick fix, I tried the following and it did the trick:

[root@master1 ~]# diff /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php.orig /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php
357c357
<             '/^[vr]2\.\d+\.\d+.*$/',
---
>             '/^[vr]?2\.\d+\.\d+.*$/',

All 4 comments

Sorry, I was in a bit of a hurry yesterday and so here's some additional explanation of the issue and why I'm reporting it here instead of in the Icinga Web 2 project.

With Icinga 2.10.5, the "Feature Commands" panel looked like this:
Screenshot 2019-07-28 at 11 51 26

With 2.11.0 RC1, the panel changed to this:
Screenshot 2019-07-28 at 11 45 46

Same Icinga Web 2 version, same system, everything is unchanged except for the Icinga 2 version. So - without having looked at the code of Icinga Web 2, I admit - my assumption is that there is some way for Icinga Web 2 to detect what features can be enabled or disabled in Icinga 2, and that there is something wrong with that detection mechanism.

The presence of the Nagios 1/Icinga 1 "obsess_over_{hosts, services}" feature selectors indicates that somehow Icinga Web 2 incorrectly assumes that it is talking to an Icinga 1 instance, and since Icinga Web 2 was not upgraded in any way this is most likely an Icinga 2.11.0 RC1 issue.

Had a look at the PHP code that leads to the old features being displayed. This is the part where it goes wrong in ToggleInstanceFeaturesCommandForm.php:

    public function createElements(array $formData = array())
    {
        $notificationDescription = null;
        $isIcinga2 = $this->getBackend()->isIcinga2($this->status->program_version);

        if (! $isIcinga2) {
            if ((bool) $this->status->notifications_enabled) {
                if ($this->hasPermission('monitoring/command/feature/instance')) {

So the observed behaviour happens when $this->getBackend()->isIcinga2($this->status->program_version) does not resolve to true. This is defined in MonitoringBackend.php as

    public function isIcinga2($programVersion = null)
    {
        if ($programVersion === null) {
            $programVersion = $this->select()->from('programstatus', array('program_version'))->fetchOne();
        }
        return (bool) preg_match(
            '/^[vr]2\.\d+\.\d+.*$/',
            $programVersion
        );
    }

Where the regex match expects either a v or an r in the first character of the version string. And the version string in the IDO DB is r2.10.5-1 for 2.10.5 and 2.11.0-0.rc1.1 in 2.11.0 RC1, lacking the first character v or r.

The change that caused this happened in CMakeLists.txt in commit 9f82faa:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ddfa2649..7ad1c95b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,9 +27,6 @@ option (USE_SYSTEMD

 set(HAVE_SYSTEMD ${USE_SYSTEMD})

-file(STRINGS VERSION VERSION_LINE REGEX "^Version: ")
-string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
-
 include(GNUInstallDirs)
 include(InstallConfig)
 include(SetFullDir)
@@ -104,10 +101,17 @@ else()
     string(SUBSTRING ${SPEC_REVISION} 10 ${SPEC_REVISION_LENGTH} SPEC_REVISION)

     set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
+    set(ICINGA2_VERSION "${SPEC_VERSION}")
+  else()
+    # use GIT version as ICINGA2_VERSION
+    string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}")
   endif()
   configure_file(icinga-version.h.cmake icinga-version.h)
 endif()

+# NuGet on Windows requires a semantic versioning, example: 2.10.4.123 (only 4 element, only numeric)
+string(REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION}")
+
 if(WIN32)
   set(Boost_USE_STATIC_LIBS ON)
   # Disabled for linking issues for newer Boost versions, they link against Windows SDKs
@@ -391,7 +395,7 @@ endif()

 set(CPACK_PACKAGE_NAME "Icinga 2")
 set(CPACK_PACKAGE_VENDOR "Icinga GmbH")
-set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
+set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION_SAFE})
 set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")

So I see three ways to fix it:

  • Revert the change in 9f82faa (probably not intended, as the change was there for a reason I assume)
  • Modify lib/db_ido/dbconnection.cpp so that the r (or v) gets inserted when the version string is written to the IDO (might have unwanted side effects I currently can't overview)
  • Modify MonitoringBackend.php in Icinga Web 2 so the prefix character is treated as optional (probably the cleanest way to fix it, with the exception that a new version of Icinga Web 2 is required when Icinga 2.11 in the final version is released).

For a quick fix, I tried the following and it did the trick:

[root@master1 ~]# diff /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php.orig /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php
357c357
<             '/^[vr]2\.\d+\.\d+.*$/',
---
>             '/^[vr]?2\.\d+\.\d+.*$/',

Thanks for the heads up @peteeckel 馃憤 Since we're about to release version 2.7.0 today, I made a PR for this: https://github.com/Icinga/icingaweb2/pull/3881

Thanks. I'd prefer not to have those r and v variants anyways, seems that the Windows version semantics for the RC broke things here. Web 2.7.0 has a patch for this, so we're safe in the future.

Was this page helpful?
0 / 5 - 0 ratings