]> granicus.if.org Git - sysstat/commitdiff
JSON: Don't display fchosts tag when no stats exist
authorSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 26 Jan 2016 21:43:23 +0000 (22:43 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 26 Jan 2016 21:43:23 +0000 (22:43 +0100)
The JSON print function can be called for A_NET_FC (Fibre Channel)
activity even if no statistics exist. This is because this activity has
the AO_CLOSE_MARKUP flag used to close the "network" section of the
output. Anyway, in this case (when no stats exist), it should only do
that (close the network section) et not display the "fchost" tag.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
json_stats.c

index 8e6ec84fa51bbdc5c59f7454313b57455da6ca76..7e38a3cc466f72fd67504baa568247ac2cbabf39 100644 (file)
@@ -2178,6 +2178,12 @@ __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab,
        struct stats_fchost *sfcc, *sfcp;
        int sep = FALSE;
 
+       if (!IS_SELECTED(a->options) || (a->nr <= 0))
+               goto close_json_markup;
+
+       json_markup_network(tab, OPEN_JSON_MARKUP);
+       tab++;
+
        xprintf(tab++, "\"fchosts\": [");
 
        for (i = 0; i < a->nr; i++) {
@@ -2207,4 +2213,11 @@ __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab,
 
        printf("\n");
        xprintf0(--tab, "]");
+
+       tab --;
+
+close_json_markup:
+       if (CLOSE_MARKUP(a->options)) {
+               json_markup_network(tab, CLOSE_JSON_MARKUP);
+       }
 }