Implement support for non-standard "multi" performance data.

Refs #5082
This commit is contained in:
Gunnar Beutner 2013-11-17 03:29:43 +01:00
parent d95c6c7d85
commit 0f28e55925
4 changed files with 25 additions and 0 deletions

View 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);

View 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;

View 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;
}

View 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()