2013-11-07 13:37:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-01-09 00:32:11 +01:00
|
|
|
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) *
|
2013-11-07 13:37:58 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "icinga/pluginutility.cpp"
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(icinga_perfdata)
|
|
|
|
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(empty)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("");
|
|
|
|
BOOST_CHECK(pd->GetLength() == 0);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(simple)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456");
|
|
|
|
BOOST_CHECK(pd->Get("test") == 123456);
|
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
|
|
|
BOOST_CHECK(str == "test=123456");
|
|
|
|
}
|
|
|
|
|
2013-11-13 15:42:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(quotes)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("'hello world'=123456");
|
|
|
|
BOOST_CHECK(pd->Get("hello world") == 123456);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(multiple)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("testA=123456 testB=123456");
|
|
|
|
BOOST_CHECK(pd->Get("testA") == 123456);
|
|
|
|
BOOST_CHECK(pd->Get("testB") == 123456);
|
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
|
|
|
BOOST_CHECK(str == "testA=123456 testB=123456");
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(uom)
|
|
|
|
{
|
2013-11-08 08:39:05 +01:00
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B");
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
PerfdataValue::Ptr pv = pd->Get("test");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
|
|
|
BOOST_CHECK(pv->GetValue() == 123456);
|
|
|
|
BOOST_CHECK(!pv->GetCounter());
|
|
|
|
BOOST_CHECK(pv->GetUnit() == "bytes");
|
|
|
|
BOOST_CHECK(pv->GetCrit() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetWarn() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetMin() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetMax() == Empty);
|
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_CHECK(str == "test=123456B");
|
2013-12-17 14:47:19 +01:00
|
|
|
|
|
|
|
pd = PluginUtility::ParsePerfdata("test=1000ms;200;500");
|
|
|
|
BOOST_CHECK(pd);
|
|
|
|
|
|
|
|
pv = pd->Get("test");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
|
|
|
BOOST_CHECK(pv->GetValue() == 1);
|
|
|
|
BOOST_CHECK(pv->GetUnit() == "seconds");
|
|
|
|
BOOST_CHECK(pv->GetWarn() == 0.2);
|
|
|
|
BOOST_CHECK(pv->GetCrit() == 0.5);
|
|
|
|
|
|
|
|
pd = PluginUtility::ParsePerfdata("test=1000ms");
|
|
|
|
BOOST_CHECK(pd);
|
|
|
|
|
|
|
|
pv = pd->Get("test");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
|
|
|
BOOST_CHECK(pv->GetValue() == 1);
|
|
|
|
BOOST_CHECK(pv->GetUnit() == "seconds");
|
|
|
|
BOOST_CHECK(pv->GetCrit() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetWarn() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetMin() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetMax() == Empty);
|
|
|
|
|
|
|
|
str = PluginUtility::FormatPerfdata(pd);
|
|
|
|
BOOST_CHECK(str == "test=1s");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 18:21:55 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(warncritminmax)
|
2013-11-07 13:37:58 +01:00
|
|
|
{
|
2013-11-08 08:39:05 +01:00
|
|
|
Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
PerfdataValue::Ptr pv = pd->Get("test");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
|
|
|
BOOST_CHECK(pv->GetValue() == 123456);
|
|
|
|
BOOST_CHECK(!pv->GetCounter());
|
|
|
|
BOOST_CHECK(pv->GetUnit() == "bytes");
|
|
|
|
BOOST_CHECK(pv->GetWarn() == 1000);
|
|
|
|
BOOST_CHECK(pv->GetCrit() == 2000);
|
2013-11-07 18:21:55 +01:00
|
|
|
BOOST_CHECK(pv->GetMin() == 3000);
|
|
|
|
BOOST_CHECK(pv->GetMax() == 4000);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_CHECK(str == "test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(invalid)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(PluginUtility::ParsePerfdata("test=1,23456") == "test=1,23456");
|
|
|
|
BOOST_CHECK(PluginUtility::ParsePerfdata("test=123456;10%;20%") == "test=123456;10%;20%");
|
|
|
|
}
|
|
|
|
|
2013-11-17 03:29:43 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|