<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2172/18/9/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/AMI+Event+Documentation">AMI Event Documentation</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://wiki.asterisk.org/wiki/display/~mjordan">Matt Jordan</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <div>
<ul>
    <li><a href='#AMIEventDocumentation-Overview'>Overview</a></li>
    <li><a href='#AMIEventDocumentation-BuildingAMIEventDocumentation'>Building AMI Event Documentation</a></li>
    <li><a href='#AMIEventDocumentation-CLICommands'>CLI Commands</a></li>
    <li><a href='#AMIEventDocumentation-WritingAMIEventDocumentation'>Writing AMI Event Documentation</a></li>
<ul>
    <li><a href='#AMIEventDocumentation-XMLSchema'>XML Schema</a></li>
    <li><a href='#AMIEventDocumentation-SourceComments'>Source Comments</a></li>
</ul>
</ul></div>

<h1><a name="AMIEventDocumentation-Overview"></a>Overview</h1>

<p>Asterisk 11 now supports the display of AMI event documentation.  The documentation is handled in the same fashion as other portions of Asterisk, and is accessible via CLI commands.</p>

<p>Not all AMI events are documented in Asterisk 11, and the list of events available in Asterisk should not be considered a comprehensive list of all events.  However, for any event that is listed in Asterisk, the documentation should be accurate and complete.  This includes:</p>
<ul>
        <li>When and why the event is raised</li>
        <li>Fields that are available in the event, both those that are always present as well as those that may be present</li>
        <li>Related information to that event</li>
</ul>


<h1><a name="AMIEventDocumentation-BuildingAMIEventDocumentation"></a>Building AMI Event Documentation</h1>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Building AMI Event documentation for Asterisk requires both libxml and python.</td></tr></table></div>

<p>Because AMI event documentation is handled in a slightly different fashion, a new build option 'make full' is required to generate the documentation from the Asterisk source.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false"># ./configure
# make full
# make install</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Because AMI event documentation must be pulled from a variety of locations in the Asterisk source, the time to generate AMI event documentation is noticeably longer then the time to generate other Asterisk documentation.</td></tr></table></div>

<h1><a name="AMIEventDocumentation-CLICommands"></a>CLI Commands</h1>

<p>Two new CLI commands have been added:</p>
<ul>
        <li>manager show events - list all documented AMI events</li>
        <li>manager show event <a href="/wiki/pages/createpage.action?spaceKey=AST&amp;title=event+name&amp;linkCreation=true&amp;fromPageId=20185227" class="createlink">event name</a> - provide detailed documentation on a single AMI event</li>
</ul>


<p>Example output of both commands is shown below.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">*CLI&gt; manager show events
Events:
  --------------------  --------------------  --------------------  
  AgentCalled           AgentComplete         AgentConnect        
  AgentDump             AgentRingNoAnswer     ChanSpyStart        
  ChanSpyStop           ConfbridgeEnd         ConfbridgeJoin      
  ConfbridgeLeave       ConfbridgeStart       ConfbridgeTalking   
  Dial                  Join                  Leave               
  MeetmeEnd             MeetmeJoin            MeetmeLeave         
  MeetmeMute            MeetmeTalkRequest     MeetmeTalking       
  MessageWaiting        QueueCallerAbandon    QueueMemberAdded    
  QueueMemberPaused     QueueMemberPenalty    QueueMemberRemoved  
  QueueMemberRinginuse  QueueMemberStatus     UserEvent</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">*CLI&gt; manager show event Dial
Event: Dial
[Synopsis]
Raised when a dial action has started.

[Syntax]
Event: Dial
SubEvent: &lt;value&gt;
Channel: &lt;value&gt;
Destination: &lt;value&gt;
CallerIDNum: &lt;value&gt;
CallerIDName: &lt;value&gt;
ConnectedLineNum: &lt;value&gt;
ConnectedLineName: &lt;value&gt;
UniqueID: &lt;value&gt;
DestUniqueID: &lt;value&gt;
Dialstring: &lt;value&gt;

[Arguments]
SubEvent
    Begin
    End
    A sub event type, specifying whether or not the dial action has begun
    or ended.

[Synopsis]
Raised when a dial action has ended.

[Syntax]
Event: Dial
DialStatus: &lt;value&gt;
SubEvent: &lt;value&gt;
Channel: &lt;value&gt;
UniqueID: &lt;value&gt;

[Arguments]
DialStatus
    The value of the ${DIALSTATUS} channel variable.
SubEvent
    Begin
    End
    A sub event type, specifying whether or not the dial action has begun
    or ended.

*CLI&gt;</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>The output shown above is subject to change</td></tr></table></div>

<h1><a name="AMIEventDocumentation-WritingAMIEventDocumentation"></a>Writing AMI Event Documentation</h1>

