broker and cluster: Wire up HookPublishEvent

This commit is contained in:
Arne Welzel 2025-04-07 14:43:39 +02:00
parent 621fd2ab39
commit 53236a184a
2 changed files with 12 additions and 0 deletions

View file

@ -38,6 +38,8 @@
#include "zeek/iosource/Manager.h"
#include "zeek/logging/Manager.h"
#include "zeek/logging/Types.h"
#include "zeek/plugin/Manager.h"
#include "zeek/plugin/Plugin.h"
#include "zeek/telemetry/Manager.h"
#include "zeek/util.h"
@ -825,6 +827,10 @@ std::vector<broker::peer_info> Manager::Peers() const {
std::string Manager::NodeID() const { return to_string(bstate->endpoint.node_id()); }
bool Manager::DoPublishEvent(const std::string& topic, cluster::detail::Event& event) {
bool do_publish = PLUGIN_HOOK_WITH_RESULT(HOOK_PUBLISH_EVENT, HookPublishEvent(*this, topic, event), true);
if ( ! do_publish )
return true;
auto maybe_ev = zeek::cluster::detail::to_broker_event(event);
if ( ! maybe_ev )
return false;

View file

@ -15,6 +15,8 @@
#include "zeek/cluster/Serializer.h"
#include "zeek/cluster/cluster.bif.h"
#include "zeek/logging/Manager.h"
#include "zeek/plugin/Manager.h"
#include "zeek/plugin/Plugin.h"
#include "zeek/util.h"
using namespace zeek::cluster;
@ -120,6 +122,10 @@ void Backend::DoReadyToPublishCallback(Backend::ReadyCallback cb) {
bool Backend::DoPublishEvent(const std::string& topic, cluster::detail::Event& event) {
byte_buffer buf;
bool do_publish = PLUGIN_HOOK_WITH_RESULT(HOOK_PUBLISH_EVENT, HookPublishEvent(*this, topic, event), true);
if ( ! do_publish )
return true;
if ( ! event_serializer->SerializeEvent(buf, event) )
return false;