diff options
author | Heikki Kallasjoki <kallasjoki@google.com> | 2018-11-15 23:32:12 +0000 |
---|---|---|
committer | Heikki Kallasjoki <kallasjoki@google.com> | 2018-11-15 23:32:12 +0000 |
commit | 13b42a939aaf63e1055f3313ddcfbfb84a049089 (patch) | |
tree | 2712be35125f26a4b69581dde3d683f825277e40 | |
parent | bd4e9df0668f883705eac840a74ce9659376dabd (diff) | |
download | nano-exporter-13b42a939aaf63e1055f3313ddcfbfb84a049089.tar.gz nano-exporter-13b42a939aaf63e1055f3313ddcfbfb84a049089.tar.xz nano-exporter-13b42a939aaf63e1055f3313ddcfbfb84a049089.zip |
Parse textfile directory argument.
-rw-r--r-- | textfile.c | 18 |
1 files 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) { |