From 46ec42182b6d192ec5c253876ca539dd92363d9f Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 14 Nov 2017 20:19:18 +0000 Subject: [PATCH] output: add some trivia data to json output These are software version, dhcpd conf and leases paths and mtime epoch timestamps. Signed-off-by: Sami Kerola --- src/output.c | 14 +++++++++++++- tests/expected/same-twice-json | 2 ++ tests/full-json | 5 +++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/output.c b/src/output.c index 9ee2475..a651ccb 100644 --- a/src/output.c +++ b/src/output.c @@ -596,7 +596,19 @@ static int output_json(struct conf_t *state, const int print_mac_addreses) fprintf(outfile, " \"backup_percent\":%g,\n", oh.bup); } fprintf(outfile, " \"status\":%d\n", oh.status); - fprintf(outfile, " }"); /* end of summary */ + fprintf(outfile, " },\n"); /* end of summary */ + fprintf(outfile, " \"trivia\": {\n"); + fprintf(outfile, " \"version\":\"%s\",\n", PACKAGE_VERSION); + fprintf(outfile, " \"conf_file_path\":\"%s\",\n", state->dhcpdconf_file); + fprintf(outfile, " \"conf_file_epoch_mtime\":"); + dp_time_tool(outfile, state->dhcpdconf_file, 1); + fprintf(outfile, ",\n"); + fprintf(outfile, " \"lease_file_path\":\"%s\",\n", state->dhcpdlease_file); + fprintf(outfile, " \"lease_file_epoch_mtime\":"); + dp_time_tool(outfile, state->dhcpdlease_file, 1); + fprintf(outfile, "\n"); + + fprintf(outfile, " }"); /* end of trivia */ } fprintf(outfile, "\n}\n"); close_outfile(outfile); diff --git a/tests/expected/same-twice-json b/tests/expected/same-twice-json index 43d431b..f572972 100644 --- a/tests/expected/same-twice-json +++ b/tests/expected/same-twice-json @@ -17,5 +17,7 @@ "touch_count":1, "touch_percent":10, "status":0 + }, + "trivia": { } } diff --git a/tests/full-json b/tests/full-json index 31b0c93..881b02d 100755 --- a/tests/full-json +++ b/tests/full-json @@ -7,7 +7,8 @@ if [ ! -d tests/outputs ]; then fi dhcpd-pools -f J -c $top_srcdir/tests/confs/same-twice \ - -l $top_srcdir/tests/leases/same-twice \ - -o tests/outputs/same-twice-json + -l $top_srcdir/tests/leases/same-twice | + sed '/"version":"/d; /"conf_file_.*":/d; /"lease_file_.*":/d' \ + >| tests/outputs/same-twice-json diff -u $top_srcdir/tests/expected/same-twice-json tests/outputs/same-twice-json exit $?