From 324fc8d3e506655e37304edb87c1e2df83f6638d Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Wed, 16 Oct 2019 10:32:03 +0200 Subject: [PATCH] TT#68058 Improve ngcp-dlgcnt-check script in case of high traffic The script collects all the callID from redis, then, one by one it checks if callID exist in kamailo. At this time a call existing in redis before may be destroyed in kamailio dlg.list. And so script believe it's a stuck call. Solution: collect CallID from REDIS and kamailio.dlg at the same time, and compare afterwards. Change-Id: I233a498e42bf5113b5b11ea688487e1840cd84a6 (cherry picked from commit 771ed33b07249f8e4e46ec8d55ec7b851294e774) --- scripts/ngcp-dlgcnt-check | 16 +-- tests/fixtures/koredis.dlg | 104 ++++++++++--------- tests/fixtures/okredis.dlg | 206 +++++++++++++++++++------------------ tests/test_dlgcnt.py | 16 +-- 4 files changed, 175 insertions(+), 167 deletions(-) diff --git a/scripts/ngcp-dlgcnt-check b/scripts/ngcp-dlgcnt-check index 731492f..0fc9d63 100755 --- a/scripts/ngcp-dlgcnt-check +++ b/scripts/ngcp-dlgcnt-check @@ -34,16 +34,20 @@ fi REDIS_DB="$(ngcp-dlgcnt-clean -c 2>/dev/null|| echo 4)" host="$(ngcp-dlgcnt-clean -C 2>/dev/null|| echo localhost)" -# full list +# redis full list REDIS_CALLIDS=$(mktemp) -ngcp-redis-helper -h "$host" -n "$REDIS_DB" dump | egrep -v "^$" > "$REDIS_CALLIDS" || true +ngcp-redis-helper -h "$host" -n "$REDIS_DB" dump | grep -E -v "^$" > "$REDIS_CALLIDS" || true + +# kamailio full dialogs (no ngcp-kamcmd because in fails in case of large output) +KAMAILIO_DIALOGS=$(mktemp) +ngcp-kamctl proxy fifo dlg.list | awk '/"call-id":/ { print $NF}' > "$KAMAILIO_DIALOGS" || true + # 'lists:' belongs to dlglist REDIS_CALLIDS_FILTER=$(mktemp) -egrep -v '^list:' "$REDIS_CALLIDS" > "$REDIS_CALLIDS_FILTER" || true +grep -E -v '^list:' "$REDIS_CALLIDS" > "$REDIS_CALLIDS_FILTER" || true while read -r i ; do - if ! ngcp-sercmd proxy dlg.dlg_list -- "$i"| \ - awk '/call-id:/ { print $NF}'| grep -q -- "$i" + if ! grep -q -- "$i" "$KAMAILIO_DIALOGS" then printf "CallID:[%s] unknown\n" "$i" if $REMOVE ; then @@ -55,4 +59,4 @@ while read -r i ; do fi done < "$REDIS_CALLIDS_FILTER" -rm -f "$REDIS_CALLIDS" "$REDIS_CALLIDS_FILTER" +rm -f "$KAMAILIO_DIALOGS" "$REDIS_CALLIDS" "$REDIS_CALLIDS_FILTER" diff --git a/tests/fixtures/koredis.dlg b/tests/fixtures/koredis.dlg index 2e7fdb4..62e79df 100644 --- a/tests/fixtures/koredis.dlg +++ b/tests/fixtures/koredis.dlg @@ -1,51 +1,53 @@ -{ - h_entry: 51 - h_id: 3315 - call-id: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080 - from_uri: sip:390649904073@voxbone.com - to_uri: sip:390240708163@46.29.177.34 - state: 4 - start_ts: 1480083143 - init_ts: 1480083140 - timeout: 1480126343 - lifetime: 43200 - dflags: 512 - sflags: 0 - iflags: 0 - caller: { - tag: as2da8b920 - contact: sip:390649904073@81.201.82.107:5060;transport=udp - cseq: 102 - route_set: ,, - socket: udp:203.0.113.113:5062 - } - callee: { - tag: 2B56584B-583846C4000C078A-A5F9B700 - contact: sip:390240708163@203.0.113.113:5080 - cseq: 0 - route_set: - socket: udp:203.0.113.113:5062 - } - profiles: { - } - variables: { - { - recent_calls_user_online: 1 - } - { - recent_calls_caller: 390649904073 - } - { - start_time: 1480083143 - } - { - callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080 - } - } -} +[ + { + "h_entry": 51, + "h_id": 3315, + "call-id": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080", + "from_uri": "sip:390649904073@voxbone.com", + "to_uri": "sip:390240708163@46.29.177.34", + "state": 4, + "start_ts": 1480083143, + "init_ts": 1480083140, + "timeout": 1480126343, + "lifetime": 43200, + "dflags": 512, + "sflags": 0, + "iflags": 0, + "caller": { + "tag": "as2da8b920", + "contact": "sip:390649904073@81.201.82.107:5060;transport=udp", + "cseq": "102", + "route_set": ",,", + "socket": "udp:203.0.113.113:5062" + }, + "callee": { + "tag": "2B56584B-583846C4000C078A-A5F9B700", + "contact": "sip:390240708163@203.0.113.113:5080", + "cseq": "0", + "route_set": "", + "socket": "udp:203.0.113.113:5062" + }, + "profiles": { + }, + "variables": { + { + "recent_calls_user_online": "1" + }, + { + "recent_calls_caller": "390649904073" + }, + { + "start_time": "1480083143" + }, + { + "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "recent_calls_key": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "lua_dlg_callid": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080" + } + } + } +] \ No newline at end of file diff --git a/tests/fixtures/okredis.dlg b/tests/fixtures/okredis.dlg index 604bcbe..a19f7ed 100644 --- a/tests/fixtures/okredis.dlg +++ b/tests/fixtures/okredis.dlg @@ -1,102 +1,104 @@ -{ - h_entry: 51 - h_id: 3315 - call-id: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060 - from_uri: sip:390649904073@voxbone.com - to_uri: sip:390240708163@46.29.177.34 - state: 4 - start_ts: 1480083143 - init_ts: 1480083140 - timeout: 1480126343 - lifetime: 43200 - dflags: 512 - sflags: 0 - iflags: 0 - caller: { - tag: as2da8b920 - contact: sip:390649904073@81.201.82.107:5060;transport=udp - cseq: 102 - route_set: ,, - socket: udp:203.0.113.113:5062 - } - callee: { - tag: 2B56584B-583846C4000C078A-A5F9B700 - contact: sip:390240708163@203.0.113.113:5080 - cseq: 0 - route_set: - socket: udp:203.0.113.113:5062 - } - profiles: { - } - variables: { - { - recent_calls_user_online: 1 - } - { - recent_calls_caller: 390649904073 - } - { - start_time: 1480083143 - } - { - callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060 - } - } -} -{ - h_entry: 52 - h_id: 3316 - call-id: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1 - from_uri: sip:390649904073@voxbone.com - to_uri: sip:390240708163@46.29.177.34 - state: 4 - start_ts: 1480083143 - init_ts: 1480083140 - timeout: 1480126343 - lifetime: 43200 - dflags: 512 - sflags: 0 - iflags: 0 - caller: { - tag: as2da8b920 - contact: sip:390649904073@81.201.82.107:5060;transport=udp - cseq: 102 - route_set: ,, - socket: udp:203.0.113.113:5062 - } - callee: { - tag: 2B56584B-583846C4000C078A-A5F9B700 - contact: sip:390240708163@203.0.113.113:5080 - cseq: 0 - route_set: - socket: udp:203.0.113.113:5062 - } - profiles: { - } - variables: { - { - recent_calls_user_online: 1 - } - { - recent_calls_caller: 390649904073 - } - { - start_time: 1480083143 - } - { - callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec - } - { - lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1 - } - } -} +[ + { + "h_entry": 51, + "h_id": 3315, + "call-id": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060", + "from_uri": "sip:390649904073@voxbone.com", + "to_uri": "sip:390240708163@46.29.177.34", + "state": 4, + "start_ts": 1480083143, + "init_ts": 1480083140, + "timeout": 1480126343, + "lifetime": 43200, + "dflags": 512, + "sflags": 0, + "iflags": 0, + "caller": { + "tag": "as2da8b920", + "contact": "sip:390649904073@81.201.82.107:5060;transport=udp", + "cseq": "102", + "route_set": ",,", + "socket": "udp:203.0.113.113:5062" + }, + "callee": { + "tag": "2B56584B-583846C4000C078A-A5F9B700", + "contact": "sip:390240708163@203.0.113.113:5080", + "cseq": "0", + "route_set": "", + "socket": "udp:203.0.113.113:5062" + }, + "profiles": { + }, + "variables": { + { + "recent_calls_user_online": "1" + }, + { + "recent_calls_caller": "390649904073" + }, + { + "start_time": "1480083143" + }, + { + "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "recent_calls_key": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "lua_dlg_callid": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060" + } + } + }, + { + "h_entry": 52, + "h_id": 3316, + "call-id": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1", + "from_uri": "sip:390649904073@voxbone.com", + "to_uri": "sip:390240708163@46.29.177.34", + "state": 4, + "start_ts": 1480083143, + "init_ts": 1480083140, + "timeout": 1480126343, + "lifetime": 43200, + "dflags": 512, + "sflags": 0, + "iflags": 0, + "caller": { + "tag": "as2da8b920", + "contact": "sip:390649904073@81.201.82.107:5060;transport=udp", + "cseq": "102", + "route_set": ",,", + "socket": "udp:203.0.113.113:5062", + }, + "callee": { + "tag": "2B56584B-583846C4000C078A-A5F9B700", + "contact": "sip:390240708163@203.0.113.113:5080", + "cseq": "0", + "route_set": "", + "socket": "udp:203.0.113.113:5062", + }, + "profiles": { + }, + "variables": { + { + "recent_calls_user_online": "1" + }, + { + "recent_calls_caller": "390649904073" + }, + { + "start_time": "1480083143" + }, + { + "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "recent_calls_key": "38de282f-5c5c-4d71-8a0d-b300a68d86ec" + }, + { + "lua_dlg_callid": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1" + } + } + } +] \ No newline at end of file diff --git a/tests/test_dlgcnt.py b/tests/test_dlgcnt.py index 3e2fd49..36668d1 100755 --- a/tests/test_dlgcnt.py +++ b/tests/test_dlgcnt.py @@ -119,7 +119,7 @@ class TestDlgCnt(unittest.TestCase): def test_noredisconf(self): create_prog(os.path.join(FAKE_BIN, 'ngcp-dlgcnt-clean'), 'echo "error" >&2; false') - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "true") create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), "%s; true" % FAKE_REDIS_HELPER) @@ -128,7 +128,7 @@ class TestDlgCnt(unittest.TestCase): self.checkNotCmd() def test_redisconf(self): - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "true") create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), "%s; true" % FAKE_REDIS_HELPER) @@ -137,7 +137,7 @@ class TestDlgCnt(unittest.TestCase): self.checkNotCmd() def test_empty(self): - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "true") create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), "true") @@ -146,7 +146,7 @@ class TestDlgCnt(unittest.TestCase): self.checkNotCmd() def test_empty_line(self): - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "echo") create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), "echo") @@ -156,7 +156,7 @@ class TestDlgCnt(unittest.TestCase): def test_okredis(self): FAKE_DLG = os.path.join(FIXTURES, 'okredis.dlg') - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "cat %s" % (FAKE_DLG)) FAKE_REDIS = os.path.join(FIXTURES, 'okredis.redis') create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), @@ -167,7 +167,7 @@ class TestDlgCnt(unittest.TestCase): def test_koredis(self): FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "cat %s" % (FAKE_DLG)) FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), @@ -179,7 +179,7 @@ class TestDlgCnt(unittest.TestCase): def test_kodlgclean(self): FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "cat %s" % (FAKE_DLG)) FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), @@ -193,7 +193,7 @@ class TestDlgCnt(unittest.TestCase): def test_kolistclean(self): FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') - create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), + create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'), "cat %s" % (FAKE_DLG)) FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),