aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-09-16 23:56:28 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-09-16 23:56:28 +0200
commit73f14c3ef1e72a72de72167cd9bb868fac45b36a (patch)
treec20ef11437dfa18ff39fd5a9ae7196f50393818f
parentmodviz && redis notifications (diff)
downloadglouglou-73f14c3ef1e72a72de72167cd9bb868fac45b36a.tar.xz
glouglou-73f14c3ef1e72a72de72167cd9bb868fac45b36a.zip
fix redis events
-rw-r--r--doc/architecture.txt72
-rw-r--r--v3/glougloud/redis.c5
-rw-r--r--v3/glougloud/viz.c12
3 files changed, 74 insertions, 15 deletions
diff --git a/doc/architecture.txt b/doc/architecture.txt
index acc1a40..30d0629 100644
--- a/doc/architecture.txt
+++ b/doc/architecture.txt
@@ -322,12 +322,66 @@ PACKET_TRACE
GLOUGLOU DATABASE
===============================================================================
-n/10.0.0.1-router
-n/10.0.0.2-
-n/192.168.1.3-
-n/192.168.1.254-internet gateway
-c/10.0.0.1-1234-10.0.0.2-80
-p/10.0.0.1-10.0.0.2
-p/10.0.0.1-192.168.1.3-192.168.1.254
-d/10.0.0.1-1234-10.0.0.2-80/3
-d/10.0.0.1-1234-10.0.0.2-80/12
+2 types of records
+* history, timestamp prefixed epoch + s/10
+* current state, "/" prefixed
+
+Each record is a set storing the probes IDs using SADD and SREM (get with SMEMBERS).
+This way if a probe sends 2 times a record, no new event is generated for viz clients.
+If multiple probes send the same record, multiple events and generated for viz clients.
+
+Records must not be renamed because it's not atomic (KEYS, wait, RENAME).
+
+MODULE_NETWORK:
+
+13793315910/c/10.0.0.1-1234-10.0.0.2-80
+13793315910/c/192.168.1.3-5678-192.168.1.254-80
+13793315910/n/10.0.0.1
+13793315910/n/10.0.0.2
+13793315910/n/192.168.1.3
+13793315910/n/192.168.1.254
+13793315920/p/10.0.0.1-10.0.0.2
+13793315920/p/10.0.0.1-192.168.1.3-192.168.1.254
+13793315950/r/10.0.0.1-router
+13793315955/r/192.168.1.254-internet gateway
+13793315961/d/10.0.0.1-1234-10.0.0.2-80/3
+13793315963/d/10.0.0.1-1234-10.0.0.2-80/12
+13793315910/C/10.0.0.1-1234-10.0.0.2-80
+
+/n/192.168.1.3
+/n/192.168.1.254
+/c/192.168.1.3-5678-192.168.1.254-80
+/r/192.168.1.254-internet gateway
+/r/10.0.0.1-router
+/p/10.0.0.1-10.0.0.2
+/p/10.0.0.1-192.168.1.3-192.168.1.254
+
+MODULE_PROCESS:
+
+1379331600/f/10432/bash/10434
+1379331600/c/10434/ps
+1379331600/t/10434
+
+/p/10432/bash
+
+===============================================================================
+GLOUGLOU DATABASE TEST
+===============================================================================
+
+set "13793315910/c/10.0.0.1-1234-10.0.0.2-80" ""
+set "13793315910/c/192.168.1.3-5678-192.168.1.254-80" ""
+set "13793315910/n/10.0.0.1-router" ""
+set "13793315910/n/10.0.0.2-" ""
+set "13793315910/n/192.168.1.3-" ""
+set "13793315910/n/192.168.1.254-internet gateway" ""
+set "13793315920/p/10.0.0.1-10.0.0.2" ""
+set "13793315920/p/10.0.0.1-192.168.1.3-192.168.1.254" ""
+set "13793315950/d/10.0.0.1-1234-10.0.0.2-80/3" ""
+set "13793315952/d/10.0.0.1-1234-10.0.0.2-80/12" ""
+set "13793315910/C/10.0.0.1-1234-10.0.0.2-80" ""
+set "13793315910/N/10.0.0.1" ""
+set "13793315910/N/10.0.0.2" ""
+
+set "/n/192.168.1.3-" ""
+set "/n/192.168.1.254-internet gateway" ""
+set "/c/192.168.1.3-5678-192.168.1.254-80" ""
diff --git a/v3/glougloud/redis.c b/v3/glougloud/redis.c
index b786057..10dca7c 100644
--- a/v3/glougloud/redis.c
+++ b/v3/glougloud/redis.c
@@ -33,7 +33,7 @@ redis_init(struct glougloud *ggd) {
droppriv(GLOUGLOUD_USER_PROBES, 0, NULL);
path = getenv("PATH");
snprintf(newpath, sizeof(newpath),
- "%s:/sbin:/usr/sbin:/usr/local/sbin", path);
+ "%s:/bin:/sbin:/usr/local/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin", path);
setenv("PATH", newpath, 1);
snprintf(redis_conf, sizeof(redis_conf),
@@ -54,7 +54,8 @@ redis_init(struct glougloud *ggd) {
"dbfilename glougloud_dump.rdb\n"
"dir /var/lib/glougloud/\n"
"slowlog-log-slower-than 10000\n"
- "slowlog-max-len 1024\n",
+ "slowlog-max-len 1024\n"
+ "notify-keyspace-events KEA\n",
_ggd->redis.socket);
exec_pipe("echo", echo_args, "redis-server", redis_args);
diff --git a/v3/glougloud/viz.c b/v3/glougloud/viz.c
index 35a14ab..ee455df 100644
--- a/v3/glougloud/viz.c
+++ b/v3/glougloud/viz.c
@@ -125,16 +125,20 @@ err:
static void
_redis_cb_notification(redisAsyncContext *c, void *r, void *privdata)
{
- redisReply *reply;
+ redisReply *reply, *rptr;
struct ggdviz_cli *cli;
struct ggdmodviz *m;
char *ntf_type, *ntf_pattern, *ntf_event_type, *ntf_op, *ntf_target;
- int ntf_db, res;
+ int ntf_db, res, i;
reply = r;
if (!reply)
return;
- log_debug("viz: _redis_cb_notification: %s", reply->str);
+ log_debug("viz: _redis_cb_notification: %d %d, %s", reply->type, reply->elements, reply->str);
+ for (i=0; i<reply->elements; i++) {
+ rptr = reply->element[i];
+ log_debug("element%d: %d %d %s", i, rptr->type, rptr->elements, rptr->str);
+ }
res = parse_redis_keyspace_notification(reply->str,
&ntf_type, &ntf_pattern, &ntf_event_type, &ntf_db, &ntf_op, &ntf_target);
if (res < 0) {
@@ -183,7 +187,7 @@ _redis_connect(void)
if (_viz->rc->err)
return -1;
redisAsyncCommand(_viz->rc, _redis_cb_notification, "event",
- "SUBSCRIBE __keyevent@0__:*");
+ "PSUBSCRIBE __key*@*__:*");
return 0;
}