Explorar o código

usrloc: fexible logging for roundtrip details

- new params ka_loglevel and ka_logmsg
Daniel-Constantin Mierla %!s(int64=5) %!d(string=hai) anos
pai
achega
0d912f11c9
Modificáronse 2 ficheiros con 30 adicións e 6 borrados
  1. 15 3
      src/modules/usrloc/ul_keepalive.c
  2. 15 3
      src/modules/usrloc/usrloc_mod.c

+ 15 - 3
src/modules/usrloc/ul_keepalive.c

@@ -32,6 +32,7 @@
 #include "../../core/resolve.h"
 #include "../../core/forward.h"
 #include "../../core/globals.h"
+#include "../../core/pvar.h"
 #include "../../core/parser/parse_uri.h"
 #include "../../core/parser/parse_from.h"
 #include "../../core/parser/parse_to.h"
@@ -71,6 +72,9 @@ extern str ul_ka_domain;
 extern str ul_ka_method;
 extern int ul_ka_mode;
 extern int ul_ka_filter;
+extern int ul_ka_loglevel;
+extern pv_elem_t *ul_ka_logfmt;
+
 extern unsigned int nat_bflag;
 
 static unsigned int _ul_ka_counter = 0;
@@ -417,11 +421,19 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	gettimeofday(&tvn, NULL);
 	tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000
 					+ (tvn.tv_usec - tvm.tv_usec);
+	ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff);
 
-	LM_DBG("reply for keepalive of [%.*s:%u] roundtrip: %u.%06usec\n",
-			ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000);
+	if(ul_ka_loglevel != 255 && ul_ka_logfmt != NULL) {
+		if (pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) {
+			LOG(ul_ka_loglevel, "keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n",
+					tvdiff/1000000, tvdiff%1000000, ruid.len, ruid.s,
+					tok.len, tok.s);
+			return 0;
+		}
+	}
 
-	ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff);
+	LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: %u.%06u secs\n",
+			ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000);
 
 	return 0;
 }

+ 15 - 3
src/modules/usrloc/usrloc_mod.c

@@ -123,6 +123,9 @@ str ul_ka_domain = str_init("kamailio.org");
 str ul_ka_method = str_init("OPTIONS");
 int ul_ka_mode = 0;
 int ul_ka_filter = 0;
+int ul_ka_loglevel = 255;
+str ul_ka_logmsg = str_init(" to-uri: [$tu] src-uri: [$su]");
+pv_elem_t *ul_ka_logfmt = NULL;
 
 /* sruid to get internal uid for mi/rpc commands */
 sruid_t _ul_sruid;
@@ -255,6 +258,7 @@ static param_export_t params[] = {
 	{"ka_domain",           PARAM_STR, &ul_ka_domain},
 	{"ka_method",           PARAM_STR, &ul_ka_method},
 	{"ka_filter",           PARAM_INT, &ul_ka_filter},
+	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
 	{0, 0, 0}
 };
 
@@ -396,9 +400,17 @@ static int mod_init(void)
 		ul_set_xavp_contact_clone(1);
 	}
 
-	/* set max partition number for timers processing of db records */
-	if((ul_ka_mode != ULKA_NONE) && (ul_timer_procs > 1)) {
-		ul_set_max_partition((unsigned int)ul_timer_procs);
+	if(ul_ka_mode != ULKA_NONE) {
+		/* set max partition number for timers processing of db records */
+		if (ul_timer_procs > 1) {
+			ul_set_max_partition((unsigned int)ul_timer_procs);
+		}
+		if(ul_ka_logmsg.len > 0) {
+			if(pv_parse_format(&ul_ka_logmsg, &ul_ka_logfmt) < 0) {
+				LM_ERR("failed parsing ka log message format\n");
+				return -1;
+			}
+		}
 	}
 
 	init_flag = 1;