diff --git a/lib/base/qstring.cpp b/lib/base/qstring.cpp index c3ca495ac..180fe532f 100644 --- a/lib/base/qstring.cpp +++ b/lib/base/qstring.cpp @@ -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); diff --git a/lib/base/qstring.h b/lib/base/qstring.h index 74f0202c0..ad2dd3475 100644 --- a/lib/base/qstring.h +++ b/lib/base/qstring.h @@ -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; diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index 069a88079..e1657774a 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -91,6 +91,7 @@ Value PluginUtility::ParsePerfdata(const String& perfdata) Dictionary::Ptr result = make_shared(); 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; } diff --git a/test/icinga-perfdata.cpp b/test/icinga-perfdata.cpp index 679480634..80a8c1e3e 100644 --- a/test/icinga-perfdata.cpp +++ b/test/icinga-perfdata.cpp @@ -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()