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 771ed33b07)
changes/69/34369/3
Marco Capetta 6 years ago
parent e39599d4fd
commit 324fc8d3e5

@ -34,16 +34,20 @@ fi
REDIS_DB="$(ngcp-dlgcnt-clean -c 2>/dev/null|| echo 4)" REDIS_DB="$(ngcp-dlgcnt-clean -c 2>/dev/null|| echo 4)"
host="$(ngcp-dlgcnt-clean -C 2>/dev/null|| echo localhost)" host="$(ngcp-dlgcnt-clean -C 2>/dev/null|| echo localhost)"
# full list # redis full list
REDIS_CALLIDS=$(mktemp) 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 # 'lists:' belongs to dlglist
REDIS_CALLIDS_FILTER=$(mktemp) 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 while read -r i ; do
if ! ngcp-sercmd proxy dlg.dlg_list -- "$i"| \ if ! grep -q -- "$i" "$KAMAILIO_DIALOGS"
awk '/call-id:/ { print $NF}'| grep -q -- "$i"
then then
printf "CallID:[%s] unknown\n" "$i" printf "CallID:[%s] unknown\n" "$i"
if $REMOVE ; then if $REMOVE ; then
@ -55,4 +59,4 @@ while read -r i ; do
fi fi
done < "$REDIS_CALLIDS_FILTER" done < "$REDIS_CALLIDS_FILTER"
rm -f "$REDIS_CALLIDS" "$REDIS_CALLIDS_FILTER" rm -f "$KAMAILIO_DIALOGS" "$REDIS_CALLIDS" "$REDIS_CALLIDS_FILTER"

@ -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: <sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>
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 "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": "<sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>",
"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_caller: 390649904073 "recent_calls_user_online": "1"
} },
{ {
start_time: 1480083143 "recent_calls_caller": "390649904073"
} },
{ {
callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "start_time": "1480083143"
} },
{ {
recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec"
} },
{ {
lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080 "recent_calls_key": "38de282f-5c5c-4d71-8a0d-b300a68d86ec"
},
{
"lua_dlg_callid": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5080"
}
} }
} }
} ]

@ -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: <sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>
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 "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": "<sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>",
"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_caller: 390649904073 "recent_calls_user_online": "1"
} },
{ {
start_time: 1480083143 "recent_calls_caller": "390649904073"
} },
{ {
callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "start_time": "1480083143"
} },
{ {
recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec"
} },
{ {
lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060 "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: <sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>
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 "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": "<sip:203.0.113.113;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:46.29.177.34;r2=on;lr;ftag=as2da8b920;ngcplb=yes;socket=udp:46.29.177.34:5060>,<sip:81.201.82.45;lr=on>",
"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_caller: 390649904073 "recent_calls_user_online": "1"
} },
{ {
start_time: 1480083143 "recent_calls_caller": "390649904073"
} },
{ {
callee_uuid: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "start_time": "1480083143"
} },
{ {
recent_calls_key: 38de282f-5c5c-4d71-8a0d-b300a68d86ec "callee_uuid": "38de282f-5c5c-4d71-8a0d-b300a68d86ec"
} },
{ {
lua_dlg_callid: WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1 "recent_calls_key": "38de282f-5c5c-4d71-8a0d-b300a68d86ec"
},
{
"lua_dlg_callid": "WSGH2SB52VHYLPX4VQQ6N4B2ZM@81.201.82.107:5060-pbx_1"
}
} }
} }
} ]

@ -119,7 +119,7 @@ class TestDlgCnt(unittest.TestCase):
def test_noredisconf(self): def test_noredisconf(self):
create_prog(os.path.join(FAKE_BIN, 'ngcp-dlgcnt-clean'), create_prog(os.path.join(FAKE_BIN, 'ngcp-dlgcnt-clean'),
'echo "error" >&2; false') 'echo "error" >&2; false')
create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'),
"true") "true")
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
"%s; true" % FAKE_REDIS_HELPER) "%s; true" % FAKE_REDIS_HELPER)
@ -128,7 +128,7 @@ class TestDlgCnt(unittest.TestCase):
self.checkNotCmd() self.checkNotCmd()
def test_redisconf(self): def test_redisconf(self):
create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'),
"true") "true")
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
"%s; true" % FAKE_REDIS_HELPER) "%s; true" % FAKE_REDIS_HELPER)
@ -137,7 +137,7 @@ class TestDlgCnt(unittest.TestCase):
self.checkNotCmd() self.checkNotCmd()
def test_empty(self): def test_empty(self):
create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'),
"true") "true")
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
"true") "true")
@ -146,7 +146,7 @@ class TestDlgCnt(unittest.TestCase):
self.checkNotCmd() self.checkNotCmd()
def test_empty_line(self): def test_empty_line(self):
create_prog(os.path.join(FAKE_BIN, 'ngcp-sercmd'), create_prog(os.path.join(FAKE_BIN, 'ngcp-kamctl'),
"echo") "echo")
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
"echo") "echo")
@ -156,7 +156,7 @@ class TestDlgCnt(unittest.TestCase):
def test_okredis(self): def test_okredis(self):
FAKE_DLG = os.path.join(FIXTURES, 'okredis.dlg') 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)) "cat %s" % (FAKE_DLG))
FAKE_REDIS = os.path.join(FIXTURES, 'okredis.redis') FAKE_REDIS = os.path.join(FIXTURES, 'okredis.redis')
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
@ -167,7 +167,7 @@ class TestDlgCnt(unittest.TestCase):
def test_koredis(self): def test_koredis(self):
FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') 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)) "cat %s" % (FAKE_DLG))
FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis')
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
@ -179,7 +179,7 @@ class TestDlgCnt(unittest.TestCase):
def test_kodlgclean(self): def test_kodlgclean(self):
FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') 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)) "cat %s" % (FAKE_DLG))
FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis')
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),
@ -193,7 +193,7 @@ class TestDlgCnt(unittest.TestCase):
def test_kolistclean(self): def test_kolistclean(self):
FAKE_DLG = os.path.join(FIXTURES, 'koredis.dlg') 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)) "cat %s" % (FAKE_DLG))
FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis') FAKE_REDIS = os.path.join(FIXTURES, 'koredis.redis')
create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'), create_prog(os.path.join(FAKE_BIN, 'ngcp-redis-helper'),

Loading…
Cancel
Save