2013-11-07 13:37:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2017-01-10 15:54:22 +01:00
|
|
|
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
|
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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-05-15 15:51:39 +02:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/pluginutility.hpp"
|
2016-09-07 08:20:51 +02:00
|
|
|
#include <BoostTestTargetConfig.h>
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(icinga_perfdata)
|
|
|
|
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(empty)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("");
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_CHECK(pd->GetLength() == 0);
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(simple)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pdv = PerfdataValue::Parse("test=123456");
|
|
|
|
BOOST_CHECK(pdv->GetLabel() == "test");
|
|
|
|
BOOST_CHECK(pdv->GetValue() == 123456);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
String str = pdv->Format();
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_CHECK(str == "test=123456");
|
|
|
|
}
|
|
|
|
|
2013-11-13 15:42:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(quotes)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("'hello world'=123456");
|
|
|
|
BOOST_CHECK(pd->GetLength() == 1);
|
|
|
|
|
|
|
|
PerfdataValue::Ptr pdv = PerfdataValue::Parse("'hello world'=123456");
|
|
|
|
BOOST_CHECK(pdv->GetLabel() == "hello world");
|
|
|
|
BOOST_CHECK(pdv->GetValue() == 123456);
|
2013-11-13 15:42:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(multiple)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=123456 testB=123456");
|
|
|
|
BOOST_CHECK(pd->GetLength() == 2);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
|
|
|
BOOST_CHECK(str == "testA=123456 testB=123456");
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(uom)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B");
|
2013-11-07 13:37:58 +01:00
|
|
|
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);
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
String str = pv->Format();
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_CHECK(str == "test=123456B");
|
2013-12-17 14:47:19 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
pv = PerfdataValue::Parse("test=1000ms;200;500");
|
2013-12-17 14:47:19 +01:00
|
|
|
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);
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
pv = PerfdataValue::Parse("test=1000ms");
|
2013-12-17 14:47:19 +01:00
|
|
|
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);
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
str = pv->Format();
|
2013-12-17 14:47:19 +01:00
|
|
|
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
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
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
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
BOOST_CHECK(pv->Format() == "test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 17:04:48 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ignore_invalid_warn_crit_min_max)
|
|
|
|
{
|
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456;1000:2000;0:3000;3000;4000");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
BOOST_CHECK(pv->GetValue() == 123456);
|
|
|
|
BOOST_CHECK(pv->GetWarn() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetCrit() == Empty);
|
|
|
|
BOOST_CHECK(pv->GetMin() == 3000);
|
|
|
|
BOOST_CHECK(pv->GetMax() == 4000);
|
|
|
|
|
|
|
|
BOOST_CHECK(pv->Format() == "test=123456");
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(invalid)
|
|
|
|
{
|
2015-03-01 17:04:48 +01:00
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("123456"), boost::exception);
|
2014-09-17 15:38:39 +02:00
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1,23456"), boost::exception);
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 03:29:43 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(multi)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("test::a=3 b=4");
|
|
|
|
BOOST_CHECK(pd->Get(0) == "test::a=3");
|
|
|
|
BOOST_CHECK(pd->Get(1) == "test::b=4");
|
2013-11-17 03:29:43 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|