]> granicus.if.org Git - icinga2/commitdiff
Implement support for non-standard "multi" performance data.
authorGunnar Beutner <gunnar@beutner.name>
Sun, 17 Nov 2013 02:29:43 +0000 (03:29 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 17 Nov 2013 02:29:43 +0000 (03:29 +0100)
Refs #5082

lib/base/qstring.cpp
lib/base/qstring.h
lib/icinga/pluginutility.cpp
test/icinga-perfdata.cpp

index c3ca495acf3b97eb10425e170864e4090488d772..180fe532f5c0f21dea39c3267ebd6310528dc49d 100644 (file)
@@ -139,6 +139,11 @@ size_t String::Find(const String& str, size_t pos) const
        return m_Data.find(str, pos);
 }
 
+size_t String::RFind(const String& str, size_t pos) const
+{
+       return m_Data.rfind(str, pos);
+}
+
 size_t String::FindFirstOf(const char *s, size_t pos) const
 {
        return m_Data.find_first_of(s, pos);
index 74f0202c0444f6549043953748bab0be7991c23d..ad2dd34754c75e930b239c150984e7b0a1eaf187 100644 (file)
@@ -82,6 +82,7 @@ public:
        std::string& GetData(void);
 
        size_t Find(const String& str, size_t pos = 0) const;
+       size_t RFind(const String& str, size_t pos = NPos) const;
        size_t FindFirstOf(const char *s, size_t pos = 0) const;
        size_t FindFirstOf(char ch, size_t pos = 0) const;
        size_t FindFirstNotOf(const char *s, size_t pos = 0) const;
index 069a88079864604f6045e903f505b335747b4a84..e1657774a26bd64b4c4cdf8bd471d35e706d6bbf 100644 (file)
@@ -91,6 +91,7 @@ Value PluginUtility::ParsePerfdata(const String& perfdata)
                Dictionary::Ptr result = make_shared<Dictionary>();
        
                size_t begin = 0;
+               String multi_prefix;
                
                for (;;) {
                        size_t eqp = perfdata.FindFirstOf('=', begin);
@@ -103,6 +104,11 @@ Value PluginUtility::ParsePerfdata(const String& perfdata)
                        if (key.GetLength() > 2 && key[0] == '\'' && key[key.GetLength() - 1] == '\'')
                                key = key.SubStr(1, key.GetLength() - 2);
 
+                       size_t multi_index = key.RFind("::");
+
+                       if (multi_index != String::NPos)
+                               multi_prefix = "";
+
                        size_t spq = perfdata.FindFirstOf(' ', eqp);
 
                        if (spq == String::NPos)
@@ -110,8 +116,14 @@ Value PluginUtility::ParsePerfdata(const String& perfdata)
 
                        String value = perfdata.SubStr(eqp + 1, spq - eqp - 1);
 
+                       if (!multi_prefix.IsEmpty())
+                               key = multi_prefix + "::" + key;
+
                        result->Set(key, PerfdataValue::Parse(value));
 
+                       if (multi_index != String::NPos)
+                               multi_prefix = key.SubStr(0, multi_index);
+
                        begin = spq + 1;
                }
 
index 679480634ec4f9d4105b0d3c38695f083ed44b17..80a8c1e3e18517168af4f3d6580e114cd7ea09bd 100644 (file)
@@ -99,4 +99,11 @@ BOOST_AUTO_TEST_CASE(invalid)
        BOOST_CHECK(PluginUtility::ParsePerfdata("test=123456;10%;20%") == "test=123456;10%;20%");
 }
 
+BOOST_AUTO_TEST_CASE(multi)
+{
+       Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test::a=3 b=4");
+       BOOST_CHECK(pd->Get("test::a") == 3);
+       BOOST_CHECK(pd->Get("test::b") == 4);
+}
+
 BOOST_AUTO_TEST_SUITE_END()