From 13b42a939aaf63e1055f3313ddcfbfb84a049089 Mon Sep 17 00:00:00 2001 From: Heikki Kallasjoki Date: Thu, 15 Nov 2018 23:32:12 +0000 Subject: Parse textfile directory argument. --- textfile.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/textfile.c b/textfile.c index b571f27..d9ab4fa 100644 --- a/textfile.c +++ b/textfile.c @@ -7,6 +7,9 @@ #include "textfile.h" #include "util.h" +// TODO: check default +#define DEFAULT_DIR "/var/lib/prometheus-node-exporter" + void *textfile_init(int argc, char *argv[]); void textfile_collect(scrape_req *req, void *ctx); @@ -18,9 +21,18 @@ const struct collector textfile_collector = { }; void *textfile_init(int argc, char *argv[]) { - const char *dir = "."; // TODO: default - // TODO: parse arg - return must_strdup(dir); + char *dir = DEFAULT_DIR; + + for (int arg = 0; arg < argc; arg++) { + if (strncmp(argv[arg], "dir=", 4) == 0) { + dir = &argv[arg][4]; + } else { + fprintf(stderr, "unknown argument for textfile collector: %s", argv[arg]); + return 0; + } + } + + return dir; } void textfile_collect(scrape_req *req, void *ctx) { -- cgit 1.4.1