<p>AMI Event documentation behaves a bit differently then other Asterisk documentation. A driving factor in the approach taken was to make documenting AMI events as simple and painless as possible, and leave the intricacies of tying instances of AMI events together to pre- and post-processing scripts.  The following describes some of the differences between documenting AMI events and the normal approach for documenting items in Asterisk.</p>

<ol>
        <li>Event documentation can be built directly from the macros that raise the AMI events.  This includes manager_event, ast_manager_event, and ast_manager_event_multichan.  Because of this, AMI event documentation is typically co-located with the macro call that raises the event. Note that in the example below, only the DialStatus field is explicitly defined; however, the generated AMI event documentation will include all fields found in the ast_manager_event call.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*** DOCUMENTATION
                &lt;managerEventInstance&gt;
                        &lt;synopsis&gt;Raised when a dial action has ended.&lt;/synopsis&gt;
                        &lt;syntax&gt;
                                &lt;parameter name="DialStatus"&gt;
                                        &lt;para&gt;The value of the &lt;variable&gt;DIALSTATUS&lt;/variable&gt; channel variable.&lt;/para&gt;
                                &lt;/parameter&gt;
                        &lt;/syntax&gt;
                &lt;/managerEventInstance&gt;
        ***/
        ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
                "SubEvent: End\r\n"
                "Channel: %s\r\n"
                "UniqueID: %s\r\n"
                "DialStatus: %s\r\n",
                ast_channel_name(src), ast_channel_uniqueid(src), dialstatus);</pre>
</div></div></li>
        <li>Each instance of an AMI event can be documented.  This is particularly useful when the same event can have different fields, e.g., Dial, PeerStatus, etc.  Even if the event has the same fields across all instances, it is also useful to document why the event is raised in the &lt;synopsis/&gt; tag.  Because each instance of an AMI event should be documented, a post-processing script aggregates the various &lt;managerEventInstance/&gt; XML fragments that match the same event name under a single &lt;managerEvent/&gt; tag.  Fields that are shared across instances of the same event are combined and only need to be documented a single time.  In the example below, the SubEvent field is only documented once, but the full documentation for the field will be displayed for both instances of the Dial event, as both instances of the event contain that field.  In contrast to that, only the second instance of the event contains the DialStatus field; hence, only that instance will contain that field.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*** DOCUMENTATION
                &lt;managerEventInstance&gt;
                        &lt;synopsis&gt;Raised when a dial action has started.&lt;/synopsis&gt;
                        &lt;syntax&gt;
                                &lt;parameter name="SubEvent"&gt;
                                        &lt;enumlist&gt;
                                                &lt;enum name="Begin"/&gt;
                                                &lt;enum name="End"/&gt;
                                        &lt;/enumlist&gt;
                                        &lt;para&gt;A sub event type, specifying whether or not the dial action has begun or ended.&lt;/para&gt;
                                &lt;/parameter&gt;
                        &lt;/syntax&gt;
                &lt;/managerEventInstance&gt;
        ***/
...
        /*** DOCUMENTATION
                &lt;managerEventInstance&gt;
                        &lt;synopsis&gt;Raised when a dial action has ended.&lt;/synopsis&gt;
                        &lt;syntax&gt;
                                &lt;parameter name="DialStatus"&gt;
                                        &lt;para&gt;The value of the &lt;variable&gt;DIALSTATUS&lt;/variable&gt; channel variable.&lt;/para&gt;
                                &lt;/parameter&gt;
                        &lt;/syntax&gt;
                &lt;/managerEventInstance&gt;
        ***/</pre>
</div></div></li>
        <li>In the same fashion as multiple instances of an AMI event in a single file, multiple instances of AMI events across implementation files are also combined.</li>
        <li>Because pre- and post-processing scripts are involved, some burden on having a well-formed XML fragment is lifted from the documenter.  Often, the fields in an event are self-explanatory, or are documented significantly in other AMI events.  When that is the case, documentation for the event may only consist of a &lt;synopsis/&gt; field and one or two parameters - in which case, the &lt;syntax/&gt; element is inferred for the parameters.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*** DOCUMENTATION
                &lt;managerEventInstance&gt;
                        &lt;synopsis&gt;Raised when a dial action has ended.&lt;/synopsis&gt;
                        &lt;syntax&gt;
                                &lt;parameter name="DialStatus"&gt;
                                        &lt;para&gt;The value of the &lt;variable&gt;DIALSTATUS&lt;/variable&gt; channel variable.&lt;/para&gt;
                                &lt;/parameter&gt;
                        &lt;/syntax&gt;
                &lt;/managerEventInstance&gt;
        ***/

Is equivalent to:

        /*** DOCUMENTATION
                &lt;managerEventInstance&gt;
                        &lt;synopsis&gt;Raised when a dial action has ended.&lt;/synopsis&gt;
                        &lt;parameter name="DialStatus"&gt;
                                &lt;para&gt;The value of the &lt;variable&gt;DIALSTATUS&lt;/variable&gt; channel variable.&lt;/para&gt;
                        &lt;/parameter&gt;
                &lt;/managerEventInstance&gt;
        ***/</pre>
