From 069760266eac38f8c0dbc454a98e37a22fcae248 Mon Sep 17 00:00:00 2001 From: kanoi Date: Mon, 21 Mar 2016 22:55:15 +1100 Subject: [PATCH] ckdb - add the ovents list to cmd_events --- src/ckdb.h | 2 +- src/ckdb_cmd.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 9e2f71eb..c3ababa0 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.5" -#define CKDB_VERSION DB_VERSION"-1.988" +#define CKDB_VERSION DB_VERSION"-1.989" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 6b41ae28..45120afe 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -7612,8 +7612,9 @@ static char *cmd_events(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *cd, K_TREE *trf_root) { K_ITEM *i_action, *i_cmd, *i_list, *i_ip, *i_eventname, *i_lifetime; - K_ITEM *i_des, *i_item, *next_item; + K_ITEM *i_des, *i_item, *next_item, *o_item; K_TREE_CTX ctx[1]; + OVENTS *ovents; IPS *ips; char *action, *alert_cmd, *list, *ip, *eventname, *des; char reply[1024] = ""; @@ -7621,7 +7622,7 @@ static char *cmd_events(__maybe_unused PGconn *conn, char *cmd, char *id, char tmp[1024] = ""; char *buf = NULL; size_t len, off; - int i, rows, oldlife, lifetime; + int i, rows, oldlife, lifetime, vid, min; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -8034,6 +8035,50 @@ static char *cmd_events(__maybe_unused PGconn *conn, char *cmd, char *id, APPEND_REALLOC_INIT(buf, off, len); snprintf(tmp, sizeof(tmp), "ok.expired %d", rows); APPEND_REALLOC(buf, off, len, tmp); + } else if (strcasecmp(action, "ovents") == 0) { + /* List the ovent tree contents + * Output can be large - check web Admin->ckp for tree sizes */ + bool got; + APPEND_REALLOC_INIT(buf, off, len); + APPEND_REALLOC(buf, off, len, "ok."); + rows = 0; + K_RLOCK(ovents_free); + o_item = first_in_ktree(ovents_root, ctx); + while (o_item) { + DATA_OVENTS(ovents, o_item); + for (vid = 0; o_limits[vid].name; vid++) { + got = false; + for (min = 0; min < 60; min++) { + if (ovents->count[IDMIN(vid, min)]) { + if (!got) { + snprintf(reply, siz, "key:%d=%s%c", + rows, ovents->key, FLDSEP); + APPEND_REALLOC(buf, off, len, reply); + snprintf(reply, siz, "id:%d=%d%c", + rows, vid, FLDSEP); + APPEND_REALLOC(buf, off, len, reply); + snprintf(reply, siz, "idname:%d=%s%c", + rows, o_limits[vid].name, FLDSEP); + APPEND_REALLOC(buf, off, len, reply); + snprintf(reply, siz, "hour:%d=%d%c", + rows, ovents->hour, FLDSEP); + APPEND_REALLOC(buf, off, len, reply); + got = true; + } + snprintf(reply, siz, "min%02d:%d=%d%c", + min, rows, ovents->count[IDMIN(vid, min)], + FLDSEP); + APPEND_REALLOC(buf, off, len, reply); + } + } + if (got) + rows++; + } + o_item = next_in_ktree(ctx); + } + K_RUNLOCK(ovents_free); + snprintf(tmp, sizeof(tmp), "rows=%d", rows); + APPEND_REALLOC(buf, off, len, tmp); } else { snprintf(reply, siz, "unknown action '%s'", action); LOGERR("%s() %s.%s", __func__, id, reply);