From c4639445d9d133e1df9b6035ec00f629e0f0d200 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Thu, 30 Jul 2015 19:32:18 -0600 Subject: [PATCH] Fix fax_retry.lua for domain_name and domain_uuid. Add [FAX] to the logging to the console. --- resources/install/scripts/fax_retry.lua | 93 +++++++++++++------------ 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/resources/install/scripts/fax_retry.lua b/resources/install/scripts/fax_retry.lua index e4d4d12ef7..64d214cdea 100644 --- a/resources/install/scripts/fax_retry.lua +++ b/resources/install/scripts/fax_retry.lua @@ -16,7 +16,7 @@ -- -- The Initial Developer of the Original Code is -- Mark J Crane --- Copyright (C) 2010 - 2014 +-- Copyright (C) 2010 - 2015 -- the Initial Developer. All Rights Reserved. -- -- Contributor(s): @@ -61,7 +61,7 @@ -- show all channel variables --dat = env:serialize() - --freeswitch.consoleLog("INFO","info:\n" .. dat .. "\n") + --freeswitch.consoleLog("INFO","[FAX] info:\n" .. dat .. "\n") -- example channel variables relating to fax --variable_fax_success: 0 @@ -78,6 +78,8 @@ -- set channel variables to lua variables uuid = env:getHeader("uuid"); + domain_uuid = env:getHeader("domain_uuid"); + domain_name = env:getHeader("domain_name"); fax_success = env:getHeader("fax_success"); fax_result_text = env:getHeader("fax_result_text"); fax_local_station_id = env:getHeader("fax_local_station_id"); @@ -130,7 +132,7 @@ file_name = array[count(array)]; --get the domain_uuid using the domain name required for multi-tenant - if (domain_name ~= nil) then + if (domain_uuid == nil and domain_name ~= nil) then sql = "SELECT domain_uuid FROM v_domains "; sql = sql .. "WHERE domain_name = '" .. domain_name .. "' "; status = dbh:query(sql, function(rows) @@ -276,7 +278,7 @@ sql = sql .. "'"..os.time().."' "; sql = sql .. ")"; --if (debug["sql"]) then - freeswitch.consoleLog("notice", "[fax_retry] "..sql.."\n"); + freeswitch.consoleLog("notice", "[FAX] retry: "..sql.."\n"); --end dbh:query(sql); @@ -357,7 +359,7 @@ table.insert(sql, ")"); sql = table.concat(sql, "\n"); --if (debug["sql"]) then - freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n"); + freeswitch.consoleLog("notice", "[FAX] SQL: " .. sql .. "\n"); --end if (storage_type == "base64") then array = explode("://", database["system"]); @@ -375,38 +377,38 @@ -- send the selected variables to the console if (fax_success ~= nil) then - freeswitch.consoleLog("INFO","fax_success: '" .. fax_success .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] Success: '" .. fax_success .. "'\n"); end - freeswitch.consoleLog("INFO","fax_result_text: '" .. fax_result_text .. "'\n"); - freeswitch.consoleLog("INFO","fax_file: '" .. fax_file .. "'\n"); - freeswitch.consoleLog("INFO","uuid: '" .. uuid .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] fax_result_text: '" .. fax_result_text .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] fax_file: '" .. fax_file .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] uuid: '" .. uuid .. "'\n"); --freeswitch.consoleLog("INFO","fax_ecm_used: '" .. fax_ecm_used .. "'\n"); - freeswitch.consoleLog("INFO","fax_retry_attempts: " .. fax_retry_attempts.. "\n"); - freeswitch.consoleLog("INFO","fax_retry_limit: " .. fax_retry_limit.. "\n"); - freeswitch.consoleLog("INFO","fax_retry_sleep: " .. fax_retry_sleep.. "\n"); - freeswitch.consoleLog("INFO","fax_uri: '" .. fax_uri.. "'\n"); - freeswitch.consoleLog("INFO","accountcode: '" .. accountcode .. "'\n"); - freeswitch.consoleLog("INFO","origination_caller_id_name: " .. origination_caller_id_name .. "\n"); - freeswitch.consoleLog("INFO","origination_caller_id_number: " .. origination_caller_id_number .. "\n"); - freeswitch.consoleLog("INFO","fax_result_code: ".. fax_result_code .."\n"); - freeswitch.consoleLog("INFO","mailfrom_address: ".. from_address .."\n"); - freeswitch.consoleLog("INFO","mailto_address: ".. email_address .."\n"); - freeswitch.consoleLog("INFO","hangup_cause_q850: '" .. hangup_cause_q850 .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] fax_retry_attempts: " .. fax_retry_attempts.. "\n"); + freeswitch.consoleLog("INFO","[FAX] fax_retry_limit: " .. fax_retry_limit.. "\n"); + freeswitch.consoleLog("INFO","[FAX] fax_retry_sleep: " .. fax_retry_sleep.. "\n"); + freeswitch.consoleLog("INFO","[FAX] fax_uri: '" .. fax_uri.. "'\n"); + freeswitch.consoleLog("INFO","[FAX] accountcode: '" .. accountcode .. "'\n"); + freeswitch.consoleLog("INFO","[FAX] origination_caller_id_name: " .. origination_caller_id_name .. "\n"); + freeswitch.consoleLog("INFO","[FAX] origination_caller_id_number: " .. origination_caller_id_number .. "\n"); + freeswitch.consoleLog("INFO","[FAX] fax_result_code: ".. fax_result_code .."\n"); + freeswitch.consoleLog("INFO","[FAX] mailfrom_address: ".. from_address .."\n"); + freeswitch.consoleLog("INFO","[FAX] mailto_address: ".. email_address .."\n"); + freeswitch.consoleLog("INFO","[FAX] hangup_cause_q850: '" .. hangup_cause_q850 .. "'\n"); -- if the fax failed then try again if (fax_success == "0") then - --DEBUG - --email_cmd = "/bin/echo '"..email_message_fail.."' | /usr/bin/mail -s 'Fax to: "..number_dialed.." FAILED' -r "..from_address.." -a '"..fax_file.."' "..email_address; + --DEBUG + --email_cmd = "/bin/echo '"..email_message_fail.."' | /usr/bin/mail -s 'Fax to: "..number_dialed.." FAILED' -r "..from_address.." -a '"..fax_file.."' "..email_address; ---to keep the originate command shorter these are things we always send. One place to adjust for all. - originate_same = "for_fax=1,absolute_codec_string='PCMU,PCMA',accountcode='"..accountcode.."',mailto_address='"..email_address.."',mailfrom_address='"..from_address.."',origination_caller_id_name='"..origination_caller_id_name.. "',origination_caller_id_number="..origination_caller_id_number..",fax_uri="..fax_uri..",fax_retry_limit="..fax_retry_limit..",fax_retry_sleep="..fax_retry_sleep..",fax_verbose=true,fax_file='"..fax_file.."'"; + --to keep the originate command shorter these are things we always send. One place to adjust for all. + originate_same = "for_fax=1,absolute_codec_string='PCMU,PCMA',accountcode='"..accountcode.."',domain_uuid="..domain_uuid..",domain_name="..domain_name..",mailto_address='"..email_address.."',mailfrom_address='"..from_address.."',origination_caller_id_name='"..origination_caller_id_name.. "',origination_caller_id_number="..origination_caller_id_number..",fax_uri="..fax_uri..",fax_retry_limit="..fax_retry_limit..",fax_retry_sleep="..fax_retry_sleep..",fax_verbose=true,fax_file='"..fax_file.."'"; if (fax_retry_attempts < fax_retry_limit) then --timed out waitng for comm or on first message, or busy code if (fax_result_code == "2" or fax_result_code == "3" or hangup_cause_q850 == 17) then --do nothing. don't want to increment - freeswitch.consoleLog("INFO","Last Fax was probably Busy, don't increment retry_attempts. \n"); + freeswitch.consoleLog("INFO","[FAX] Last Fax was probably Busy, don't increment retry_attempts. \n"); fax_busy_attempts = fax_busy_attempts + 1; if (fax_busy_attempts > fax_busy_limit) then fax_retry_attempts = 17; @@ -416,34 +418,34 @@ --unallocated number elseif (hangup_cause_q850 == 1 ) then fax_retry_attempts = 10; - email_message_fail = "We are sorry the fax failed to go through. The number you specified is not a working number. The fax has been attached. Please check the number "..number_dialed..", and if it was correct you might consider emailing it instead." + email_message_fail = "We are sorry the fax failed to go through. The number you specified is not a working number. The fax has been attached. Please check the number "..number_dialed..", and if it was correct you might consider emailing it instead." elseif (fax_retry_attempts < 5 ) then - freeswitch.consoleLog("INFO","Last Fax Failed, try a different way. Wait first.\n"); + freeswitch.consoleLog("INFO","[FAX] Last Fax Failed, try a different way. Wait first.\n"); freeswitch.msleep(fax_retry_sleep * 500); else - freeswitch.consoleLog("INFO","All attempts to send fax to "..number_dialed.."FAILED\n"); + freeswitch.consoleLog("INFO","[FAX] All attempts to send fax to "..number_dialed.."FAILED\n"); end if (fax_retry_attempts == 1) then - --send t38 on ECM on - freeswitch.consoleLog("INFO","FAX TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 ON ECM ON, Fast\n"); + --send t38 on ECM on + freeswitch.consoleLog("INFO","[FAX] TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 ON ECM ON, Fast\n"); if (hangup_cause_q850 ~= 17) then fax_retry_attempts = fax_retry_attempts + 1; end cmd = "originate {fax_retry_attempts="..fax_retry_attempts..","..originate_same..",fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=false,fax_busy_attempts='"..fax_busy_attempts.."',api_hangup_hook='lua fax_retry.lua'}"..fax_uri.." &txfax('"..fax_file.."')"; elseif (fax_retry_attempts == 2) then - --send t38 off, ECM on - freeswitch.consoleLog("INFO","FAX TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 OFF ECM ON, Fast\n"); + --send t38 off, ECM on + freeswitch.consoleLog("INFO","[FAX] TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 OFF ECM ON, Fast\n"); if (hangup_cause_q850 ~= 17) then fax_retry_attempts = fax_retry_attempts + 1; end cmd = "originate {fax_retry_attempts="..fax_retry_attempts..","..originate_same..",fax_use_ecm=true,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false,fax_busy_attempts='"..fax_busy_attempts.."',api_hangup_hook='lua fax_retry.lua'}"..fax_uri.." &txfax('"..fax_file.."')"; elseif (fax_retry_attempts == 3) then - --send t38 on v17 [slow] on ECM off - freeswitch.consoleLog("INFO","FAX TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 ON ECM OFF, SLOW\n"); + --send t38 on v17 [slow] on ECM off + freeswitch.consoleLog("INFO","[FAX] TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 ON ECM OFF, SLOW\n"); if (hangup_cause_q850 ~= 17) then fax_retry_attempts = fax_retry_attempts + 1; end @@ -451,8 +453,8 @@ cmd = "originate {fax_retry_attempts="..fax_retry_attempts..","..originate_same..",fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=true,fax_busy_attempts='"..fax_busy_attempts.."',api_hangup_hook='lua fax_retry.lua'}"..fax_uri.." &txfax('"..fax_file.."')"; elseif (fax_retry_attempts == 4) then - --send t38 off v17 [slow] on ECM off - freeswitch.consoleLog("INFO","FAX TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 OFF ECM OFF, SLOW\n"); + --send t38 off v17 [slow] on ECM off + freeswitch.consoleLog("INFO","[FAX] TRYING ["..fax_retry_attempts.."] of [4] to: "..number_dialed.." with: t38 OFF ECM OFF, SLOW\n"); if (hangup_cause_q850 ~= 17) then fax_retry_attempts = fax_retry_attempts + 1; end @@ -461,8 +463,8 @@ --bad number elseif (fax_retry_attempts == 10) then - freeswitch.consoleLog("INFO","FAX_RETRY FAILED: BAD NUMBER\n"); - freeswitch.consoleLog("INFO", "FAX_RETRY_STATS FAILURE BAD NUMBER: GATEWAY[".. fax_uri .."]"); + freeswitch.consoleLog("INFO","[FAX] RETRY FAILED: BAD NUMBER\n"); + freeswitch.consoleLog("INFO", "[FAX] RETRY_STATS FAILURE BAD NUMBER: GATEWAY[".. fax_uri .."]"); email_message_fail = email_message_fail.."We tried sending, but the number entered was not a working phone number " email_address = email_address:gsub("\\,", ","); freeswitch.email("", @@ -474,8 +476,8 @@ --busy number elseif (fax_retry_attempts == 17) then - freeswitch.consoleLog("INFO","FAX_RETRY FAILED: TRIED ["..fax_busy_attempts.."] of [4]: BUSY NUMBER\n"); - freeswitch.consoleLog("INFO", "FAX_RETRY_STATS FAILURE BUSY: GATEWAY[".. fax_uri .."], BUSY NUMBER"); + freeswitch.consoleLog("INFO","[FAX] RETRY FAILED: TRIED ["..fax_busy_attempts.."] of [4]: BUSY NUMBER\n"); + freeswitch.consoleLog("INFO", "[FAX] RETRY STATS FAILURE BUSY: GATEWAY[".. fax_uri .."], BUSY NUMBER"); email_message_fail = email_message_fail.." We tried sending, but the call was busy "..fax_busy_attempts.." of those times." email_address = email_address:gsub("\\,", ","); freeswitch.email("", @@ -487,8 +489,8 @@ else --the fax failed completely. send a message - freeswitch.consoleLog("INFO","FAX_RETRY FAILED: TRIED ["..fax_retry_attempts.."] of [4]: GIVING UP\n"); - freeswitch.consoleLog("INFO", "FAX_RETRY_STATS FAILURE: GATEWAY[".. fax_uri .."], tried 5 combinations without success"); + freeswitch.consoleLog("INFO","[FAX] RETRY FAILED: tried ["..fax_retry_attempts.."] of [4]: GIVING UP\n"); + freeswitch.consoleLog("INFO", "[FAX] RETRY STATS FAILURE: GATEWAY[".. fax_uri .."], tried 5 combinations without success"); email_message_fail = email_message_fail.." We tried sending 5 times ways. You may also want to know that the call was busy "..fax_busy_attempts.." of those times." email_address = email_address:gsub("\\,", ","); @@ -505,13 +507,12 @@ end api = freeswitch.API(); if ( not cmd ) then - freeswitch.consoleLog("INFO","Last Fallthrough (5th) of FAX_RETRY.lua: \n"); + freeswitch.consoleLog("INFO","[FAX] Last Attempt (5th) of fax_retry.lua: \n"); else - freeswitch.consoleLog("INFO","retry cmd: " .. cmd .. "\n"); + freeswitch.consoleLog("INFO","[FAX] Retry Command: " .. cmd .. "\n"); reply = api:executeString(cmd); end end - else --Success if (fax_retry_attempts == 0) then @@ -527,7 +528,7 @@ else fax_trial = "fax_retry had an issue and tried more than 5 times" end - freeswitch.consoleLog("INFO", "FAX_RETRY_STATS SUCCESS: GATEWAY[".. fax_uri .."] VARS[" .. fax_trial .. "]"); + freeswitch.consoleLog("INFO", "[FAX] RETRY STATS SUCCESS: GATEWAY[".. fax_uri .."] VARS[" .. fax_trial .. "]"); email_address = email_address:gsub("\\,", ","); freeswitch.email("",