]> granicus.if.org Git - icinga2/commitdiff
CompatUtility: Fix host 2d_coords.
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 2 Apr 2014 12:43:40 +0000 (14:43 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 2 Apr 2014 12:43:40 +0000 (14:43 +0200)
Fixes #5917

components/livestatus/hoststable.cpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.h

index 8f3ecc7382345c735c59629f81b7625f508f1473..281faeaff7514f68edabd765d0b9741a4606488c 100644 (file)
@@ -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<String> 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<String> 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)
index 8e32d2f80fc919066297a8820a05c461dd41fd4b..5012161841d1557e89d492eccd15e9b3441179bc 100644 (file)
@@ -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<String> 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());
index 34f1815d2efae6822c6404bc10d514028eab294f..8c64eee554f1ab2ddfd8daeb80f9cbc15a7d345c 100644 (file)
@@ -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);