From 5ec77b0583216ed688802eda14bb7ea9f23e2603 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 10 Nov 2012 13:35:29 +0200 Subject: [PATCH] rrdtool: Add pre_draw_cmd This is a configurable command that can be executed before drawing images. Right now only "shell" command is supported. This takes a set of string arguments that are executed via execv. Signed-off-by: Timo Kokkonen --- config.c | 7 +++++++ rrdtool.c | 5 +++++ rrdtool.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/config.c b/config.c index 8e9a360..0754d0a 100644 --- a/config.c +++ b/config.c @@ -263,6 +263,7 @@ static int parse_database(config_setting_t *rrd, struct rrd_database *db) { config_setting_t *list, *str_list; const char *name, *parser = NULL, *filename, **parser_data; + const char **pre_draw_cmd; if (!config_setting_lookup_string(rrd, "name", &name)) { pr_err("Database entry does not contain name\n"); @@ -298,6 +299,12 @@ static int parse_database(config_setting_t *rrd, struct rrd_database *db) db->parser_data = parser_data; } + str_list = config_setting_get_member(rrd, "pre_draw_cmd"); + if (str_list) { + read_strings_from_list(str_list, &pre_draw_cmd); + db->pre_draw_cmd = (char *const *)pre_draw_cmd; + } + return 0; } diff --git a/rrdtool.c b/rrdtool.c index f889d90..d2fd024 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -231,6 +231,11 @@ int rrdtool_update_data(struct rrd_database *rrd) harvest_zombies(pid); } + if (rrd->pre_draw_cmd && !strcmp(rrd->pre_draw_cmd[0], "shell")) { + pid = run(rrd->pre_draw_cmd[1], &rrd->pre_draw_cmd[1]); + harvest_zombies(pid); + } + if (rrd->images) rrdtool_draw_images(rrd->images); diff --git a/rrdtool.h b/rrdtool.h index 4b8bc65..fa1df37 100644 --- a/rrdtool.h +++ b/rrdtool.h @@ -40,6 +40,8 @@ struct rrd_database { int (*parse)(char *rrd_data, const char **parser_data); const char **parser_data; /* data to be fed to the parser */ + char *const *pre_draw_cmd; /* Command to execute prior drawing images*/ + struct rrd_image **images; /* Images to draw */ struct rrd_data_source *sources; /* These are currently only used */ -- 2.45.0