</div></div></li>
</ol>


<h2><a name="AMIEventDocumentation-XMLSchema"></a>XML Schema</h2>

<p>The following are the changes to the XML DTD schema used to validate the generated XML documentation.  An example of a generated XML fragment for the Dial event is also shown below.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">&lt;!ELEMENT managerEvent (managerEventInstance+)&gt;
  &lt;!ATTLIST managerEvent name CDATA #REQUIRED&gt;
  &lt;!ATTLIST managerEvent language CDATA #REQUIRED&gt;

  &lt;!ELEMENT managerEventInstance (synopsis?,syntax?,description?,see-also?)*&gt;
  &lt;!ATTLIST managerEventInstance class CDATA #REQUIRED&gt;</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">&lt;managerEvent language="en_US" name="Dial"&gt;&lt;managerEventInstance class="EVENT_FLAG_CALL"&gt;
    &lt;synopsis&gt;Raised when a dial action has started.&lt;/synopsis&gt;
        &lt;syntax&gt;
            &lt;parameter name="SubEvent"&gt;
                &lt;enumlist&gt;
                    &lt;enum name="Begin"/&gt;
                    &lt;enum name="End"/&gt;
                &lt;/enumlist&gt;
                &lt;para&gt;A sub event type, specifying whether or not the dial action has begun or ended.&lt;/para&gt;
            &lt;/parameter&gt;
            &lt;parameter name="Channel"/&gt;
            &lt;parameter name="Destination"/&gt;
            &lt;parameter name="CallerIDNum"/&gt;
            &lt;parameter name="CallerIDName"/&gt;
            &lt;parameter name="ConnectedLineNum"/&gt;
            &lt;parameter name="ConnectedLineName"/&gt;
            &lt;parameter name="UniqueID"/&gt;
            &lt;parameter name="DestUniqueID"/&gt;
            &lt;parameter name="Dialstring"/&gt;
        &lt;/syntax&gt;
    &lt;/managerEventInstance&gt;
    &lt;managerEventInstance class="EVENT_FLAG_CALL"&gt;
        &lt;synopsis&gt;Raised when a dial action has ended.&lt;/synopsis&gt;
        &lt;syntax&gt;
            &lt;parameter name="DialStatus"&gt;
                &lt;para&gt;The value of the &lt;variable&gt;DIALSTATUS&lt;/variable&gt; channel variable.&lt;/para&gt;
            &lt;/parameter&gt;
            &lt;parameter name="SubEvent"&gt;
                &lt;enumlist&gt;
                    &lt;enum name="Begin"/&gt;
                    &lt;enum name="End"/&gt;
                &lt;/enumlist&gt;
                &lt;para&gt;A sub event type, specifying whether or not the dial action has begun or ended.&lt;/para&gt;
            &lt;/parameter&gt;
            &lt;parameter name="Channel"/&gt;
            &lt;parameter name="UniqueID"/&gt;
        &lt;/syntax&gt;
    &lt;/managerEventInstance&gt;
&lt;/managerEvent&gt;</pre>
</div></div>

<h2><a name="AMIEventDocumentation-SourceComments"></a>Source Comments</h2>

<ul>
        <li>Event documentation <b>MUST</b> be within a documentation comment block (shown below), regardless of its location within an implementation file.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">/*** DOCUMENTATION
....
***/</pre>
</div></div></li>
        <li>If documentation is placed at the top of the header file, the documentation <b>MUST</b> be enclosed with the &lt;managerEvent/&gt; tag, as well as the &lt;managerEventInstance/&gt; tags that describe the event instances.  The documentation is not modified by the pre-processing script, but will be modified by the post-processing script in that it will be combined with other &lt;managerEventInstance/&gt; tags for the same event.</li>
        <li>If documentation is placed within a source file co-located with AMI event call, the event documentation <b>MUST</b> be on the lines immediately preceding the AMI event call.
        <ul>
                <li>The AMI event call <b>MUST</b> be one of the following three methods: ami_manager_event, manager_event, or ami_manager_event_multichan</li>
                <li>The AMI event call <b>MUST</b> contain the full manager event name with no format specifiers or ternary operations</li>
                <li>Only fields in the AMI event call that contain no format specifiers will be documented.  If a field consists of a format specifier or contains some format specifier, it must be explicitly documented.</li>
                <li>Documentation co-located with an AMI event call may or may not contain a &lt;syntax /&gt; element.  Parameter documentation will automatically be assumed to be children nodes of a &lt;syntax/&gt; element if one is not found.</li>
        </ul>
        </li>
</ul>

    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;" class="grey">
                        <a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
       <a href="https://wiki.asterisk.org/wiki/display/AST/AMI+Event+Documentation">View Online</a>
              |
       <a href="https://wiki.asterisk.org/wiki/display/AST/AMI+Event+Documentation?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>