Code

store: Include backend information in the JSON serialization.
authorSebastian Harl <sh@tokkee.org>
Tue, 1 Jul 2014 19:59:29 +0000 (21:59 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 1 Jul 2014 19:59:29 +0000 (21:59 +0200)
src/core/store.c
t/unit/core/store_test.c

index 125009cd574b355625960a53f4eeb995ad7575dc..d185431f976de168213aa769ceee8bd2a7f16482 100644 (file)
@@ -379,6 +379,7 @@ store_common_tojson(sdb_store_obj_t *obj, sdb_strbuf_t *buf)
 {
        char time_str[64];
        char interval_str[64];
+       size_t i;
 
        if (! sdb_strftime(time_str, sizeof(time_str),
                                "%F %T %z", obj->last_update))
@@ -391,7 +392,15 @@ store_common_tojson(sdb_store_obj_t *obj, sdb_strbuf_t *buf)
        interval_str[sizeof(interval_str) - 1] = '\0';
 
        sdb_strbuf_append(buf, "\"last_update\": \"%s\", "
-                       "\"update_interval\": \"%s\"", time_str, interval_str);
+                       "\"update_interval\": \"%s\", \"backends\": [",
+                       time_str, interval_str);
+
+       for (i = 0; i < obj->backends_num; ++i) {
+               sdb_strbuf_append(buf, "\"%s\"", obj->backends[i]);
+               if (i < obj->backends_num - 1)
+                       sdb_strbuf_append(buf, ",");
+       }
+       sdb_strbuf_append(buf, "]");
 } /* store_common_tojson */
 
 /*
index cca3968c4674df076a948d641a71d211c1257e3d..4e40743d85ce60b28dcb965ac770b72935285927 100644 (file)
@@ -278,72 +278,72 @@ START_TEST(test_store_tojson)
        } golden_data[] = {
                { 0, "{\"hosts\":["
                                "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"attributes\": ["
                                                "{\"name\": \"k1\", \"value\": \"v1\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"k2\", \"value\": \"v2\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"k3\", \"value\": \"v3\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"}"
+                                                       "\"update_interval\": \"0s\", \"backends\": []}"
                                        "], "
                                        "\"services\": []},"
                                "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"attributes\": [], "
                                        "\"services\": ["
                                                "{\"name\": \"s1\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"s2\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"}"
+                                                       "\"update_interval\": \"0s\", \"backends\": []}"
                                        "]}"
                        "]}" },
                { SDB_SKIP_SERVICES,
                        "{\"hosts\":["
                                "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"attributes\": ["
                                                "{\"name\": \"k1\", \"value\": \"v1\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"k2\", \"value\": \"v2\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"k3\", \"value\": \"v3\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"}"
+                                                       "\"update_interval\": \"0s\", \"backends\": []}"
                                        "]},"
                                "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"attributes\": []}"
                        "]}" },
                { SDB_SKIP_ATTRIBUTES,
                        "{\"hosts\":["
                                "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"services\": []},"
                                "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\", "
+                                       "\"update_interval\": \"0s\", \"backends\": [], "
                                        "\"services\": ["
                                                "{\"name\": \"s1\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"},"
+                                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                                "{\"name\": \"s2\", "
                                                        "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                                       "\"update_interval\": \"0s\"}"
+                                                       "\"update_interval\": \"0s\", \"backends\": []}"
                                        "]}"
                        "]}" },
                { SDB_SKIP_SERVICES | SDB_SKIP_ATTRIBUTES,
                        "{\"hosts\":["
                                "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\"},"
+                                       "\"update_interval\": \"0s\", \"backends\": []},"
                                "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
-                                       "\"update_interval\": \"0s\"}"
+                                       "\"update_interval\": \"0s\", \"backends\": []}"
                        "]}" },
        };