Skip to content
Snippets Groups Projects
Commit 3626d497 authored by Reidar Cederqvist's avatar Reidar Cederqvist Committed by Sukru Senli
Browse files

asterisk: voice.asterisk: fix call_logs with lots of entries

Improved the logic to decrease the call response

Limit the logs to 100 to avoid ubus call timeout.
parent 3bc54294
Branches calllog
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
. /usr/share/libubox/jshn.sh
. /lib/voice/utils.sh
CALL_LOG_FILE="/var/log/asterisk/cdr-csv/Master.csv"
case "$1" in
list)
echo '{ "status" : {}, "lines" : {}, "codecs" : {}, "call_log" : {}, "supported_countries" : {} }'
......@@ -84,40 +86,72 @@ case "$1" in
json_init
json_add_array "call_log"
[ -f /var/log/asterisk/cdr-csv/Master.csv ] || {
[ -f ${CALL_LOG_FILE} ] || {
json_dump
return
}
while read -r line
do
line="$(echo $line | tr -d '\"')"
uniqueid="$(echo $line | awk -F',' '{print $(NF-1)}')"
echo $uniqueid | grep "[A-Z,a-z]" && continue
from="$(echo $line | cut -d',' -f2)"
to="$(echo $line | cut -d',' -f3)"
# "from" will be empty for call log of internal call (beween extension numbers)
[ -z "$from" ] && [ -z "$to" ] && continue
account="$(echo $line | cut -d',' -f4)"
tail -200 ${CALL_LOG_FILE} | sed -n '1!G;h;$p' > ${CALL_LOG_FILE}.tmp
num_entries=0
sip_service_providers=$(uci show $VOICE_UCI_CONFIG | grep sip_service_provider)
sip_user=$(uci show $VOICE_UCI_CONFIG | grep user)
old_ifs=$IFS
while read -r line
do
line_whithout_quotes=$(echo $line | tr -d '"')
IFS=,
set -- $line_whithout_quotes
IFS=$old_ifs
n_args=$#
eval "uniqueid=\$$n_args"
case $uniqueid in
[A-Z,a-z]+) continue ;;
esac
source="$2"
destination="$3"
# "source" will be empty for call log of internal call (beween extension numbers)
[ -z "$source" ] && [ -z "$destination" ] && continue
account="$4"
#Filter out a trailing -outgoing from the SIP account name
#This will have been added if a direct_dial number was used
account=${account%-outgoing}
actok=0
uci show $VOICE_UCI_CONFIG | grep sip_service_provider | grep -wq "$account" && actok=1
# match "sip0" in "$VOICE_UCI_CONFIG.sip0=sip_service_provider"
case $sip_service_providers in
*.$account=*) actok=1 ;;
esac
[ "$account" == "call_line" ] && actok=1
[ $actok -eq 0 ] && continue
timestart="$(echo $line | awk -F',' '{print $(NF-8)}')"
timend="$(echo $line | awk -F',' '{print $(NF-6)}')"
startdate=$(date -u -d "$timestart" +"%s")
enddate=$(date -u -d "$timend" +"%s")
uci show $VOICE_UCI_CONFIG | grep user | grep -wq "$from" && direction="OUTGOING" || direction="INCOMING"
ts=$((n_args-7))
eval "time_start=\$$ts"
dp=$((n_args-2))
eval "disposition=\$$dp"
# match "user0" from "$VOICE_UCI_CONFIG.user0=sip_user"
case $sip_user in
*.$source=*) direction="OUTGOING" ;;
*) direction="INCOMING" ;;
esac
du=$((n_args-4))
eval "duration=\$$du"
json_add_object ""
json_add_string uniqueid "$uniqueid"
json_add_string time "$timestart"
json_add_int duration $((enddate - startdate))
json_add_string disposition "$(echo $line | awk -F',' '{print $(NF-3)}')"
json_add_string direction "$direction"
json_add_string from "$from"
json_add_string to "$to"
json_add_string uniqueid "$uniqueid"
json_add_string time "$time_start"
json_add_int duration "$duration"
json_add_string disposition "$disposition"
json_add_string direction "$direction"
json_add_string from "$source"
json_add_string to "$destination"
json_select ..
done < /var/log/asterisk/cdr-csv/Master.csv
num_entries=$((num_entries+1))
if [ $num_entries -ge 100 ]; then
break
fi
done < ${CALL_LOG_FILE}.tmp
rm ${CALL_LOG_FILE}.tmp
json_dump
;;
supported_countries)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment