From ba8305e1e644a55e05b98ae86f5e3819966a7f87 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 23 Sep 2025 15:46:15 +0200 Subject: [PATCH] cluster: Add None backend Mostly so we have the CLUSTER_BACKEND_NONE enum value available, but potentially useful for testing, too. The rough idea is that Zeek by default has Cluster::backend set to CLUSTER_BACKEND_NONE, and script packages in frameworks/cluster/backend redef it accordingly. --- src/cluster/backend/CMakeLists.txt | 2 + src/cluster/backend/none/CMakeLists.txt | 3 ++ src/cluster/backend/none/Plugin.cc | 57 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/cluster/backend/none/CMakeLists.txt create mode 100644 src/cluster/backend/none/Plugin.cc diff --git a/src/cluster/backend/CMakeLists.txt b/src/cluster/backend/CMakeLists.txt index c5a6d1b4a2..c312395c16 100644 --- a/src/cluster/backend/CMakeLists.txt +++ b/src/cluster/backend/CMakeLists.txt @@ -17,3 +17,5 @@ if (ENABLE_CLUSTER_BACKEND_ZEROMQ) add_subdirectory(zeromq) endif () + +add_subdirectory(none) diff --git a/src/cluster/backend/none/CMakeLists.txt b/src/cluster/backend/none/CMakeLists.txt new file mode 100644 index 0000000000..60b3dff0cb --- /dev/null +++ b/src/cluster/backend/none/CMakeLists.txt @@ -0,0 +1,3 @@ +zeek_add_plugin( + Zeek Cluster_Backend_None + SOURCES Plugin.cc) diff --git a/src/cluster/backend/none/Plugin.cc b/src/cluster/backend/none/Plugin.cc new file mode 100644 index 0000000000..2ee9d1d051 --- /dev/null +++ b/src/cluster/backend/none/Plugin.cc @@ -0,0 +1,57 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +#include "zeek/plugin/Plugin.h" + +#include "zeek/cluster/Backend.h" +#include "zeek/cluster/Component.h" +#include "zeek/cluster/Serializer.h" + +namespace { + +using namespace zeek::cluster; + +/** + * A backend that does nothing. + */ +class NoneBackend : public Backend { +private: + bool DoInit() override { return true; }; + void DoTerminate() override {}; + void DoInitPostScript() override {}; + bool DoPublishLogWrites(const zeek::logging::detail::LogWriteHeader& header, const std::string& format, + zeek::byte_buffer& buf) override { + return true; + } + bool DoPublishEvent(const std::string& topic, const std::string& format, const zeek::byte_buffer& buf) override { + return true; + }; + bool DoSubscribe(const std::string& topic_prefix, SubscribeCallback cb) override { return true; }; + bool DoUnsubscribe(const std::string& topic_prefix) override { return true; }; + +public: + NoneBackend(std::unique_ptr es, std::unique_ptr ls, + std::unique_ptr ehs) + : Backend("None", std::move(es), std::move(ls), std::move(ehs)) {} + + static std::unique_ptr Instantiate(std::unique_ptr es, std::unique_ptr ls, + std::unique_ptr ehs) { + return std::make_unique(std::move(es), std::move(ls), std::move(ehs)); + } +}; +} // namespace + + +namespace zeek::plugin::Zeek_Cluster_None { + +class Plugin : public zeek::plugin::Plugin { + zeek::plugin::Configuration Configure() override { + AddComponent(new cluster::BackendComponent("None", NoneBackend::Instantiate)); + + zeek::plugin::Configuration config; + config.name = "Zeek::Cluster_Backend_None"; + config.description = "Cluster backend none"; + return config; + } +} plugin; + +} // namespace zeek::plugin::Zeek_Cluster_None