Asterisk cmd DeadAGI

DeadAGI is a variant of AGI that you use when the channel is hung up.

Syntax and Usage:

Please refer to the AGI application for general AGI information as the syntax and usage are identical.

The main difference is that the AGI application may terminate if the line is hung up during execution and DeadAGI will not terminate even if the call is hung up during execution, however, the call leg will not automatically enter a "down" state until execution is completed if executed on a live line. As such, commands and applications designed to return the call state will inaccurately return an "up" status.

This also means that any calls stuck in a DeadAGI execution upon hangup will continue to be considered "up" by the CDR. It is very important for your script to be aggressive in completing after hangup in order to maintain accurate CDR records.

A possible method of checking the channel would be to "exec playback" of an audio file (possibly a short, silent file) and look for the returned result of that execution. This relies on the fact that the file actually exists and will "answer" the call if it is not yet up. Of course, this will display a "Failed to write frame" warning on failure, returning -1 and indicating the channel is down. It returns a 0 result on success.

Versions

This command was added to the development (CVS) edition of Asterisk on 2004-03-03. It does not exist in Asterisk 1.0 or 0.9.
It is available in 1.0.9 and 1.2.x.

DeadAGI is obsolete in Asterisk 1.6 and later: Simply use AGI().

Notes

I can't verify lack of presence in 1.0 or 0.9, but I can verify presence in 1.0.9 and 1.2.x. Anyone using older copies, please update version information. Thanks - Flobi

In Asterisk 1.4.19 and later 1.4 releases you might see this (usually harmless) warning:

deadagi_exec: Running DeadAGI on a live channel will cause problems

One possible way to avoid this warning is to call

SoftHangup(${CHANNEL})

before calling DeadAGI. Read more about this at bug 14811. The issues has been fixed in Asterisk 1.6 and later.

Alternative approach: SIGHUP

Q: I've got a very nice PHP AGI script but I want to be able to do some database cleanup when the user hangs up the phone. I wish everyone would hang up when they were suposed to, but some people don't. So what does Asterisk send to an AGI file when the line has been disconnected?

A: SIGHUP

Q: If I remember reading somewhere correctly, I don't need to use DeadAGI. Instead I'm able to use normal AGI but I just need to catch a SIGTERM or something like that and process it.

A: You need to catch it or the script will terminate. Not sure if this is possible at all in PHP. I think there's an inofficial POSIX module which can do it. Perl can do it for sure.

In fact, if you need to cleanup connections, catching the signal is EXACTLY what you ought to do. Just bear in mind that as soon as you get a signal, the current version of AGI will stop interacting with your script.
Note: This has been changed for the next release cycle (Asterisk 1.6), so AGI will transparently switch over to what is now DeadAGI behavior (after sending a HUP) and continue to interact with the script until the script dies (which is what most people wanted anyway).

In Asterisk 1.2 even a DeadAGI script will receive a SIGHUP and may terminate when the channel is hung up. Your script will have to block SIGHUP signals, which you can do like so:

Perl:
$SIG{HUP} = "IGNORE" (Perl)

PHP (though you must compile with --enable-pcntl to get this function):
pcntl_signal(SIGHUP, SIG_IGN)

Ruby:
trap('SIGHUP','IGNORE')

In addition, don't try and communicate with the Asterisk server after the hangup or you'll receive a SIGPIPE which will also terminate your script (again unless you ignore it). To avoid this be sure and check result codes. Info gathered from bug4845

See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

DeadAGI is a variant of AGI that you use when the channel is hung up.

Syntax and Usage:

Please refer to the AGI application for general AGI information as the syntax and usage are identical.

The main difference is that the AGI application may terminate if the line is hung up during execution and DeadAGI will not terminate even if the call is hung up during execution, however, the call leg will not automatically enter a "down" state until execution is completed if executed on a live line. As such, commands and applications designed to return the call state will inaccurately return an "up" status.

This also means that any calls stuck in a DeadAGI execution upon hangup will continue to be considered "up" by the CDR. It is very important for your script to be aggressive in completing after hangup in order to maintain accurate CDR records.

A possible method of checking the channel would be to "exec playback" of an audio file (possibly a short, silent file) and look for the returned result of that execution. This relies on the fact that the file actually exists and will "answer" the call if it is not yet up. Of course, this will display a "Failed to write frame" warning on failure, returning -1 and indicating the channel is down. It returns a 0 result on success.

Versions

This command was added to the development (CVS) edition of Asterisk on 2004-03-03. It does not exist in Asterisk 1.0 or 0.9.
It is available in 1.0.9 and 1.2.x.

DeadAGI is obsolete in Asterisk 1.6 and later: Simply use AGI().

Notes

I can't verify lack of presence in 1.0 or 0.9, but I can verify presence in 1.0.9 and 1.2.x. Anyone using older copies, please update version information. Thanks - Flobi

In Asterisk 1.4.19 and later 1.4 releases you might see this (usually harmless) warning:

deadagi_exec: Running DeadAGI on a live channel will cause problems

One possible way to avoid this warning is to call

SoftHangup(${CHANNEL})

before calling DeadAGI. Read more about this at bug 14811. The issues has been fixed in Asterisk 1.6 and later.

Alternative approach: SIGHUP

Q: I've got a very nice PHP AGI script but I want to be able to do some database cleanup when the user hangs up the phone. I wish everyone would hang up when they were suposed to, but some people don't. So what does Asterisk send to an AGI file when the line has been disconnected?

A: SIGHUP

Q: If I remember reading somewhere correctly, I don't need to use DeadAGI. Instead I'm able to use normal AGI but I just need to catch a SIGTERM or something like that and process it.

A: You need to catch it or the script will terminate. Not sure if this is possible at all in PHP. I think there's an inofficial POSIX module which can do it. Perl can do it for sure.

In fact, if you need to cleanup connections, catching the signal is EXACTLY what you ought to do. Just bear in mind that as soon as you get a signal, the current version of AGI will stop interacting with your script.
Note: This has been changed for the next release cycle (Asterisk 1.6), so AGI will transparently switch over to what is now DeadAGI behavior (after sending a HUP) and continue to interact with the script until the script dies (which is what most people wanted anyway).

In Asterisk 1.2 even a DeadAGI script will receive a SIGHUP and may terminate when the channel is hung up. Your script will have to block SIGHUP signals, which you can do like so:

Perl:
$SIG{HUP} = "IGNORE" (Perl)

PHP (though you must compile with --enable-pcntl to get this function):
pcntl_signal(SIGHUP, SIG_IGN)

Ruby:
trap('SIGHUP','IGNORE')

In addition, don't try and communicate with the Asterisk server after the hangup or you'll receive a SIGPIPE which will also terminate your script (again unless you ignore it). To avoid this be sure and check result codes. Info gathered from bug4845

See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: oej, Last modification: Thu 04 of Nov, 2010 (13:26 UTC) by JustRumours
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+