]> git.ipfire.org Git - collecty.git/commitdiff
graph: Add a helper function to pull in all data sources from a module
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 08:58:22 +0000 (08:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 08:58:22 +0000 (08:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c
src/daemon/graph.h
src/daemon/module.c
src/daemon/module.h

index e043418d4500931d006f1d56d82d76795a4ca638..900f836c166354635694250cf8eb2229ce00386f 100644 (file)
@@ -108,6 +108,41 @@ char* collecty_graph_get_bus_path(collecty_graph* self) {
        return path;
 }
 
+int collecty_graph_require_module(collecty_graph* self,
+               collecty_args* args, const char* name, const char* object) {
+       collecty_modules* modules = NULL;
+       collecty_module* module = NULL;
+       int r;
+
+       // Fetch all modules
+       modules = collecty_daemon_get_modules(self->daemon);
+       if (!modules) {
+               r = -ENOTSUP;
+               goto ERROR;
+       }
+
+       // Fetch the module by its name
+       module = collecty_modules_get_by_name(modules, name);
+       if (!module) {
+               ERROR(self->ctx, "Could not find module '%s'\n", name);
+               r = -ENOENT;
+               goto ERROR;
+       }
+
+       // Add the data of the module
+       r = collecty_module_render(module, args, object);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (modules)
+               collecty_modules_unref(modules);
+       if (module)
+               collecty_module_unref(module);
+
+       return r;
+}
+
 int collecty_graph_render(collecty_graph* self,
                const char* object, char** buffer, size_t* length) {
        collecty_args* args = NULL;
index 332234447e08d9d6201b32646b3fe171956a3d3d..1f703c128d1a49266fd699cd9fd0bc3a480367c7 100644 (file)
@@ -47,6 +47,9 @@ collecty_graph* collecty_graph_unref(collecty_graph* self);
 const char* collecty_graph_get_name(collecty_graph* self);
 char* collecty_graph_get_bus_path(collecty_graph* self);
 
+int collecty_graph_require_module(collecty_graph* self,
+       collecty_args* args, const char* name, const char* object);
+
 int collecty_graph_render(collecty_graph* self,
        const char* object, char** buffer, size_t* length);
 
index a94f4d72b552acb771e30deaeaec020c677473da..02dd23881b0004bbb01512f15c5509ace4be3f32 100644 (file)
@@ -401,3 +401,7 @@ int collecty_module_commit(collecty_module* self,
 
        return 0;
 }
+
+int collecty_module_render(collecty_module* self, collecty_args* args, const char* object) {
+       return 0;
+}
index 06789918b08d14ed92b536571b74fed2a0b142c3..c4db55926c5eec3ee2d637c5163a8d5f55037f11 100644 (file)
@@ -23,6 +23,7 @@
 
 typedef struct collecty_module collecty_module;
 
+#include "args.h"
 #include "ctx.h"
 #include "daemon.h"
 
@@ -83,4 +84,7 @@ int collecty_module_submit(collecty_module* self, const char* object,
 int collecty_module_commit(collecty_module* self,
        const char* object, unsigned int num_samples, const char** samples);
 
+int collecty_module_render(collecty_module* self,
+       collecty_args* args, const char* object);
+
 #endif /* COLLECTY_MODULE_H */