summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dfb8c39)
raw | patch | inline | side by side (parent: dfb8c39)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 3 Apr 2014 13:28:00 +0000 (15:28 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 3 Apr 2014 13:28:00 +0000 (15:28 +0200) |
src/core/store.c | patch | blob | history | |
t/core/store_test.c | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index 0dec68db0ba9eea881c97bc00a6a178f4356c640..fd08de9101272dfafa7e7b0e6f8e4dbe1d626675 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
{
sdb_llist_iter_t *iter;
char time_str[64];
+ char interval_str[64];
assert((type == SDB_ATTRIBUTE) || (type == SDB_SERVICE));
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
+ if (! sdb_strfinterval(interval_str, sizeof(interval_str),
+ sobj->interval))
+ snprintf(interval_str, sizeof(interval_str), "<error>");
+ interval_str[sizeof(interval_str) - 1] = '\0';
+
sdb_strbuf_append(buf, "{\"name\": \"%s\", ", SDB_OBJ(sobj)->name);
if (type == SDB_ATTRIBUTE) {
char tmp[sdb_data_strlen(&SDB_ATTR(sobj)->value) + 1];
sdb_data_format(&SDB_ATTR(sobj)->value, tmp, sizeof(tmp),
SDB_DOUBLE_QUOTED);
- sdb_strbuf_append(buf, "\"value\": %s, \"last_update\": \"%s\"}",
- tmp, time_str);
+ sdb_strbuf_append(buf, "\"value\": %s, \"last_update\": \"%s\", "
+ "\"update_interval\": \"%s\"}", tmp, time_str,
+ interval_str);
}
else
- sdb_strbuf_append(buf, "\"last_update\": \"%s\"}", time_str);
+ sdb_strbuf_append(buf, "\"last_update\": \"%s\", "
+ "\"update_interval\": \"%s\"}", time_str, interval_str);
if (sdb_llist_iter_has_next(iter))
sdb_strbuf_append(buf, ",");
{
sdb_store_obj_t *host;
char time_str[64];
+ char interval_str[64];
if ((! h) || (h->type != SDB_HOST) || (! buf))
return -1;
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
+ if (! sdb_strfinterval(interval_str, sizeof(interval_str),
+ host->_interval))
+ snprintf(interval_str, sizeof(interval_str), "<error>");
+ interval_str[sizeof(interval_str) - 1] = '\0';
+
sdb_strbuf_append(buf, "{\"name\": \"%s\", "
- "\"last_update\": \"%s\"",
- SDB_OBJ(host)->name, time_str);
+ "\"last_update\": \"%s\", \"update_interval\": \"%s\"",
+ SDB_OBJ(host)->name, time_str, interval_str);
if (! (flags & SDB_SKIP_ATTRIBUTES)) {
sdb_strbuf_append(buf, ", \"attributes\": ");
diff --git a/t/core/store_test.c b/t/core/store_test.c
index d0ef5a910cbc7e5c15c32fb93ff58d8b85ee5bce..bc514027d5d9bbfb34719be5c7b375731b68a11a 100644 (file)
--- a/t/core/store_test.c
+++ b/t/core/store_test.c
} golden_data[] = {
{ 0, "{\"hosts\":["
"{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"attributes\": ["
- "{\"name\": \"k1\", \"value\": \"v1\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"k2\", \"value\": \"v2\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"k3\", \"value\": \"v3\", \"last_update\": \"1970-01-01 00:00:00 +0000\"}"
+ "{\"name\": \"k1\", \"value\": \"v1\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"k2\", \"value\": \"v2\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"k3\", \"value\": \"v3\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"}"
"], "
"\"services\": []},"
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"attributes\": [], "
"\"services\": ["
- "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:00 +0000\"}"
+ "{\"name\": \"s1\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"s2\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"}"
"]}"
"]}" },
{ SDB_SKIP_SERVICES,
"{\"hosts\":["
"{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"attributes\": ["
- "{\"name\": \"k1\", \"value\": \"v1\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"k2\", \"value\": \"v2\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"k3\", \"value\": \"v3\", \"last_update\": \"1970-01-01 00:00:00 +0000\"}"
+ "{\"name\": \"k1\", \"value\": \"v1\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"k2\", \"value\": \"v2\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"k3\", \"value\": \"v3\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"}"
"]},"
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"attributes\": []}"
"]}" },
{ SDB_SKIP_ATTRIBUTES,
"{\"hosts\":["
"{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"services\": []},"
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", "
"\"services\": ["
- "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:00 +0000\"}"
+ "{\"name\": \"s1\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"s2\", "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"}"
"]}"
"]}" },
{ SDB_SKIP_SERVICES | SDB_SKIP_ATTRIBUTES,
"{\"hosts\":["
- "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\"},"
- "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\"}"
+ "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"},"
+ "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\"}"
"]}" },
};