mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
cluster/Backend: Make backend event processing customizable
This allows configurability at the code level to decide what to do with a received remote events and events produced by a backend. For now, only enqueue events into the process's script layer, but for the WebSocket interface, the action would be to send out the event on a WebSocket connection instead.
This commit is contained in:
parent
337b62960b
commit
0b7a660a34
10 changed files with 139 additions and 27 deletions
|
@ -13,9 +13,20 @@
|
|||
#include "zeek/cluster/Serializer.h"
|
||||
#include "zeek/iosource/Manager.h"
|
||||
#include "zeek/logging/Manager.h"
|
||||
#include "zeek/util.h"
|
||||
|
||||
using namespace zeek::cluster;
|
||||
|
||||
|
||||
bool detail::LocalEventHandlingStrategy::DoHandleRemoteEvent(std::string_view topic, detail::Event e) {
|
||||
zeek::event_mgr.Enqueue(e.Handler(), std::move(e.args), util::detail::SOURCE_BROKER, 0, nullptr, e.timestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
void detail::LocalEventHandlingStrategy::DoEnqueueLocalEvent(EventHandlerPtr h, zeek::Args args) {
|
||||
zeek::event_mgr.Enqueue(h, std::move(args));
|
||||
}
|
||||
|
||||
std::optional<zeek::Args> detail::check_args(const zeek::FuncValPtr& handler, zeek::ArgsSpan args) {
|
||||
const auto& func_type = handler->GetType<zeek::FuncType>();
|
||||
|
||||
|
@ -58,6 +69,10 @@ std::optional<zeek::Args> detail::check_args(const zeek::FuncValPtr& handler, ze
|
|||
return result;
|
||||
}
|
||||
|
||||
Backend::Backend(std::unique_ptr<EventSerializer> es, std::unique_ptr<LogSerializer> ls,
|
||||
std::unique_ptr<detail::EventHandlingStrategy> ehs)
|
||||
: event_serializer(std::move(es)), log_serializer(std::move(ls)), event_handling_strategy(std::move(ehs)) {}
|
||||
|
||||
std::optional<detail::Event> Backend::MakeClusterEvent(FuncValPtr handler, ArgsSpan args, double timestamp) const {
|
||||
auto checked_args = detail::check_args(handler, args);
|
||||
if ( ! checked_args )
|
||||
|
@ -96,6 +111,10 @@ bool Backend::DoPublishLogWrites(const zeek::logging::detail::LogWriteHeader& he
|
|||
return DoPublishLogWrites(header, log_serializer->Name(), buf);
|
||||
}
|
||||
|
||||
void Backend::EnqueueEvent(EventHandlerPtr h, zeek::Args args) {
|
||||
event_handling_strategy->EnqueueLocalEvent(h, std::move(args));
|
||||
}
|
||||
|
||||
bool Backend::ProcessEventMessage(std::string_view topic, std::string_view format,
|
||||
const detail::byte_buffer_span payload) {
|
||||
if ( format != event_serializer->Name() ) {
|
||||
|
@ -113,11 +132,7 @@ bool Backend::ProcessEventMessage(std::string_view topic, std::string_view forma
|
|||
return false;
|
||||
}
|
||||
|
||||
auto& event = *r;
|
||||
zeek::event_mgr.Enqueue(event.Handler(), std::move(event.args), util::detail::SOURCE_BROKER, 0, nullptr,
|
||||
event.timestamp);
|
||||
|
||||
return true;
|
||||
return event_handling_strategy->HandleRemoteEvent(topic, std::move(*r));
|
||||
}
|
||||
|
||||
bool Backend::ProcessLogMessage(std::string_view format, detail::byte_buffer_span payload) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue