Skip to content

Commit 717cb21

Browse files
committed
Clickhouse - add main plugin class and plugin interface implementation
1 parent 6e17fb6 commit 717cb21

File tree

3 files changed

+687
-0
lines changed

3 files changed

+687
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief Plugin interface implementation
5+
* @date 2024
6+
*
7+
* Copyright(c) 2024 CESNET z.s.p.o.
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
#include "plugin.h"
12+
13+
#include <ipfixcol2.h>
14+
15+
#include <memory>
16+
17+
/** Plugin description */
18+
IPX_API struct ipx_plugin_info ipx_plugin_info = {
19+
// Plugin identification name
20+
"clickhouse",
21+
// Brief description of plugin
22+
"Output plugin that stores flow records to ClickHouse database.",
23+
// Plugin type
24+
IPX_PT_OUTPUT,
25+
// Configuration flags (reserved for future use)
26+
0,
27+
// Plugin version string (like "1.2.3")
28+
"1.0.0",
29+
// Minimal IPFIXcol version string (like "1.2.3")
30+
"2.3.0"
31+
};
32+
33+
int
34+
ipx_plugin_init(ipx_ctx_t *ctx, const char *xml_config)
35+
{
36+
std::unique_ptr<Plugin> plugin;
37+
try {
38+
plugin = std::make_unique<Plugin>(ctx, xml_config);
39+
} catch (const std::exception &ex) {
40+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured: %s", ex.what());
41+
return IPX_ERR_DENIED;
42+
} catch (...) {
43+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured.");
44+
return IPX_ERR_DENIED;
45+
}
46+
ipx_ctx_private_set(ctx, plugin.release());
47+
return IPX_OK;
48+
}
49+
50+
void
51+
ipx_plugin_destroy(ipx_ctx_t *ctx, void *priv)
52+
{
53+
(void) ctx;
54+
Plugin *plugin = reinterpret_cast<Plugin *>(priv);
55+
try {
56+
plugin->stop();
57+
} catch (const std::exception &ex) {
58+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured: %s", ex.what());
59+
} catch (...) {
60+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured.");
61+
}
62+
delete plugin;
63+
}
64+
65+
int
66+
ipx_plugin_process(ipx_ctx_t *ctx, void *priv, ipx_msg_t *msg)
67+
{
68+
Plugin *plugin = reinterpret_cast<Plugin *>(priv);
69+
try {
70+
plugin->process(msg);
71+
} catch (const std::exception &ex) {
72+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured: %s", ex.what());
73+
return IPX_ERR_DENIED;
74+
} catch (...) {
75+
IPX_CTX_ERROR(ctx, "An unexpected exception has occured.");
76+
return IPX_ERR_DENIED;
77+
}
78+
79+
return IPX_OK;
80+
}

0 commit comments

Comments
 (0)