From: Michael Friedrich Date: Wed, 2 Apr 2014 12:43:40 +0000 (+0200) Subject: CompatUtility: Fix host 2d_coords. X-Git-Tag: v0.0.10~238 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a05c31cda2c8b579b8ef3eccb0f45fcbbbb41aee;p=icinga2 CompatUtility: Fix host 2d_coords. Fixes #5917 --- diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 8f3ecc738..281faeaff 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -347,11 +347,6 @@ Value HostsTable::NotesUrlAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr custom = host->GetCustom(); - - if (!custom) - return Empty; - return CompatUtility::GetCustomAttributeConfig(host, "notes_url"); } @@ -1066,20 +1061,7 @@ Value HostsTable::X2dAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr custom = host->GetCustom(); - - if (!custom) - return Empty; - - String coords = custom->Get("2d_coords"); - - std::vector tokens; - boost::algorithm::split(tokens, coords, boost::is_any_of(",")); - - if (tokens.size() != 2) - return Empty; - - return tokens[0]; + return CompatUtility::GetHost2dCoordX(host); } Value HostsTable::Y2dAccessor(const Value& row) @@ -1089,20 +1071,7 @@ Value HostsTable::Y2dAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr custom = host->GetCustom(); - - if (!custom) - return Empty; - - String coords = custom->Get("2d_coords"); - - std::vector tokens; - boost::algorithm::split(tokens, coords, boost::is_any_of(",")); - - if (tokens.size() != 2) - return Empty; - - return tokens[1]; + return CompatUtility::GetHost2dCoordY(host); } Value HostsTable::LatencyAccessor(const Value& row) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 8e32d2f80..501216184 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -111,11 +111,18 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host) Host2dCoords bag; if (custom) { - bag.have_2d_coords = (custom->Get("x_2d") && custom->Get("y_2d") ? 1 : 0); + String coords = custom->Get("2d_coords"); + bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0); + + std::vector tokens; + boost::algorithm::split(tokens, coords, boost::is_any_of(",")); + + if (tokens.size() != 2) + bag.have_2d_coords = 0; if (bag.have_2d_coords == 1) { - bag.x_2d = custom->Get("x_2d"); - bag.y_2d = custom->Get("y_2d"); + bag.x_2d = tokens[0]; + bag.y_2d = tokens[1]; } } else { bag.have_2d_coords = 0; @@ -124,6 +131,26 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host) return bag; } +String CompatUtility::GetHost2dCoordX(const Host::Ptr& host) +{ + Host2dCoords bag = GetHost2dCoords(host); + + if (bag.have_2d_coords == 0) + return Empty; + + return bag.x_2d; +} + +String CompatUtility::GetHost2dCoordY(const Host::Ptr& host) +{ + Host2dCoords bag = GetHost2dCoords(host); + + if (bag.have_2d_coords == 0) + return Empty; + + return bag.y_2d; +} + int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) { ASSERT(host->OwnsLock()); diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index 34f1815d2..8c64eee55 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -59,6 +59,8 @@ public: static String GetHostAddress(const Host::Ptr& host); static String GetHostAddress6(const Host::Ptr& host); static Host2dCoords GetHost2dCoords(const Host::Ptr& host); + static String GetHost2dCoordX(const Host::Ptr& host); + static String GetHost2dCoordY(const Host::Ptr& host); static int GetHostNotifyOnDown(const Host::Ptr& host); static int GetHostNotifyOnUnreachable(const Host::Ptr& host);