diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index c5dc084c0..b0aa6ffd0 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -1905,7 +1905,7 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul auto eventTime (cr->GetExecutionEnd()); auto eventTs (TimestampToMilliseconds(eventTime)); - Array::Ptr rawId = new Array({m_EnvironmentId, object->GetName()}); + Array::Ptr rawId = new Array({m_EnvironmentId, GetObjectIdentifier(object)}); rawId->Add(eventTs); RedisConnection::Query xAdd ({ diff --git a/lib/icingadb/icingadb-utility.cpp b/lib/icingadb/icingadb-utility.cpp index 74dc9afe7..59be32f47 100644 --- a/lib/icingadb/icingadb-utility.cpp +++ b/lib/icingadb/icingadb-utility.cpp @@ -92,7 +92,7 @@ String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object) */ String IcingaDB::CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime, NotificationType nt) { - Array::Ptr rawId = new Array({object->GetName()}); + Array::Ptr rawId = new Array({GetObjectIdentifier(object)}); rawId->Insert(0, m_EnvironmentId); rawId->Insert(1, eventType); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 94296c38b..73ab8142b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,6 +61,7 @@ if(ICINGA2_WITH_PGSQL) endif() if(ICINGA2_WITH_ICINGADB) + list(APPEND types_test_SOURCES icingadb-eventid.cpp) list(APPEND types_test_SOURCES $) endif() diff --git a/test/icingadb-eventid.cpp b/test/icingadb-eventid.cpp new file mode 100644 index 000000000..9ab235e89 --- /dev/null +++ b/test/icingadb-eventid.cpp @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2012 Icinga GmbH +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "icingadb/icingadb.hpp" +#include "icinga/host.hpp" +#include + +using namespace icinga; + +BOOST_AUTO_TEST_CASE(calc_event_id_uses_object_identifier) +{ + Host::Ptr host = new Host(); + host->SetName("master01"); + + host->SetIcingadbIdentifier("id-a"); + auto first = IcingaDB::CalcEventID("state_change", host, 1710000000.123); + + host->SetIcingadbIdentifier("id-b"); + auto second = IcingaDB::CalcEventID("state_change", host, 1710000000.123); + + BOOST_CHECK_NE(first, second); +}