# doccm.awk #/* #************************************************************************* #** * #** Copyright (C) 1992-2020 Trans-Mit Pty. Ltd. Melbourne Australia * #** This software may not be loaned, resold, changed or copied * #** in any way without the express written permission of author * #** and Trans-Mit Pty. Ltd., Australia. * #** * #************************************************************************* #** #** $Header: /u/catcom/AccTraf/src/clupoll/RCS/doccm.awk,v 1.43 2020/11/10 05:51:44 catcom Exp $ #** $Author: catcom $ #** $Date: 2020/11/10 05:51:44 $ #** $Locker: $ #** #************************************************************************* #*/ #---------------------------------------------------------- function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function clip(s) { sub(/[ \t]*$/,"",s) return s } #---------------------------------------------------------- function ld_rtipaddr(rtipaddrfile) { printf("ld_rtipaddr(%s)\n", rtipaddrfile) system("date") while ( (getline aline < rtipaddrfile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) f = 0 siteid = clip(a_arr[++f]) routeid = clip(a_arr[++f]) trunklocalid = clip(a_arr[++f]) ipaddr = clip(a_arr[++f]) device = clip(a_arr[++f]) ipaddrdev = ipaddr if ( device != "" ) ipaddrdev = ipaddrdev ":" device ipaddrdev_to_trunklocalid_arr[ipaddrdev] = trunklocalid print " ipaddrdev_to_trunklocalid_arr[" ipaddrdev "] = [" ipaddrdev_to_trunklocalid_arr[ipaddrdev] "]" } close(rtipaddrfile) } #---------------------------------------------------------- BEGIN { printf("STARTCLPSEND:\n") >> ccmcluoutfile; reccount = -1; hextodecarr["0"] = 0; hextodecarr["1"] = 1; hextodecarr["2"] = 2; hextodecarr["3"] = 3; hextodecarr["4"] = 4; hextodecarr["5"] = 5; hextodecarr["6"] = 6; hextodecarr["7"] = 7; hextodecarr["8"] = 8; hextodecarr["9"] = 9; hextodecarr["a"] = 10; hextodecarr["A"] = 10; hextodecarr["b"] = 11; hextodecarr["B"] = 11; hextodecarr["c"] = 12; hextodecarr["C"] = 12; hextodecarr["d"] = 13; hextodecarr["D"] = 13; hextodecarr["e"] = 14; hextodecarr["E"] = 14; hextodecarr["f"] = 15; hextodecarr["F"] = 15; print "doccm.awk:" print "" print "ccmcluoutfile = [" ccmcluoutfile "]" print " ccmerrfile = [" ccmerrfile "]" errout = sprintf("sort -u >>%s", ccmerrfile) printf("errout=[%s]\n", errout); printf("lo=%s\n", ccmipphlo); printf("hi=%s\n", ccmipphhi); nipextlo = split(ccmipphlo, ipextlo, " "); nipexthi = split(ccmipphhi, ipexthi, " "); # no ranges or different count if ( nipextlo == 0 || nipexthi == 0 || niextlo != niexthi ) { print( "doccm: ip phone ranges not set or bad in envfile\n"); exit(1); } ndevnames = split(ccmdevicenamelist, devname_arr, " "); if ( ccmloglevel >= 1 ) { printf("config - ccmdevicenamelist= %s\n", ccmdevicenamelist) } for ( i = 1; i <= ndevnames; ++ i ) { devname = devname_arr[i] devname_to_devid_arr[devname] = i if ( ccmloglevel >= 1 ) { printf("config - devname_to_devid_arr[%s] = %s\n", devname, devname_to_devid_arr[devname]) } } IPADDRfmt += 0 printf("config - inlet/oulet IPADDRfmt = %d\n", IPADDRfmt) if ( IPADDRfmt == 1 ) { print "Using 32 bit signed integer representation of IP addresds for trunklocalid" } else if ( IPADDRfmt == 2 ) { prin "Using IP address in dot notation" } else if ( IPADDRfmt == 3 ) { print "Using trunklocalid from rtipaddr table orig IP lookup" } else { # using last 2 octets for trunklocalid print "config - default to last 2 octets for trunklocalid\n" } useccmdevicenames += 0 printf("config - inlet/oulet useccmdevicenames = %d\n", useccmdevicenames) if ( useccmdevicenames != 0 ) { if ( IPADDRfmt == 3 ) print "Using device name for rtipaddr trunklocalid lookup" if ( IPADDRfmt == 0 ) print "preceding last 2 octets with device name index" } nextnalters= split(ccmextnalterlist, extnalter_arr, "|"); if ( ccmloglevel >= 1 ) { printf("config - ccmextnalterlist= %s\n", ccmextnalterlist) } for ( i = 1; i <= nextnalters; ++ i ) { extnalter = extnalter_arr[i] if ( extnalter == "" ) continue split(extnalter, extnalter_item_arr, ","); ndigits_before[i] = sprintf("%d", extnalter_item_arr[1]) digits_prefix[i] = sprintf("%s", extnalter_item_arr[2]) digits_start[i] = sprintf("%d", extnalter_item_arr[3]) ndigits_after[i] = sprintf("%d", extnalter_item_arr[4]) return_prefix[i] = sprintf("%s", extnalter_item_arr[5]) return_postfix[i] = sprintf("%s", extnalter_item_arr[6]) if ( ccmloglevel >= 1 ) { printf("config - extnalter = [%s]\n", extnalter) printf(" ndigits_before[%d] = %d\n", i, ndigits_before[i]) printf(" digits_prefix[%d] = %s\n", i, digits_prefix[i]) printf(" digits_start[%d] = %d\n", i, digits_start[i]) printf(" ndigits_after[%d] = %d\n", i, ndigits_after[i]) printf(" return_prefix[%d] = %s\n", i, return_prefix[i]) printf(" return_postfix[%d] = %s\n", i, return_postfix[i]) } } print "CCMCDRVER=[" CCMCDRVER "]" print "CCMCDRSKIPFIRST=[" CCMCDRSKIPFIRST "]" splitinternal = ENVIRON["splitinternal"] print "splitinternal=[" splitinternal "]" nodename = ENVIRON["nodename"] print "nodename=[" nodename "]" dovideo = ENVIRON["dovideo"] print "dovideo=[" dovideo "]" gateways_override_ip_phones = 0 + ENVIRON["gateways_override_ip_phones"] print "gateways_override_ip_phones=[" gateways_override_ip_phones "]" splitdiverted_gateway_trunlocalid = ENVIRON["splitdiverted_gateway_trunlocalid"] print "splitdiverted_gateway_trunlocalid=[" splitdiverted_gateway_trunlocalid "]" log_conferenace_as_internal log_conferenace_as_internal = ENVIRON["log_conferenace_as_internal"] if ( log_conferenace_as_internal == "" ) log_conferenace_as_internal = 0 print "log_conferenace_as_internal=[" log_conferenace_as_internal "]" IPFILTER1 = ENVIRON["IPFILTER1"] print "IPFILTER1=[" IPFILTER1 "]" # load data to translate gw IP adresses to telmax21 trunklocalid ld_rtipaddr(rtipaddrfile) } function hextodec(hexstr) { #printf("hexstr = %s ", hexstr); decval = 0; for ( i = 1; i <= length(hexstr); ++i ) { s = substr(hexstr,i,1); #printf(" i=%d s = %s", i, s); decval = (decval * 16) + hextodecarr[s]; } #printf(" decval = %s\n", decval); return decval; } function is_ipphone(partynumber) { if ( ccmloglevel >= 9 ) { printf("is_ipphone(%s)\n", partynumber) } if ( partynumber != "" && length(partynumber) <= 9 ) { extn = int(partynumber) printf(" extn=%d\n", extn) for ( i in ipextlo ) { if ( ccmloglevel >= 9 ) { printf("extn=%s ipextlo[%d]=%s ipexthi[%d]=%s\n", extn, i, ipextlo[i], i, ipexthi[i]); } if ( int(extn) >= int(ipextlo[i]) && int(extn) <= int(ipexthi[i]) ) { if ( ccmloglevel >= 9 ) { print "is ip phone" } return 1; } } } if ( ccmloglevel >= 9 ) { print "is NOT ip phone" } return 0; } function handle_partynumber(partynumberstr) { matchedpn = "not matched" # remove these before the translation rules are appplied (ie +61..) gsub("[#*+ ]","",partynumberstr) partynumber = partynumberstr if ( ccmloglevel >= 9 ) { printf("handle_partynumber(%s) partynumber=[%s]\n", partynumberstr, partynumber) } #if ( (partynumberstr + 0) > 9999 ) { if ( length(partynumberstr) > 0 ) { #fst2 = substr(partynumberstr,1,2) #fst3 = substr(partynumberstr,1,3) #if (length(partynumberstr) == 6) { # if (fst3 == "382") # partynumber = substr(partynumberstr,4,3) # if (fst2 == "32" || fst2 == "33" || fst2 == "37") # partynumber = substr(partynumberstr,3,4) #} #else { # partynumber = 0 #} # handle extn alter config list for ( i = 1; i <= nextnalters; ++ i ) { # yyyXXXzzz = passed party number string # ndigits_before[i] = number of y's X's z's # digits_prefix[i] = yyy # digits_start[i] = offset to first z (starting from 1) # ndigits_after[i] = number of z's # return_prefix[i] = pp # return_postfix[i] = PP # ppzzzPP = partynumber to return #print "length(" partynumberstr ")=" length(partynumberstr) #print "ndigits_before[" i "]= " ndigits_before[i] if (length(partynumberstr) == ndigits_before[i]) { dpref = digits_prefix[i] #print "dpref=[" dpref "]" #print "substr(" partynumberstr ",1," length(dpref) ")=[" substr(partynumberstr,1,length(dpref)) "]" if (substr(partynumberstr,1,length(dpref)) == dpref) { if (digits_start[i] > 0 && ndigits_after[i] > 0) partofpnstr = substr(partynumberstr, digits_start[i], ndigits_after[i]) else partofpnstr = "" partynumber = return_prefix[i] partofpnstr return_postfix[i] matchedpn = "matched" if ( ccmloglevel >= 9 ) { printf("extnalter: handle_partynumber(%s) partynumber = [%s]\n", partynumberstr, partynumber) } break } } } } ###gsub("[#]","",partynumber) ##gsub("[#*]","",partynumber) #gsub("[#*+]","",partynumber) # leave rest ## strip any non numberic #gsub("[^0-9]","",partynumber) if ( ccmloglevel >= 9 ) { printf("PN translation (%s) -> [%s] %s {%s}\n", partynumberstr, partynumber, matchedpn, nodename) } return partynumber } function handle_devname(inoutno,devname) { # prepend configured deviceID from DeviceName lookup devid = devname_to_devid_arr[devname] if ( ccmloglevel >= 9 ) { printf("devname_to_devid_arr[%s] = %s\n", devname, devname_to_devid_arr[devname]) } if ( devid != "" ) { if ( ccmloglevel >= 2 ) { printf("prepend [%s] to inoutno=%s\n", devid, inoutno) } inoutno = sprintf("%s%06d", devid, inoutno) } return inoutno } function handle_PNPartition(partynumberpartition) { #return "" #PNPprefix = partynumberpartition #re = "IDDPT|InternalPT|LocalPT|MobilePT|OnlyPT|Partition|STDMobilePT|STDPT|PT" ##re = "InternalPT" #if ( sub(re, "", PNPprefix) <= 0 ) # PNPprefix = "" PNPprefix = "" if ( PartitionPrefixList != "" ) { re = PartitionPrefixList if ( match(partynumberpartition,re) > 0 ) PNPprefix = substr(partynumberpartition,RSTART,RLENGTH) } print "handle_PNPartition(" partynumberpartition ") PNPprefix=[" PNPprefix "]" print " PartitionPrefixList=[" PartitionPrefixList "]" return PNPprefix } function get_TZ_for_PartitionPrefix(destPNP) { pptzvar = "PPTZ_" destPNP pptz = ENVIRON[pptzvar] if ( pptz == "" ) pptz = "default" print "get_TZ_for_PartitionPrefix(" destPNP ")" " pptzvar=[" pptzvar "]" " pptz=[" pptz "]" return pptz } { if ( NR <= CCMCDRSKIPFIRST ) next if ( ccmloglevel >= 9 ) { print "Loop" } if ( doccmrawoutfile != "" ) print $0 >> doccmrawoutfile #################### cdrfields = NF # override configured version confCCMCDRVER = CCMCDRVER CCMCDRVER = 0 if ( cdrfields == 74 ) CCMCDRVER = 5 if ( cdrfields == 75 ) CCMCDRVER = 5.1 if ( cdrfields == 78 ) CCMCDRVER = 6 if ( cdrfields == 82 ) CCMCDRVER = 7.0 if ( cdrfields == 94 ) CCMCDRVER = 7.1 if ( cdrfields == 103 ) CCMCDRVER = 8 if ( cdrfields == 104 ) CCMCDRVER = 8.03 if ( cdrfields == 112 ) CCMCDRVER = 8.5 if ( cdrfields == 118 ) CCMCDRVER = 9.0 if ( cdrfields == 125 ) CCMCDRVER = 10.0 if ( cdrfields == 129 ) CCMCDRVER = 10.5 if ( cdrfields == 133 ) CCMCDRVER = 12.5 if ( CCMCDRVER != 0 ) { # fould a known version nfields = cdrfields } else { CCMCDRVER = confCCMCDRVER } #################### # fields from CDR print "---- cdrfields= " cdrfields " --------- CCMCDRVER=" CCMCDRVER " -----" f = 0 cdrRecordType = $(++f) globalCallID_callManagerId = $(++f) globalCallID_callId = $(++f) origLegCallIdentifier = $(++f) dateTimeOrigination = $(++f) origNodeId = $(++f) origSpan = $(++f) origIpAddr = $(++f) if ( CCMCDRVER < 5 ) { origIpPort = $(++f) } callingPartyNumber = $(++f) if ( CCMCDRVER >= 5 ) { callingPartyUnicodeLoginUserID = $(++f) } origCause_location = $(++f) origCause_value = $(++f) if ( CCMCDRVER >= 5 ) { origPrecedenceLevel = $(++f) } origMediaTransportAddress_IP = $(++f) origMediaTransportAddress_Port = $(++f) origMediaCap_payloadCapability = $(++f) origMediaCap_maxFramesPerPacke = $(++f) origMediaCap_g723BitRate = $(++f) if ( CCMCDRVER >= 5 ) { origVideoCap_Codec = $(++f) origVideoCap_Bandwidth = $(++f) origVideoCap_Resolution = $(++f) origVideoTransportAddress_IP = $(++f) origVideoTransportAddress_Port = $(++f) origRSVPAudioStat = $(++f) origRSVPVideoStat = $(++f) } destLegIdentifier = $(++f) destNodeId = $(++f) destSpan = $(++f) destIpAddr = $(++f) if ( CCMCDRVER < 5 ) { destIpPort = $(++f) } originalCalledPartyNumber = $(++f) finalCalledPartyNumber = $(++f) if ( CCMCDRVER >= 5 ) { finalCalledPartyUnicodeLoginUserID = $(++f) } destCause_location = $(++f) destCause_value = $(++f) if ( CCMCDRVER >= 5 ) { destPrecedenceValue = $(++f) } destMediaTransportAddress_IP = $(++f) destMediaTransportAddress_Port = $(++f) destMediaCap_payloadCapability = $(++f) destMediaCap_maxFramesPerPacke = $(++f) destMediaCap_g723BitRate = $(++f) if ( CCMCDRVER >= 5 ) { destVideoCap_Codec = $(++f) destVideoCap_Bandwidth = $(++f) destVideoCap_Resolution = $(++f) destVideoTransportAddress_IP = $(++f) destVideoTransportAddress_Port = $(++f) destRSVPAudioStat = $(++f) destRSVPVideoStat = $(++f) } dateTimeConnect = $(++f) dateTimeDisconnect = $(++f) lastRedirectDn = $(++f) pkid = $(++f) originalCalledPartyNumberParti = $(++f) callingPartyNumberPartition = $(++f) #print "f=" f " callingPartyNumberPartition=[" callingPartyNumberPartition "]" finalCalledPartyNumberPartitio = $(++f) #print "f=" f " finalCalledPartyNumberPartitio=[" finalCalledcallingPartyNumberPartitio "]" lastRedirectDnPartition = $(++f) #print "f=" f " lastRedirectDnPartition=[" lastRedirectDnPartition "]" duration = $(++f) origDeviceName = $(++f) destDeviceName = $(++f) ##### original cm3 code ended here ##### # from USQ 2/10/2006 if ( CCMCDRVER == 3 ) { origCallTerminationOnBehalfOf = $(++f) destCallTerminationOnBehalfOf = $(++f) origCalledPartyRedirectOnBeha = $(++f) lastRedirectRedirectOnBehalfOf = $(++f) origCalledPartyRedirectReason = $(++f) lastRedirectRedirectReason = $(++f) joinOnBehalfOf = $(++f) destConversationId = $(++f) globalCallId_ClusterID = $(++f) authCodeDescription = $(++f) authorizationLevel = $(++f) clientMatterCode = $(++f) } # from BOM 2/10/2006 if ( CCMCDRVER == 4 ) { origCalledPartyRedirectReason = $(++f) lastRedirectRedirectReason = $(++f) destConversationId = $(++f) origCallTerminationOnBehalfOf = $(++f) destCallTerminationOnBehalfOf = $(++f) origCalledPartyRedirectOnBehal = $(++f) lastRedirectRedirectOnBehalfOf = $(++f) globalCallId_ClusterID = $(++f) joinOnBehalfOf = $(++f) authCodeDescription = $(++f) authorizationLevel = $(++f) callingPartyLoginUserID = $(++f) clientMatterCode = $(++f) comment = $(++f) destPrecedenceLevel = $(++f) destVideoCap_Bandwidth = $(++f) destVideoCap_Codec = $(++f) destVideoCap_Resolution = $(++f) destVideoTransportAddress_IP = $(++f) destVideoTransportAddress_Port = $(++f) finalCalledPartyLoginUserID = $(++f) origPrecedenceLevel = $(++f) origVideoCap_Bandwidth = $(++f) origVideoCap_Codec = $(++f) origVideoCap_Resolution = $(++f) origVideoTransportAddress_IP = $(++f) origVideoTransportAddress_Port = $(++f) } # from Unified Callmanager 5.0 CDR Definition pdf # (also see other CCMCDRVER < 5 and CCMCDRVER >= 5 code above) if ( CCMCDRVER >= 5 ) { origCallTerminationOnBehalfOf = $(++f) destCallTerminationOnBehalfOf = $(++f) origCalledPartyRedirectOnBehal = $(++f) lastRedirectRedirectOnBehalfOf = $(++f) origCalledPartyRedirectReason = $(++f) lastRedirectRedirectReason = $(++f) destConversationId = $(++f) globalCallId_ClusterID = $(++f) joinOnBehalfOf = $(++f) comment = $(++f) authCodeDescription = $(++f) authorizationLevel = $(++f) clientMatterCode = $(++f) origDTMFMethod = $(++f) destDTMFMethod = $(++f) callSecuredStatus = $(++f) } if ( CCMCDRVER >= 6 ) { origConversationId = $(++f) origMediaCap_Bandwidth = $(++f) destMediaCap_Bandwidth = $(++f) } if ( CCMCDRVER >= 5.1 ) { authorizationCodeValue = $(++f) } if ( CCMCDRVER >= 7.0 ) { outpulsedCallingPartyNumber = $(++f) outpulsedCalledPartyNumber = $(++f) origIpv4v6Addr = $(++f) destIpv4v6Addr = $(++f) } if ( CCMCDRVER >= 7.1 ) { origVideoCap_Codec_Channel2 = $(++f) origVideoCap_Bandwidth_Channel2 = $(++f) origVideoCap_Resolution_Channel2 = $(++f) origVideoTransportAddress_IP_Channel2 = $(++f) origVideoTransportAddress_Port_Channel2 = $(++f) origVideoChannel_Role_Channel2 = $(++f) destVideoCap_Codec_Channel2 = $(++f) destVideoCap_Bandwidth_Channel2 = $(++f) destVideoCap_Resolution_Channel2 = $(++f) destVideoTransportAddress_IP_Channel2 = $(++f) destVideoTransportAddress_Port_Channel2 = $(++f) destVideoChannel_Role_Channel2 = $(++f) } if ( CCMCDRVER >= 8 ) { IncomingProtocolID = $(++f) IncomingProtocolCallRef = $(++f) OutgoingProtocolID = $(++f) OutgoingProtocolCallRef = $(++f) currentRoutingReason = $(++f) origRoutingReason = $(++f) lastRedirectingRoutingReason = $(++f) huntPilotPartition = $(++f) huntPilotDN = $(++f) } if ( CCMCDRVER >= 8.03 ) { calledPartyPatternUsage = $(++f) } if ( CCMCDRVER >= 8.5 ) { IncomingICID = $(++f) IncomingOrigIOI = $(++f) IncomingTermIOI = $(++f) OutgoingICID = $(++f) OutgoingOrigIOI = $(++f) OutgoingTermIOI = $(++f) outpulsedOriginalCalledPartyNumber = $(++f) outpulsedLastRedirectingNumber = $(++f) } if ( CCMCDRVER >= 9.0 ) { wasCallQueued = $(++f) totalWaitTimeInQueue = $(++f) callingPartyNumber_uri = $(++f) originalCalledPartyNumber_uri = $(++f) finalCalledPartyNumber_uri = $(++f) lastRedirectDn_uri = $(++f) } if ( CCMCDRVER >= 10.0 ) { mobileCallingPartyNumber = $(++f) finalMobileCalledPartyNumber = $(++f) origMobileDeviceName = $(++f) destMobileDeviceName = $(++f) origMobileCallDuration = $(++f) destMobileCallDuration = $(++f) mobileCallType = $(++f) } if ( CCMCDRVER >= 10.5 ) { originalCalledPartyPattern = $(++f) finalCalledPartyPattern = $(++f) lastRedirectingPartyPattern = $(++f) huntPilotPattern = $(++f) } if ( CCMCDRVER >= 12.5 ) { origDeviceType = $(++f) destDeviceType = $(++f) origDeviceSessionID = $(++f) destDeviceSessionID = $(++f) } if ( ccmloglevel >= 3 ) { printf("\n"); printf("%s\n", $0); } # exclude non connected calls if ( CCMEXCL0DURATION == 1 && duration == 0 ) { if ( ccmloglevel >= 3 ) { printf("Skipping 0 duration\n"); } next } # use t21 host TZ for call call_TZ = "default" #-------------------- # calling party print "callingPartyNumber=[" callingPartyNumber "]" print "callingPartyNumberPartition=[" callingPartyNumberPartition "]" print "" # called party print "finalCalledPartyNumber=[" finalCalledPartyNumber "]" print " lastRedirectDn=[" lastRedirectDn "]" print "usefinalCalledPartyNumber=[" usefinalCalledPartyNumber "]" print "" print " mobileCallingPartyNumber=[" mobileCallingPartyNumber "]" print "finalMobileCalledPartyNumber=[" finalMobileCalledPartyNumber "]" print " origMobileDeviceName=[" origMobileDeviceName "]" print " destMobileDeviceName=[" destMobileDeviceName "]" print " origMobileCallDuration=[" origMobileCallDuration "]" print " destMobileCallDuration=[" destMobileCallDuration "]" print " mobileCallType=[" mobileCallType "]" if ( clientMatterCode != "" ) print " clientMatterCode=[" clientMatterCode "]" print "" # OnBehalfOf Codes print "" print " origCallTerminationOnBehalfOf=[" origCallTerminationOnBehalfOf "]" print " destCallTerminationOnBehalfOf=[" destCallTerminationOnBehalfOf "]" print " origCalledPartyRedirectOnBeha=[" origCalledPartyRedirectOnBeha "]" print " lastRedirectRedirectOnBehalfOf=[" lastRedirectRedirectOnBehalfOf "]" print " joinOnBehalfOf=[" joinOnBehalfOf "]" # Redirect Reason Codes print "" print " origCalledPartyRedirectReason=[" origCalledPartyRedirectReason "]" print " lastRedirectRedirectReason=[" lastRedirectRedirectReason "]" print "" is_video = 0 if ( dovideo == "1" ) { if ( origVideoCap_Codec != "0" || destVideoCap_Codec != "0" ) { is_video = 1 print "VIDEO: origVideoCap_Codec=[" origVideoCap_Codec "]" print " destVideoCap_Codec=[" destVideoCap_Codec "]" print "" } } # IP/Device for calling parting orig_ipaddr = origIpAddr orig_ipport = origIpPort orig_nodeid = origNodeId orig_devicename = substr(origDeviceName,1,54) # IP/Device for called parting dest_ipaddr = destIpAddr dest_ipport = destIpPort dest_nodeid = destNodeId dest_devicename = substr(destDeviceName,1,54) if ( ccmloglevel >= 2 ) { if ( orig_to_dest_header != 1 ) { print "orig_to_dest ,origDeviceName,callingPartyNumber,destDeviceName,lastRedirectDn,finalCalledPartyNumber" orig_to_dest_header = 1 } print "orig_to_dest" "," origDeviceName "," callingPartyNumber "," destDeviceName "," lastRedirectDn "," finalCalledPartyNumber } # if NOT part of conference bridge # and finalCalledartyNumber != lastRedirectDn # then set call is diverted diverted = 0 if (substr(callingPartyNumber,1,1) != "b" && substr(finalCalledartyNumber,1,1) != "b") { if ( finalCalledPartyNumber != "" && lastRedirectDn != "" ) { if ( finalCalledPartyNumber != lastRedirectDn ) { diverted = 1 print "FCPNDIFF" } } } # split diverted calls if ( usefinalCalledPartyNumber == 2 && diverted ) { print "SPLIT DIVERTED" # first callingParting -> lastRedirectDn # set calling party values # calling party callingpnstr = callingPartyNumber callingpnpartition = callingPartyNumberPartition # # set called party values calledpnstr = lastRedirectDn calledpnpartition = lastRedirectDnPartition proccm(1) # then lastRedirectDn -> finalCalledPartyNumber # set calling party values callingpnstr = lastRedirectDn callingpnpartition = lastRedirectDnPartition # # set called party values calledpnstr = finalCalledPartyNumber calledpnpartition = finalCalledPartyNumberPartitio proccm(2) } else { # calling party callingpnstr = callingPartyNumber callingpnpartition = callingPartyNumberPartition # called party calledpnstr = lastRedirectDn; calledpnpartition = lastRedirectDnPartitio # use finalCalledParty field for destination if ( usefinalCalledPartyNumber != 0 ) { calledpnstr = finalCalledPartyNumber; if ( finalCalledParyNumberPartitio != "" ) calledpnpartition = finalCalledPartyNumberPartitio } proccm(0) } } function proccm(val) { #xyzzy print "" print "===========================================" print "proccm(" val ")" print "" print "calling party callinpnstr=[" callingpnstr "]" #original code>>> callingpn = (callingPartyNumber + 0) % 10000 callingpn = handle_partynumber(callingpnstr) print "callingpn=[" callingpn "]" print "" print "called party calledpnstr=[" calledpnstr "]" calledpn = handle_partynumber(calledpnstr) calledpn = substr(calledpn,1,20) print "calledpn=[" calledpn "]" print "" cmt = "" cmt = cmt ", DBG" #cmt = cmt ": globalCallID_callId: " globalCallID_callId #cmt = cmt ", dest_CauseValue: " dest_CauseValue #cmt = cmt ", origCalledPartyRedirectReason: " origCalledPartyRedirectRe on #cmt = cmt ", lastRedirectRedirectReason: " lastRedirectRedirectReason #cmt = cmt ", origTerminationOnBehalfOf: " origTerminationOnBehalfOf #cmt = cmt ", destTerminationOnBehalfOf: " destTerminationOnBehalfOf #cmt = cmt ", origCalledRedirectOnBehalfOf: " origCalledRedirectOnBehalf #cmt = cmt ", lastRedirectRedirectOnBehalfOf: " lastRedirectRedirectOnBe lfOf #cmt = cmt ", joinOnBehalfOf: " joinOnBehalfOf cmt = cmt ", origconversationid: " origconversationid cmt = cmt ", destconversationid: " destconversationid #cmt = cmt ", comment: " comment # is conference bridge (orig) if ( substr(callingpnstr,1,1) == "b" ) { orig_cbridge = 1; if ( cbridgeextn != "" ) { cbridgeid = "orig_" callingpnstr cmt callingpnstr= cbridgeextn; callingpn = callingpnstr } } else { orig_cbridge = 0; } # is conference bridge (dest) if ( substr(calledpnstr,1,1) == "b" ) { dest_cbridge = 1; #calledpnstr= substr(calledpnstr,2); if ( cbridgeextn != "" ) { cbridgeid = "dest_" calledpnstr cmt calledpnstr= cbridgeextn; calledpn = calledpnstr } #else { # calledpnstr= finalCalledPartyNumber # calledpn = calledpnstr #} } else { dest_cbridge = 0; } #if ( cbridge == 1 || orig_ipport == 0 ) if ( orig_cbridge == 1 && cbridgeextn != "" ) { print "calling party is set to cbridgeextn = " cbridgeextn " so orig is ipphone" orig_is_ipphone = 1; } else { print "test callingpn is_ipphone()" orig_is_ipphone = is_ipphone(callingpn); } #if ( cbridge == 1 || dest_ipport == 0 ) if ( dest_cbridge == 1 && cbridgeextn != "" ) { print "called party is set to cbridgeextn = " cbridgeextn " so dest is ipphone" dest_is_ipphone = 1; } else { print "test calledpn is_ipphone()" dest_is_ipphone = is_ipphone(calledpn); } if ( ccmloglevel >= 2 ) { print "callingpn=[" callingpn "]" " <--> " "calledpn=[" calledpn "]" print "orig_cbridge=" orig_cbridge " dest_cbridge=" dest_cbridge print "orig_nodeid=" orig_nodeid " dest_nodeid=" dest_nodeid if ( orig_is_ipphone ) { print "orig is IP Phone based on extranges" } else { print "orig is Not an IP Phone based on extranges" } if ( dest_is_ipphone ) { print "dest is IP Phone based on extranges" } else { print "dest is Not an IP Phone based on extranges" } } #-------------------- hexorigIP = sprintf("%08x", orig_ipaddr); if ( length(hexorigIP) > 8 ) hexorigIP = substr(hexorigIP,length(hexorigIP)-8+1,8) origoctet3dec = hextodec(substr(hexorigIP,1,2)); origoctet2dec = hextodec(substr(hexorigIP,3,2)); origoctet1dec = hextodec(substr(hexorigIP,5,2)); origoctet0dec = hextodec(substr(hexorigIP,7,2)); origipdotnot = sprintf("%d.%d.%d.%d", origoctet0dec, origoctet1dec, origoctet2dec, origoctet3dec); use_orig_last_2_octets = 1 origipaddrdev = "" origdevid = 0 if ( IPADDRfmt == 1 ) { # set to 32 bit signed int representation of orig IP address origiprep = orig_ipaddr use_orig_last_2_octets = 0 } else if ( IPADDRfmt == 2 ) { # set to orig IP address in dot notation origiprep = origipdotnot } else if ( IPADDRfmt == 3 ) { # set to unique trunklocalid from rtipaddr table orig IP lookup origipaddrdev = origipdotnot print "Lookup orig1 ipaddrdev_to_trunklocalid_arr[" origipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[origipaddrdev] "]" origiprep = ipaddrdev_to_trunklocalid_arr[origipaddrdev] if ( origiprep == "" ) { print "orig_devicename=[" orig_devicename "]" if ( useccmdevicenames != 0 && orig_devicename != "" ) { if ( ndevnames > 0 ) # only configured devnames origdevid = devname_to_devid_arr[orig_devicename] else origdevid = -1 # always use device name if ( origdevid != 0 ) origipaddrdev = origipaddrdev ":" orig_devicename } print "Lookup orig2 ipaddrdev_to_trunklocalid_arr[" origipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[origipaddrdev] "]" origiprep = ipaddrdev_to_trunklocalid_arr[origipaddrdev] } if ( origiprep == "" ) { if ( useNodeID ) { # use NodeId origipaddrdev = origipaddrdev ":" orig_nodeid } if ( useSpan ) { # use Span origipaddrdev = origipaddrdev ":" origSpan } if ( usePartition ) { # use Partition origPNP = "" if ( !orig_is_ipphone && dest_is_ipphone ) { # INCOMING origPNP = handle_PNPartition(calledpartypartition) } if ( !orig_is_ipphone && !dest_is_ipphone ) { # TRANSIT # for Transit calls - use dest Partition origPNP = handle_PNPartition(calledpnpartition) } print "origPNP=[" origPNP "]" if ( origPNP != "" ) { # use Partiton prefix for devicename lookup if ( usePartition == 1 || usePartition == 3 ) { print "use Partition prefix to lookup devicename" origipaddrdev = origipaddrdev ":" origPNP } } } print "Lookup orig3 ipaddrdev_to_trunklocalid_arr[" origipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[origipaddrdev] "]" origiprep = ipaddrdev_to_trunklocalid_arr[origipaddrdev] } if ( origiprep != "" ) { # found use_orig_last_2_octets = 0 } else { # try with ignore ipaddr ignore_ipaddrdev = origipaddrdev if ( i = match(ignore_ipaddrdev,":") ) { ignore_ipaddrdev = "ignore" substr(ignore_ipaddrdev,i) origiprep = ipaddrdev_to_trunklocalid_arr[ignore_ipaddrdev] if ( ccmloglevel >= 3 ) print "ignore orig ipaddr, lookup [" ignore_ipaddrdev "] = [" origiprep "]" if ( origiprep != "" ) # found use_orig_last_2_octets = 0 } } } if ( use_orig_last_2_octets ) { # set to last 2 octets of orig IP address origiprep = sprintf("%03d%03d", origoctet2dec, origoctet3dec) + 0; if ( IPADDRfmt == 0 && useccmdevicenames != 0 ) origiprep = handle_devname(origiprep,orig_devicename) } else { # found orig g/w if ( gateways_override_ip_phones > 0 && orig_is_ipphone ) { printf("Gateway override set: ignoring orig IP phone\n", gateways_override_ip_phones) orig_is_ipphone = 0 } } hexdestIP = sprintf("%08x", dest_ipaddr); if ( length(hexdestIP) > 8 ) hexdestIP = substr(hexdestIP,length(hexdestIP)-8+1,8) destoctet3dec = hextodec(substr(hexdestIP,1,2)); destoctet2dec = hextodec(substr(hexdestIP,3,2)); destoctet1dec = hextodec(substr(hexdestIP,5,2)); destoctet0dec = hextodec(substr(hexdestIP,7,2)); destipdotnot = sprintf("%d.%d.%d.%d", destoctet0dec, destoctet1dec, destoctet2dec, destoctet3dec); use_dest_last_2_octets = 1 destipaddrdev = "" destdevid = 0 if ( IPADDRfmt == 1 ) { # set to 32 bit signed int representation of dest IP address destiprep = dest_ipaddr use_dest_last_2_octets = 0 } else if ( IPADDRfmt == 2 ) { # set to dest IP address in dot notation destiprep = destipdotnot use_dest_last_2_octets = 0 } else if ( IPADDRfmt == 3 ) { # set to unique trunklocalid from rtipaddr table dest IP lookup destipaddrdev = destipdotnot print "Lookup dest1 ipaddrdev_to_trunklocalid_arr[" destipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[destipaddrdev] "]" destiprep = ipaddrdev_to_trunklocalid_arr[destipaddrdev] if ( destiprep == "" ) { print "dest_devicename=[" dest_devicename "]" if ( useccmdevicenames != 0 && dest_devicename != "" ) { if ( ndevnames > 0 ) # only configured devnames destdevid = devname_to_devid_arr[dest_devicename] else destdevid = -1 # always use device name if ( destdevid != 0 ) destipaddrdev = destipaddrdev ":" dest_devicename } print "Lookup dest2 ipaddrdev_to_trunklocalid_arr[" destipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[destipaddrdev] "]" destiprep = ipaddrdev_to_trunklocalid_arr[destipaddrdev] } if ( destiprep == "" ) { if ( useNodeID ) { # use NodeId destipaddrdev = destipaddrdev ":" dest_nodeid } if ( useSpan ) { # use Span destipaddrdev = destipaddrdev ":" destSpan } if ( usePartition ) { # use Partition destPNP = "" if ( orig_is_ipphone && !dest_is_ipphone ) { # OUTGOING destPNP =handle_PNPartition(callingpnpartition) } if ( !orig_is_ipphone && !dest_is_ipphone ) { # TRANSIT # for Transit calls - use dest Partition destPNP = handle_PNPartition(calledpnpartition) } print "destPNP=[" destPNP "]" if ( destPNP != "" ) { # use Partiton prefix for devicename lookup if ( usePartition == 1 || usePartition == 3 ) { print "use Partition prefix to lookup devicename" destipaddrdev = destipaddrdev ":" destPNP } # set timezone from dest Partition if ( usePartition == 2 || usePartition == 3 ) { print "use Partition prefix to SET TZ for destPNP=[" destPNP "]" call_TZ = get_TZ_for_PartitionPrefix(destPNP) } } } print "Lookup dest3 ipaddrdev_to_trunklocalid_arr[" destipaddrdev "]=[" ipaddrdev_to_trunklocalid_arr[destipaddrdev] "]" destiprep = ipaddrdev_to_trunklocalid_arr[destipaddrdev] } if ( destiprep != "" ) { # found use_dest_last_2_octets = 0 } else { # try with ignore ipaddr ignore_ipaddrdev = destipaddrdev if ( i = match(ignore_ipaddrdev,":") ) { ignore_ipaddrdev = "ignore" substr(ignore_ipaddrdev,i) destiprep = ipaddrdev_to_trunklocalid_arr[ignore_ipaddrdev] if ( ccmloglevel >= 3 ) print "ignore dest ipaddr, lookup [" ignore_ipaddrdev "] = [" destiprep "]" if ( destiprep != "" ) # found use_dest_last_2_octets = 0 } } } if ( use_dest_last_2_octets ) { # set to last 2 octets of dest IP address destiprep = sprintf("%03d%03d", destoctet2dec, destoctet3dec) + 0; if ( IPADDRfmt == 0 ) destiprep = handle_devname(destiprep,dest_devicename) } else { # found dest g/w if ( gateways_override_ip_phones > 0 && dest_is_ipphone ) { printf("Gateway override set: ignoring dest IP phone\n", gateways_override_ip_phones) dest_is_ipphone = 0 } } if ( val == 2 ) { # second leg of split diverted call print "this is 2nd leg of split diverted" print "dest_is_ipphone=[" dest_is_ipphone "]" print "use_dest_last_2_octets=[" use_dest_last_2_octets "]" if ( dest_is_ipphone == 0 && use_dest_last_2_octets == 1 ) { print "dest is NOT an IP Phone or confiured G/W Route" if ( splitdiverted_gateway_trunlocalid != "" ) { print "for dest G/W use splitdiverted_gateway_trunlocalid=[" splitdiverted_gateway_trunlocalid "]" destiprep = splitdiverted_gateway_trunlocalid use_dest_last_2_octets = 0 } } } #------------------------------------------- # handle Call Transfer xfr = 0 OnBehalfOf_xfrcodes[10] = "Transfer" RedirectReason_xfrcodes[4] = "Call Transfer" RedirectReason_xfrcodes[34] = "Blind Transfer" if ( OnBehalfOf_xfrcodes[origCallTerminationOnBehalfOf] != "" ) xfr = 1 if ( OnBehalfOf_xfrcodes[destCallTerminationOnBehalfOf] != "" ) xfr = 1 if ( OnBehalfOf_xfrcodes[origCalledPartyRedirectOnBeha] != "" ) xfr = 1 if ( OnBehalfOf_xfrcodes[lastRedirectRedirectOnBehalfOf] != "" ) xfr = 1 if ( OnBehalfOf_xfrcodes[joinOnBehalfOf] != "" ) xfr = 1 if ( RedirectReason_xfrcodes[origCalledPartyRedirectReason] != "" ) xfr = 1 lastRedirectRedirectReason if ( RedirectReason_xfrcodes[lastRedirectRedirectReason] != "" ) xfr = 1 #------------------------------------------- if ( dateTimeDisconnect == "" ) { printf("ERROR: dateTimeDisconnect blank"); strdatetime = "" } else { cmd = "" if ( call_TZ != "default" ) { cmd = "TZ='" call_TZ "'; export TZ;" } cmd = cmd "cnvep -d " dateTimeDisconnect print "cnvep cmd=[" cmd "]" cmd | getline strdatetime close(cmd) } if ( ccmloglevel >= 3 ) { printf("strdatetime=%s\norig_ipport=%d orig_ipaddr=%ld (%s)\nuse_orig_last_2_octets=%d origdevid=%d\norigipaddrdev=[%s]\norigiprep=%s\ndest_ipport=%d dest_ipaddr=%ld (%s)\nuse_dest_last_2_octets=%d destdevid=%d\ndestipaddrdev=[%s]\nsplitdiverted_gateway_trunlocalid=[%s]\ndestiprep=%s\n", strdatetime, orig_ipport, orig_ipaddr, origipdotnot, use_orig_last_2_octets, origdevid, origipaddrdev, origiprep, dest_ipport, dest_ipaddr, destipdotnot, use_dest_last_2_octets, destdevid, destipaddrdev, splitdiverted_gateway_trunlocalid, destiprep); } # create clu record #:inlet|outlet|dialledno|DDMMYYHHMMSS|duration|meterpulse|accountcode|ct # eg. #in :100021|4321||151100182020|3||123456|81 #out :4321|100020|036199574|151100182020|2||123456|01 #in transit :104009|103007||151100182020|11||123456|83 #out transit :104009|103007|0442002|151100182020|11||123456|03 #internal :4321|2222|2222|151100182020|8|||89 if ( ccmloglevel >= 2 ) { print "hexorigIP=[" hexorigIP "]" " <--> " "hexdestIP=[" hexdestIP "]" print "ip orig=[" origipaddrdev "]" " <--> " "dest=[" destipaddrdev "]" print "iporig=[" origipaddrdev "]," " calling=[" callingpnstr " : " callingpn " isphone=" orig_is_ipphone "]," " --> " ",ipdest=[" destipaddrdev "]," " called=[" calledpnstr " : " calledpn " isphone=" dest_is_ipphone "]," " diverted=" diverted } if ( orig_is_ipphone ) { # INTERNAL or OUTGOING inlet = callingpn; if ( dest_is_ipphone ) { # INTERNAL # logging conference calls as internal to/from # cbridgeextn if ( log_conferenace_as_internal && (orig_cbridge == 1 || dest_cbridge == 1) && cbridgeextn != "" ) { outlet = calledpn; ct = "89"; dialledno = cbridgeid; spitclu() } else { if ( splitinternal == "1" ) { #if ( callingpn == "2092" && calledpn == "4131" ) { print "splitinternal" # logi internal as 2 calls # outgoing and incoming # outgoing bit inlet = callingpn; outlet = "8888888"; ct = "01"; dialledno = calledpn; spitclu() ++reccount # incoming bit inlet = "8888888"; outlet = calledpn; ct = "81"; dialledno = callingpn; spitclu() #} } else { # log as internal outlet = calledpn; ct = "89"; dialledno = callingpn; spitclu() } } } else { # OUTGOING outlet = destiprep ct = "01"; dialledno = calledpn; spitclu() } } else { # INCOMING or TRANSIT inlet = origiprep if ( dest_is_ipphone ) { # INCOMING outlet = calledpn; ct = "81"; dialledno = callingpn; spitclu() } else { # TRANSIT outlet = destiprep ct = "03"; dialledno = calledpn; spitclu() } } #------------------------------ # handle config err out file # for orig if not found to be an IP phone and using 2 octects for gw if ( IPADDRfmt > 0 && !orig_is_ipphone && use_orig_last_2_octets ) { outp = sprintf("orig") outp = outp sprintf(" (%s)", origiprep) outp = outp sprintf(" [%s]", origipdotnot) outp = outp sprintf(" [%s]", orig_devicename) #if ( (callingpnstr + 0) <= 999999 ) { if ( ("" callingpnstr) != ("" callingpn) ) outp = outp sprintf(" (%s->%s)", callingpnstr,callingpn) else outp = outp sprintf(" (%s)", callingpn) #} print outp | errout if ( ccmloglevel >= 3 ) { print "errout: " outp } } # for dest if not found to be an IP phone and using 2 octects for gw if ( IPADDRfmt > 0 && !dest_is_ipphone && use_dest_last_2_octets ) { outp = sprintf("dest") outp = outp sprintf(" (%s)", destiprep) outp = outp sprintf(" [%s]", destipdotnot) outp = outp sprintf(" [%s]", dest_devicename) #if ( (calledpnstr + 0) <= 999999 ) { if ( ("" calledpnstr) != ("" calledpn) ) outp = outp sprintf(" (%s->%s)", calledpnstr, calledpn) else outp = outp sprintf(" (%s)", calledpn) #} print outp | errout print "errout: " outp } } function spitclu() { #dialledno = calledpnstr; if ( dovideo == "1" ) { if ( is_video ) { #dialledno = handle_partynumber(dialledno) #if ( dialledno != "" ) # dialledno = " " dialledno dialledno = "VIDEO" dialledno } } ##gsub("[#*]","",dialledno) #gsub("[^0-9]","",dialledno) gsub("[#*+]","",dialledno) # limit dialledno to 20 chars # re:- overflow in scl caused by long calling party numbers # and also dialeno n telmax21 cdt tables is max 20 chars # this is alreday being done for called party numbers elsewhere # but best to do it here dialledno = substr(dialledno,1,20) if ( ccmloglevel >= 4 ) { print "duration=[" duration "]" } if ( CLUDURINSECS == 1 ) cluduration = duration; else cluduration = duration / 4; meter = 0; # set account cde to ClientMatterCode (ECU 14/1/2015) #accountcode = ""; accountcode = substr(clientMatterCode,1,12); #------------------------------------------ # handle Additotion nibble of calltype flags # xfr f3: 1 = Call was Transfered # f2: unused # f1: unused # f0: unused newct = ct f3 = xfr f2 = 0 f1 = 0 f0 = 0 # only add additional nibble if if xfr is set if ( xfr == 1 ) { #additional_nibble = (f3 << 3) | (f2 << 2) | (f1 << 1) | f0 additional_nibble = 0 if ( f3 ) additional_nibble += 0x08 if ( f2 ) additional_nibble += 0x04 if ( f1 ) additional_nibble += 0x02 if ( f0 ) additional_nibble += 0x01 if ( additional_nibble <= 10 ) additional_nibble += 48 # ascii code for '0' else additional_nibble += 65 # ascii code for 'A' if ( ccmloglevel >= 3 ) { print "additional_nibble = [" additional_nibble "]" } newct = sprintf("%s%c", ct, additional_nibble) } #------------------------------------------ filtercall = 0 if ( origipdotnot == IPFILTER1 || destipdotnot == IPFILTER1 ) { filtercall = 1 if ( ccmloglevel >= 3 ) { print "FILTERING CALL due to orig or dest IP = " IPFILTER1 } } if ( filtercall == 0 ) { # skip till lastpollblock records with datetime same as lastpolldate if ( ccmloglevel >= 3 ) { printf("reccount=%d lastpollblock=%d strdatetime=%s lastpolldate=%s\n", reccount, lastpollblock, strdatetime, lastpolldate); } # skip lastpollblock records at start of requested period if ( ++reccount < lastpollblock ) { if ( ccmloglevel >= 9 ) { printf("Skipping...\n"); } return; } } clufmt = sprintf("%d:%s|%s|%s|%s|%s%d|%d|%s|%s", reccount, inlet, outlet, dialledno, strdatetime, CLUDURINSECS == 1 ? "+" : "", cluduration, meter, accountcode, newct); if ( ccmloglevel >= 3 ) { #print "clufmt [" clufmt "]" print "clufmt" ((filtercall != 0) ? " FILTER" : "") (is_video ?"VID" : "") " [" clufmt "]" } if ( filtercall == 0 ) { print clufmt >> ccmcluoutfile } } END { printf("ENDCLPSEND:\n") >> ccmcluoutfile; }