Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/icinga/checkresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ double CheckResult::CalculateLatency() const

return latency;
}

void CheckResult::SetPerformanceData(const Array::Ptr& value, bool suppress_events, const Value& cookie)
{
if (value) {
value->Freeze();
}
ObjectImpl<CheckResult>::SetPerformanceData(value, suppress_events, cookie);
}
1 change: 1 addition & 0 deletions lib/icinga/checkresult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CheckResult final : public ObjectImpl<CheckResult>

double CalculateExecutionTime() const;
double CalculateLatency() const;
void SetPerformanceData(const Array::Ptr& value, bool suppress_events = false, const Value& cookie = Empty) override;
};

}
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/checkresult.ti
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CheckResult
[state, enum] ServiceState "state";
[state, enum] ServiceState previous_hard_state;
[state] String output;
[state] Array::Ptr performance_data;
[state, set_virtual] Array::Ptr performance_data;

[state] bool active {
default {{{ return true; }}}
Expand Down
2 changes: 0 additions & 2 deletions lib/icinga/pluginutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata, bool normalize)

std::ostringstream result;

ObjectLock olock(perfdata);

bool first = true;
for (const Value& pdv : perfdata) {
if (!first)
Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/elasticsearchwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Ch
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

if (perfdata) {
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/gelfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
Array::Ptr perfdata = cr->GetPerformanceData();

if (perfdata) {
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/graphitewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ void GraphiteWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&

CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/influxdbcommonwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ void InfluxdbCommonWriter::CheckResultHandler(const Checkable::Ptr& checkable, c
double ts = cr->GetExecutionEnd();

if (Array::Ptr perfdata = cr->GetPerformanceData()) {
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/opentsdbwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ void OpenTsdbWriter::AddPerfdata(const Checkable::Ptr& checkable, const String&

CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand Down
1 change: 0 additions & 1 deletion lib/perfdata/otlpmetricswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ void OTLPMetricsWriter::CheckResultHandler(const Checkable::Ptr& checkable, cons
auto endTime = cr->GetExecutionEnd();

Array::Ptr perfdata = cr->GetPerformanceData();
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
if (val.IsObjectType<PerfdataValue>()) {
Expand Down
5 changes: 5 additions & 0 deletions test/icinga-perfdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE(quotes)
BOOST_AUTO_TEST_CASE(multiple)
{
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=123456 testB=123456");
pd->Freeze();
Comment thread
julianbrost marked this conversation as resolved.
BOOST_CHECK_EQUAL(pd->GetLength(), 2);

String str = PluginUtility::FormatPerfdata(pd);
Expand All @@ -47,12 +48,14 @@ BOOST_AUTO_TEST_CASE(multiple)
BOOST_AUTO_TEST_CASE(multiline)
{
Array::Ptr pd = PluginUtility::SplitPerfdata(" 'testA'=123456 'testB'=123456");
pd->Freeze();
BOOST_CHECK_EQUAL(pd->GetLength(), 2);

String str = PluginUtility::FormatPerfdata(pd);
BOOST_CHECK_EQUAL(str, "testA=123456 testB=123456");

pd = PluginUtility::SplitPerfdata(" 'testA'=123456 \n'testB'=123456");
pd->Freeze();
BOOST_CHECK_EQUAL(pd->GetLength(), 2);

str = PluginUtility::FormatPerfdata(pd);
Expand All @@ -62,6 +65,7 @@ BOOST_AUTO_TEST_CASE(multiline)
BOOST_AUTO_TEST_CASE(normalize)
{
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=2m;3;4;1;5 testB=2foobar");
pd->Freeze();
BOOST_CHECK_EQUAL(pd->GetLength(), 2);

String str = PluginUtility::FormatPerfdata(pd, true);
Expand Down Expand Up @@ -333,6 +337,7 @@ BOOST_AUTO_TEST_CASE(ignore_warn_crit_ranges)
BOOST_AUTO_TEST_CASE(empty_warn_crit_min_max)
{
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=5;;7;1;9 testB=5;7;;1;9 testC=5;;;1;9 testD=2m;;;1 testE=5;;7;;");
pd->Freeze();
BOOST_CHECK_EQUAL(pd->GetLength(), 5);

String str = PluginUtility::FormatPerfdata(pd, true);
Expand Down
2 changes: 1 addition & 1 deletion test/perfdata-perfdatawriterfixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object Host "h1" {
std::size_t unchangedCount = 0;
while(true){
ReceiveCheckResults(10, ServiceCritical, [&](const CheckResult::Ptr& cr) {
cr->GetPerformanceData()->Add(new PerfdataValue{GetRandomString("", 4096), 1});
cr->SetPerformanceData(new Array{new PerfdataValue{GetRandomString("", 4096), 1}});
});

if (std::chrono::steady_clock::now() - start >= timeout) {
Expand Down
Loading