]> git.ipfire.org Git - oddments/collecty.git/commitdiff
source: Fetch the last update timestamp
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Oct 2025 19:12:55 +0000 (19:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Oct 2025 19:12:55 +0000 (19:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index b19ad67d4fa73914a38f30c2dfad3adc375a51c7..009925106f9dc47bd89762800b2af8a0785a6ab6 100644 (file)
@@ -891,12 +891,29 @@ static int td_source_migrate(td_source* self, const char* path, rrd_info_t* info
        return td_source_create_database(self, path, path);
 }
 
+static int td_source_fetch_lastupdate(td_source* self, rrd_info_t* info, time_t* t) {
+       // Find last_update
+       for (; info; info = info->next) {
+               if (td_string_equals(info->key, "last_update")) {
+                       if (info->type != RD_I_CNT)
+                               return -ENOTSUP;
+
+                       // Write the time
+                       *t = info->value.u_cnt;
+                       break;
+               }
+       }
+
+       return 0;
+}
+
 /*
        Called to write all collected samples to disk
 */
 static int td_source_commit_samples(td_source* self,
                const char* object, unsigned int num_samples, const char** samples) {
        rrd_info_t* info = NULL;
+       time_t lastupdate = 0;
        char path[PATH_MAX];
        int r;
 
@@ -920,12 +937,19 @@ static int td_source_commit_samples(td_source* self,
                                r = -errno;
                                goto ERROR;
                }
-       }
 
-       // Migrate the RRD file
-       r = td_source_migrate(self, path, info);
-       if (r < 0)
-               goto ERROR;
+       // If we could parse the metadata of the file we will do some more stuff
+       } else {
+               // Migrate the RRD file
+               r = td_source_migrate(self, path, info);
+               if (r < 0)
+                       goto ERROR;
+
+               // Fetch lastupdate
+               r = td_source_fetch_lastupdate(self, info, &lastupdate);
+               if (r < 0)
+                       goto ERROR;
+       }
 
        // Write the samples
        r = rrd_update_r(path, NULL, num_samples, samples);