]> git.ipfire.org Git - collecty.git/commitdiff
module: Format the data sources
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 09:42:48 +0000 (09:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 09:42:48 +0000 (09:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/module.c

index 0af412a3cf482140645017c10e6cb985fe7099f7..2414e8074c7ad5c45ac0109977baa85b920eb432 100644 (file)
 
 #include <systemd/sd-event.h>
 
+#include "args.h"
 #include "ctx.h"
 #include "daemon.h"
 #include "module.h"
+#include "util.h"
 
 // Interval after which the heartbeat function is being called again
 #define HEARTBEAT 60000000 // 60s
@@ -270,11 +272,47 @@ int collecty_module_submit(collecty_module* self,
 }
 
 static int collecty_module_create_database(collecty_module* self, const char* path) {
+       collecty_args* args = NULL;
+       char min[24];
+       char max[24];
+       int r;
+
        DEBUG(self->ctx, "Creating database for %s at %s\n", collecty_module_name(self), path);
 
-       // XXX TODO
+       // Allocate a new argument array
+       r = collecty_args_create(&args, self->ctx);
+       if (r < 0)
+               goto ERROR;
 
-       return 0;
+       // Add all data sources
+       for (const collecty_rrd_ds* ds = self->methods->rrd_dss; ds->field; ds++) {
+               // Format the minimum value
+               r = collecty_format_number(min, ds->min);
+               if (r < 0)
+                       goto ERROR;
+
+               // Format the maximum value
+               r = collecty_format_number(max, ds->max);
+               if (r < 0)
+                       goto ERROR;
+
+               // Add the DS line
+               r = collecty_args_push(args, "DS:%s:%s:%d:%s:%s",
+                               ds->field, ds->type, HEARTBEAT * 2, min, max);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Dump all arguments
+       r = collecty_args_dump(args);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (args)
+               collecty_args_unref(args);
+
+       return r;
 }
 
 /*