]> git.ipfire.org Git - oddments/collecty.git/commitdiff
graphs: Add option to omit the title
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 16:18:31 +0000 (16:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 16:18:31 +0000 (16:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client/main.c
src/daemon/graph-bus.c
src/daemon/graph.c
src/daemon/graph.h

index 23e2166804f83498f43b09a2350345d1b756c428..1ef0543142aa59b078c6d727a7412c1be77426d2 100644 (file)
@@ -31,8 +31,7 @@ static const char* doc = "The telemetry client that can draw graphs";
 
 typedef struct td_client_ctx {
        enum {
-               // Enables debugging output
-               DEBUG       = (1 << 0),
+               OMIT_TITLE = (1 << 0),
        } flags;
 
        // DBus
@@ -64,11 +63,12 @@ typedef struct td_client_ctx {
 } td_client_ctx;
 
 enum {
-       OPT_FORMAT  = 1,
-       OPT_HEIGHT  = 2,
-       OPT_WIDTH   = 3,
-       OPT_SINCE   = 4,
-       OPT_UNTIL   = 5,
+       OPT_FORMAT     = 1,
+       OPT_HEIGHT     = 2,
+       OPT_WIDTH      = 3,
+       OPT_SINCE      = 4,
+       OPT_UNTIL      = 5,
+       OPT_OMIT_TITLE = 6,
 };
 
 static struct argp_option options[] = {
@@ -79,6 +79,9 @@ static struct argp_option options[] = {
        // Time
        { "since",  OPT_SINCE, "TIMESTAMP", 0, "Start the graph from the specified date", 0 },
        { "until",  OPT_UNTIL, "TIMESTAMP", 0, "End the graph at the specified date", 0 },
+
+       // Flags
+       { "omit-title", OPT_OMIT_TITLE, NULL, 0, "Omit the title in the graph image", 0},
        { NULL },
 };
 
@@ -117,6 +120,10 @@ static error_t parse(int key, char* arg, struct argp_state* state) {
                        ctx->interval.until = arg;
                        break;
 
+               case OPT_OMIT_TITLE:
+                       ctx->flags |= OMIT_TITLE;
+                       break;
+
                // Called for each argument
                case ARGP_KEY_ARG:
                        // Take the graph name as first argument
@@ -216,6 +223,13 @@ static int render(td_client_ctx* ctx) {
                        goto ERROR;
        }
 
+       // Omit the title?
+       if (ctx->flags & OMIT_TITLE) {
+               r = sd_bus_message_append(m, "{sv}", "omit-title", "b", 1);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Close the array
        r = sd_bus_message_close_container(m);
        if (r < 0)
index 3d7e75ce18d74cd42df57d6c0469fd1e4475ceb9..540662e91df694620aa391f252048a4055da04d9 100644 (file)
@@ -111,6 +111,9 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro
        const char* since = NULL;
        const char* until = NULL;
 
+       // Flags
+       int omit_title = 0;
+
        // Open the options array
        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
        if (r < 0)
@@ -181,6 +184,15 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro
                                                SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", until);
                                goto ERROR;
                        }
+
+               // Parse "omit-title"
+               } else if (td_string_equals(key, "omit-title")) {
+                       r = sd_bus_message_read(m, "v", "b", &omit_title);
+                       if (r < 0)
+                               goto ERROR;
+
+                       if (omit_title)
+                               options.flags |= TD_GRAPH_OMIT_TITLE;
                }
 
                // Leave the container
index 53d2e4a3b45c8cff7c07f0dd54d81f185ab04139..ecaad1f91f6f287bdc619d17e2dcef9f224a535b 100644 (file)
@@ -201,11 +201,39 @@ ERROR:
        return r;
 }
 
+static int td_graph_render_title(td_graph* self, const char* object,
+               const td_graph_render_options* options, td_args* args) {
+       char title[TITLE_MAX] = "";
+       int r;
+
+       // Don't render the title if requested to omit
+       if (options->flags & TD_GRAPH_OMIT_TITLE)
+               return 0;
+
+       // Call the implementation
+       if (self->impl->title) {
+               // Fetch the title
+               r = self->impl->title(self->ctx, self, object, title, sizeof(title));
+               if (r < 0) {
+                       ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
+                       return r;
+               }
+
+               // Add the title to the command line
+               if (*title) {
+                       r = td_args_push(args, "--title=%s", title);
+                       if (r < 0)
+                               return r;
+               }
+       }
+
+       return 0;
+}
+
 int td_graph_render(td_graph* self, const char* object,
                const td_graph_render_options* options, char** buffer, size_t* length) {
        td_args* args = NULL;
        char vlabel[VLABEL_MAX] = "";
-       char title[TITLE_MAX] = "";
        char** data = NULL;
        FILE* f = NULL;
        int w = 0;
@@ -299,21 +327,9 @@ int td_graph_render(td_graph* self, const char* object,
        }
 
        // Set the title
-       if (self->impl->title) {
-               // Fetch the title
-               r = self->impl->title(self->ctx, self, object, title, sizeof(title));
-               if (r < 0) {
-                       ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
-                       goto ERROR;
-               }
-
-               // Add the title to the command line
-               if (*title) {
-                       r = td_args_push(args, "--title=%s", title);
-                       if (r < 0)
-                               goto ERROR;
-               }
-       }
+       r = td_graph_render_title(self, object, options, args);
+       if (r < 0)
+               goto ERROR;
 
        // Set the vertical label
        if (self->impl->vlabel) {
index 89e631942806042d3f9b921e75720ad36ca78bd5..01d3a8be44f8410ff3d3696f0dbd3bdede392021 100644 (file)
@@ -84,6 +84,11 @@ typedef struct td_graph_render_options {
                time_t t_start;
                time_t t_end;
        } interval;
+
+       // Flags
+       enum {
+               TD_GRAPH_OMIT_TITLE = (1 << 0),
+       } flags;
 } td_graph_render_options;
 
 int td_graph_render(td_graph* self, const char* object,