Trunk

Sep 29, 2013 at 5:02 PM
Hi guys
second Thread.

Is there a way to know via AMI what Trunks are available in Asterisk installation ?

Thank for response.
Sep 30, 2013 at 9:28 AM
Depends on what you mean by "Trunk". You can get a list of the ZAP interfaces, and you can get a list of SIP Peers. So really, just depends on how you define trunk.

If you can be a little more specific, I'm sure there's a way :)
Oct 1, 2013 at 8:18 PM
thank skrusty
i mean all possibilities to make a call to the world from my pbx e.g.
sip provider, zap channels, external device like Patton, etc.
Oct 1, 2013 at 10:24 PM
As far as I know, and I may be wrong, there's no specific way to get a list of "trunks" because they're a concept not an actual asset within asterisk. I.e. a SIP peer could be a phone or could be a trunk from a sip provider. ZAP interfaces are different as they often tend to be access to external services.

I guess the answer is no, there's no specific way. If however you discover otherwise, be sure to update us! :)
Oct 2, 2013 at 11:20 PM
I found that in an installation of Asterisk with Freepbx, you can access to configuration file with GetConfig action and retrive information about trunk, intended by outbound connection, parsing extensions_additional.conf and looking for "OUT_x=aaa/bbb" pairs, Every pair is a trunk.
If i'm not wrong.
Oct 3, 2013 at 11:08 AM
Yes, that would work in theory! If you're trunks are well defined in your config file, then it should be fine to do that!
Oct 4, 2013 at 9:41 PM
With FREEPBX is the web interface that do the work, so they are "well defined" by phps i think.
Oct 6, 2013 at 8:18 PM
If you're able. don't be afraid to post some sample code on how to read the trunks from FreePBX. I assume it's using a regex or something?
Oct 6, 2013 at 8:42 PM
I'll try. For now you have to look for string like "OUT_1=SIP/xxxxxx" where xxxxxx is the name you give at the
trunk in FreePBX web interface. If there are more trunks, the number after OUT_ increase
one by one. Before the "/" there is the type of trunk. I hope to be clear.
Oct 6, 2013 at 8:48 PM
Edited Oct 6, 2013 at 8:48 PM
Here the function that does the work for me:
    private void CheckTrunks()
    {
        int counter = 0;
        ManagerResponse response = manager.SendAction(new GetConfigAction("extensions_additional.conf"));
        if (response.IsSuccess())
        {
            GetConfigResponse responseConfig = (GetConfigResponse)response;
            foreach (int key in responseConfig.Categories.Keys)
            {
                foreach (int keyLine in responseConfig.Lines(key).Keys)
                {
                    if (responseConfig.Lines(key)[keyLine].Substring(0, 4) == "OUT_")
                    {
                        GlobalVariables.Trunks[counter] = responseConfig.Lines(key)[keyLine].Substring(6, responseConfig.Lines(key)[keyLine].Length - 6);
                        counter++;
                    }
                }
            }
        }
    }
Marked as answer by skrusty on 10/6/2013 at 1:58 PM