From 073ef8aa62fc9909d1fe7b9a711f651951e9fbc5 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Thu, 10 Sep 2015 21:04:10 +0200 Subject: [PATCH] new feature: round-trip monitoring, aka "pingping" closes #17 --- Makefile | 4 ++++ README.md | 5 +++++ config.mk.in | 1 + ocat.c | 3 +++ ot-recorder.c | 21 ++++++++++++++------- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 581021d..f5508d0 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,10 @@ OTR_OBJS = json.o \ util.o \ storage.o +ifeq ($(HAVE_PING),yes) + CFLAGS += -DHAVE_PING=1 +endif + ifeq ($(HAVE_LMDB),yes) CFLAGS += -DHAVE_LMDB=1 -Imdb/ OTR_OBJS += gcache.o diff --git a/README.md b/README.md index 630ed62..fdaf92e 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,11 @@ The `monitor` file is located relative to STORE and contains a single line, the 1439738692 owntracks/jjolie/ipad ``` + +If _recorder_ is built with `HAVE_PING` (default), a location publish to `owntracks/ping/ping` (i.e. username is `ping` and device is `ping`) can be used to round-trip-test the recorder. For this particular username/device combination, _recorder_ will store LAST position, but it will not keep a .REC file for it. This can be used to verify, say, via your favorite monitoring system, that the _recorder_ is still operational. + +After sending a _pingping_, query the REST interface and deterrmine the difference in time. + ## `ocat` _ocat_ is a CLI driver for _recorder_: it prints data stored by the _recorder_ in a variety of output formats. diff --git a/config.mk.in b/config.mk.in index f01b834..bf6bbab 100644 --- a/config.mk.in +++ b/config.mk.in @@ -1,6 +1,7 @@ # Select features HAVE_HTTP ?= yes HAVE_LMDB ?= yes +HAVE_PING ?= yes STORAGEDEFAULT = "./store" diff --git a/ocat.c b/ocat.c index 991804a..d212a6a 100644 --- a/ocat.c +++ b/ocat.c @@ -164,6 +164,9 @@ void print_versioninfo() #endif #ifdef HAVE_HTTP printf("\tHAVE_HTTP = yes\n"); +#endif +#ifdef HAVE_PING + printf("\tHAVE_PING = yes\n"); #endif printf("\tSTORAGEDEFAULT = \"%s\"\n", STORAGEDEFAULT); printf("\tGEOHASH_PREC = %d\n", GEOHASH_PREC); diff --git a/ot-recorder.c b/ot-recorder.c index 1cf1967..ce269f0 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -371,6 +371,7 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m static UT_string *reltopic = NULL; char *jsonstring; time_t now; + int pingping = FALSE; /* * mosquitto_message-> @@ -411,6 +412,12 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m utstring_printf(username, "%s", topics[1]); utstring_printf(device, "%s", topics[2]); +#ifdef HAVE_PING + if (!strcmp(utstring_body(username), "ping") && !strcmp(utstring_body(device), "ping")) { + pingping = TRUE; + } +#endif + if ((count == TOPIC_PARTS) && (strcmp(topics[count-1], TOPIC_SUFFIX) == 0)) { if (do_info(ud, username, device, m->payload) == TRUE) { /* this was a card */ return; @@ -546,7 +553,7 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m */ #ifdef HAVE_HTTP - if (ud->mgserver) { + if (ud->mgserver && !pingping) { /* * Create a new location object containing all the bits and @@ -595,13 +602,13 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m } #endif - if ((fp = pathn("a", "rec", username, device, "rec")) != NULL) { - - fprintf(fp, RECFORMAT, isotime(now), "*", jsonstring); - fclose(fp); + if (!pingping) { + if ((fp = pathn("a", "rec", username, device, "rec")) != NULL) { + fprintf(fp, RECFORMAT, isotime(now), "*", jsonstring); + fclose(fp); + } } - /* Keep track of original username & device name in LAST. */ json_append_member(json, "username", json_mkstring(utstring_body(username))); json_append_member(json, "device", json_mkstring(utstring_body(device))); @@ -740,7 +747,7 @@ int main(int argc, char **argv) udata.gc = NULL; #endif #ifdef HAVE_HTTP - udata.mgserver = NULL; + udata.mgserver = NULL; #endif if ((p = getenv("OTR_HOST")) != NULL) {