Module: kamailio
Branch: master
Commit: 0d912f11c9618ea399b81fe7d38faf335fe911c7
URL:
https://github.com/kamailio/kamailio/commit/0d912f11c9618ea399b81fe7d38faf3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-03-28T10:11:54+01:00
usrloc: fexible logging for roundtrip details
- new params ka_loglevel and ka_logmsg
---
Modified: src/modules/usrloc/ul_keepalive.c
Modified: src/modules/usrloc/usrloc_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/0d912f11c9618ea399b81fe7d38faf3…
Patch:
https://github.com/kamailio/kamailio/commit/0d912f11c9618ea399b81fe7d38faf3…
---
diff --git a/src/modules/usrloc/ul_keepalive.c b/src/modules/usrloc/ul_keepalive.c
index 7955efa14b..0addb21a42 100644
--- a/src/modules/usrloc/ul_keepalive.c
+++ b/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;
}
diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c
index 0cceb0b0e5..8d3cfffdbf 100644
--- a/src/modules/usrloc/usrloc_mod.c
+++ b/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;