From 2366df60570e794c674d2a010817de6bcba05ea0 Mon Sep 17 00:00:00 2001 From: Max Rosin Date: Fri, 19 Oct 2018 15:37:32 +0200 Subject: [PATCH 1/2] Fix the Icinga2 version check for versions with more than 5 characters The previous implementation assumed that every version number will have 5 characters. With the release of 2.10.0 this does not work anymore. The new implementation extracts everything from the second character to the first dash. This should work as long as the version string is in a format like 'v2.10.1-8-gaebe6da'. fixes Icinga#6703 --- lib/methods/icingachecktask.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 0c85de6d4..75f301f5f 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -174,9 +174,12 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes cr->SetState(ServiceWarning); } - /* Return an error if the version is less than specified (optional). */ - String parsedAppVersion = appVersion.SubStr(1,5); + /* Extract the version number of the running Icinga2 instance. + * We assume that appVersion will allways be something like 'v2.10.1-8-gaebe6da' and we want to extract '2.10.1'. */ + int endOfVersionNumber = appVersion.FindFirstOf("-") - 1; + String parsedAppVersion = appVersion.SubStr(1,endOfVersionNumber); + /* Return an error if the version is less than specified (optional). */ if (missingIcingaMinVersion.IsEmpty() && !icingaMinVersion.IsEmpty() && Utility::CompareVersion(icingaMinVersion, parsedAppVersion) < 0) { output += "; Minimum version " + icingaMinVersion + " is not installed."; cr->SetState(ServiceCritical); From 3d45d0bcf6d5f993cdde270a1be6f82e53280395 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 29 Oct 2018 13:45:18 +0100 Subject: [PATCH 2/2] Minor styleguide --- lib/methods/icingachecktask.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 75f301f5f..c5832aebe 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -175,9 +175,10 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes } /* Extract the version number of the running Icinga2 instance. - * We assume that appVersion will allways be something like 'v2.10.1-8-gaebe6da' and we want to extract '2.10.1'. */ + * We assume that appVersion will allways be something like 'v2.10.1-8-gaebe6da' and we want to extract '2.10.1'. + */ int endOfVersionNumber = appVersion.FindFirstOf("-") - 1; - String parsedAppVersion = appVersion.SubStr(1,endOfVersionNumber); + String parsedAppVersion = appVersion.SubStr(1, endOfVersionNumber); /* Return an error if the version is less than specified (optional). */ if (missingIcingaMinVersion.IsEmpty() && !icingaMinVersion.IsEmpty() && Utility::CompareVersion(icingaMinVersion, parsedAppVersion) < 0) {