Choose the namespace before sending the action
AMI Getvar reads a channel variable or a dialplan-function result. Setvar writes a channel variable or writable dialplan function. Both accept ActionID, optional Channel and Variable; Setvar also accepts Value. The current action references say that omitting Channel selects a global variable.
That makes the channel header a scope boundary, not optional decoration. Record the complete live channel name, Uniqueid and Linkedid when channel scope is intended. Keep a channel variable, inherited variable, global variable, SHARED() namespace and another dialplan function as different targets.
Correlate the synchronous response first
Assign a unique ActionID and retain the matching response. For Getvar, distinguish an action error, an empty or unset value and a function result. For Setvar, an accepted response means Asterisk processed the write request; it is not proof that later dialplan logic read that value or produced the intended service outcome.
AMI messages are header blocks with an empty-line terminator. Preserve exact header spelling, delimiters and framing before interpreting a timeout as a variable failure.
Treat channel lifetime as part of the key
A channel variable lives on a channel structure. A stale display label, prefix match or channel name captured before masquerade, transfer, Local-channel optimization or hangup can address no channel or the wrong live channel. Resolve the exact channel at the time of each action.
Do not reuse a prior call’s channel name as durable state. Use purpose-built persistent or application-owned storage where the business requirement must outlive the channel, with explicit concurrency and recovery design.
Preserve inheritance semantics instead of editing the child late
A single leading underscore causes one generation of inheritance and is removed on the child. Two leading underscores continue across descendants. Asterisk also documents that assigning any prefixed or unprefixed version replaces the other versions of that variable on the channel.
Inheritance happens when a child is created. Setting _FOO or __FOO after the target child already exists does not retroactively populate it. Capture the parent value before creation and the child value after creation rather than inferring one from the other.
Bound global, SHARED and function side effects
Omitting Channel selects global scope. That is broader than one call and can expose races or stale state across unrelated calls. SHARED() is a separate namespace for data shared between channels, and the current function reference explicitly warns that concurrent channels can change it without notice. Read a shared value into a regular channel variable before multi-step calculations.
Function evaluation can have side effects. Asterisk documents safeguards for privilege-escalating functions reached through AMI or ARI, controlled by live_dangerously; do not relax that safeguard to make a general-purpose remote write work. Give manager users only the required action classes and allowable inputs.
Use VarSet as change evidence, not an outcome receipt
VarSet reports the channel snapshot plus Variable and new Value; the generated reference has distinct variants for ordinary, LOCAL() and SHARED() writes. Event delivery also depends on the manager session’s event mask, permissions and filters. A missing event therefore does not by itself prove the write failed.
Correlate the action response, exact target, optional event and a fresh read. Then verify the dialplan branch or application outcome separately. Redact credentials, tokens and personal data before logging variables. No PBX, manager account, session, channel, variable, function, event, dialplan, packet, media stream or live call was inspected or tested.
Sources & applicability
Primary references for the technical details above. Operational examples and planning checklists are VoIP.info editorial guidance.
- Asterisk 23 AMI Getvar action ↗
- Asterisk 23 AMI Setvar action ↗
- Asterisk 23 AMI VarSet event ↗
- Asterisk channel-variable setting and substitution ↗
- Asterisk channel-variable inheritance ↗
- Asterisk global-variable basics ↗
- Asterisk 23 SHARED dialplan function ↗
- Asterisk external-protocol dialplan-function safeguards ↗
- Asterisk AMI event filtering ↗
Examples require adaptation to your topology. No live PBX or hardware testing is claimed.