get variable

Usage: GET VARIABLE <variablename>

Does not work* with global variables. Does not work with some variables that are generated by modules.
(* now works for global variables in 1.2.10 - see http://bugs.digium.com/view.php?id=7609 )

'Variable' actually includes functions (but no expression parsing). Tested on 1.2.13.

EXAMPLE:
QUESTION:
GET VARIABLE UNIQUEID
ANSWER:
200 result=1 (1187188485.0)

Returns:
failure or not set: 200 result=0
success: 200 result=1 <value>

The AGI script communicates with Asterisk by sending AGI commands on standard output and receiving responses on standard input. The result typically takes this form:

<code> result=<result> [data]

where code is an HTTP-like response code (200 for success, 5xx for error); result is the result of the command (common values are -1 for error, and 0 for success); some commands return additional name=value pairs in data, while some return a string value in parentheses (especially "timeout" for a timed command.) Also note that if code is followed by a hyphen instead of a space, the response will span multiple lines; the last line of the response will start with code. The response is easily defined using a regular expression: /^\d{3}(?: result=.*?(?: \(?.*\))?)|(?:-.*)$/

PHP example


ob_implicit_flush(true);
set_time_limit(30);
$in = fopen("php://stdin","r");
$debug = true;

function __read__() {
global $in, $debug;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) echo "VERBOSE \"read: $input\"\n";
return $input;
}

function __write__($line) {
global $debug;
if ($debug) echo "VERBOSE \"write: $line\"\n";
print $line."\n";
}

//get the variable and strip of all the extra stuff around it
__write__("GET VARIABLE MYDIALPLANVAR");
$res = substr(strrchr(__read__(),"("),1,-1);
__write__("EXEC NOOP '======??? MYDIALPLANVAR: ".$res." ???======'\n");
__read__();



Tip

In many earlier versions of Asterisk (typically 1.0.x) the GET VARIABLE command doesn't appear to work at all. You can, however, pass your variables to the script when calling it from the dialplan through AGI(), example:

exten => 1234,1,AGI(test.agi,${CALLERIDNUM})

and then in PHP, for example, use this with the help of $argv[1].

Use "AGI DEBUG" in the Asterisk CLI to get to the bottom of this - or a similar - issue.

See also



Go back to Asterisk AGI
Usage: GET VARIABLE <variablename>

Does not work* with global variables. Does not work with some variables that are generated by modules.
(* now works for global variables in 1.2.10 - see http://bugs.digium.com/view.php?id=7609 )

'Variable' actually includes functions (but no expression parsing). Tested on 1.2.13.

EXAMPLE:
QUESTION:
GET VARIABLE UNIQUEID
ANSWER:
200 result=1 (1187188485.0)

Returns:
failure or not set: 200 result=0
success: 200 result=1 <value>

The AGI script communicates with Asterisk by sending AGI commands on standard output and receiving responses on standard input. The result typically takes this form:

<code> result=<result> [data]

where code is an HTTP-like response code (200 for success, 5xx for error); result is the result of the command (common values are -1 for error, and 0 for success); some commands return additional name=value pairs in data, while some return a string value in parentheses (especially "timeout" for a timed command.) Also note that if code is followed by a hyphen instead of a space, the response will span multiple lines; the last line of the response will start with code. The response is easily defined using a regular expression: /^\d{3}(?: result=.*?(?: \(?.*\))?)|(?:-.*)$/

PHP example


ob_implicit_flush(true);
set_time_limit(30);
$in = fopen("php://stdin","r");
$debug = true;

function __read__() {
global $in, $debug;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) echo "VERBOSE \"read: $input\"\n";
return $input;
}

function __write__($line) {
global $debug;
if ($debug) echo "VERBOSE \"write: $line\"\n";
print $line."\n";
}

//get the variable and strip of all the extra stuff around it
__write__("GET VARIABLE MYDIALPLANVAR");
$res = substr(strrchr(__read__(),"("),1,-1);
__write__("EXEC NOOP '======??? MYDIALPLANVAR: ".$res." ???======'\n");
__read__();



Tip

In many earlier versions of Asterisk (typically 1.0.x) the GET VARIABLE command doesn't appear to work at all. You can, however, pass your variables to the script when calling it from the dialplan through AGI(), example:

exten => 1234,1,AGI(test.agi,${CALLERIDNUM})

and then in PHP, for example, use this with the help of $argv[1].

Use "AGI DEBUG" in the Asterisk CLI to get to the bottom of this - or a similar - issue.

See also



Go back to Asterisk AGI
Created by: pinhole, Last modification: Mon 15 of Feb, 2010 (00:50 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+