/* DESC: This script can be used to send an alert call via a voice phone call * Copyright (C) 2016 NetModule AG */ // Who should we call phoneNo=argv[1]; // How many seconds should we wait to answer the call timeout=30; //seconds // How manay seconds should we wait for the next try callbreak=60; // How many times should we try to calll; retries=5;// //maximum time in seconds a call can be connected before we assume it's picked up by a machine maxConnectTime=10; //Enable Debug Messages; DEBUG=true; void debug(string msg) { if(DEBUG) { nb_syslog("DEBUG: %s",msg); printf("DEBUG: %s\n",msg); } } //function to get the current uptime seconds int jiffy() { sys = sysinfo(); u = struct_get(sys, "uptime"); if (is_void(u) || u < 1) { return 0; } else { return u; } } startTime=jiffy(); tryNo=1; while(tryNo\n- <%s>" , event.type , event.call.id , event.call.state , event.call.calling , event.call.called )); switch (event.type) { case "outgoing": debug("handle outgoing: -"); break; case "incoming": debug("handle incoming: -"); break; case "dialing": debug("handle dialing: "); break; case "dispatched": debug("handle dispatched: -"); break; case "connected": debug("handle connected:"); nb_syslog("Call with %s was answered. Let's check if we have voicemail answering (max 10sec call)",phoneNo); if (connectStart==0) connectStart=jiffy(); if (connectStart>0 && jiffy()-maxConnectTime>connectStart) { nb_syslog("We will terminated the call, call was anserwered by a machine, call was connected longer then 10 sec."); nb_syslog("We will retry the call"); nb_voice_call_hangup(event.call.id); connecStart=0; } break; case "hungup": if (connectStart!=0) { if (jiffy()-maxConnectTimetryStart+timeout) { callOngoing=false; call = nb_voice_call_get(dialcall); if (call) { debug("handle timer: hangup"); nb_voice_call_hangup(call); nb_syslog("We let it ring for %i seconds, let's hangup",timeout); } else { debug("handle timer: call not found"); } } } } nb_syslog("Alarm not successfull after %i call, let's wait %i sec and try again",tryNo,callbreak); sleep(callbreak); tryNo++; } nb_syslog("Alarm was not successfull after %i seconds",jiffy()-startTime); exit(0);