Asterisk.net (AsterNet) and QueueStatus

Mar 7, 2014 at 3:02 PM
I am attempting to build a Live statistical view from our Asterisk PBX.

The asterisk.net / AsterNet has been handy in trying to understand how different calls are implemented / sent to the PBX but I am struggling to force the calls to get a response from the system.

I have attempted to get the details a couple of ways but get the same result.

We are running Asterix version 1.8

I am using the following references
using Asterisk.NET.Manager;
using Asterisk.NET.Manager.Response ;
using Asterisk.NET.Manager.Action;
using Asterisk.NET.Manager.Event;
using Asterisk.NET.FastAGI;
I can successfully get a connection to our system using
private void btnConnect_Click(object sender, EventArgs e)
        {
            string address = this.tbAddress.Text;
            int port = int.Parse(this.tbPort.Text);
            string user = this.tbUser.Text;
            string password = this.tbPassword.Text;

            pbxConn = new ManagerConnection(address, port, user, password);
            pbxConn.UnhandledEvent += new ManagerEventHandler(pbxConn_Events);
            try
            {
                pbxConn.Login();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error connect\n" + ex.Message);
                pbxConn.Logoff();
            }
        }

        void pbxConn_Events(object sender, ManagerEvent e)
        {
            Debug.WriteLine("Event : " + e.GetType().Name);
        }
Calling the QueueStatus with QueueStatusAction and conn.SendAction()
private void QueueStatus(string sQueue)
        {
            QueueStatusAction qsa = new QueueStatusAction();
            //qsa.Queue = sQueue;
            try
            {
                ManagerResponse mr = pbxConn.SendAction(qsa, 200000);
                messagebox.show("Queue Status" + "\n\tResponse:" + mr.Response + "\n\tMessage:" + mr.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
First time this is run I instantly get a response as follows
When looking at ManagerResponse I get a Response:Success and Message:Queue status will follow
Although I then can't seem to see anything else, even if I run it multiple times on the same connection.

Calling the QueueStatus with QueueStatusAction and conn.SendEventGeneratingAction()
private static void displayQueue()
        {
                string queueStatus = "";

                QueueStatusAction myQueue = new QueueStatusAction() ;
               // myQueue.Queue = "400";
            
            ResponseEvents re;
            try
            {
                re = pbxConn.SendEventGeneratingAction(myQueue);
            }
            catch (EventTimeoutException e)
            {
                // this happens with Asterisk 1.0.x as it doesn't send a QueueStatusCompleteEvent
                re = e.PartialResult;
            }

            foreach (ManagerEvent e in re.Events)
            {
                if (e is QueueParamsEvent)
                {
                    QueueParamsEvent qe = (QueueParamsEvent)e;
                    queueStatus = queueStatus + ("QueueParamsEvent" + "\n\tQueue:\t\t" + qe.Queue + "\n\tServiceLevel:\t" + qe.ServiceLevel);
                }
                else if (e is QueueMemberEvent)
                {
                    QueueMemberEvent qme = (QueueMemberEvent)e;
                    queueStatus = queueStatus + ("QueueMemberEvent" + "\n\tQueue:\t\t" + qme.Queue + "\n\tLocation:\t" + qme.Location);
                }
                else if (e is QueueEntryEvent)
                {
                    QueueEntryEvent qee = (QueueEntryEvent)e;
                    queueStatus = queueStatus + ("QueueEntryEvent" + "\n\tQueue:\t\t" + qee.Queue + "\n\tChannel:\t" + qee.Channel + "\n\tPosition:\t" + qee.Position);
                }
            }
            MessageBox.Show(queueStatus);
        }
First time this is run I instantly get a response as follows
When looking at re I get a Response:Success and Message:Queue status will follow

When I run this a subsequent time it seems to timeout and get to the bit of code
            catch (EventTimeoutException e)
            {
                // this happens with Asterisk 1.0.x as it doesn't send a QueueStatusCompleteEvent
                re = e.PartialResult;
            }
re then contains Response:Success and Message:Queue status will follow
the
 foreach (ManagerEvent e in re.Events)
simply drops out with no items

Once I have worked this last part out I can easily keep a live dashboard for our support.

I am 100% happy that there is definitely a connection being made as when I run the same code within telnet it starts with the Response:Success and Message:Queue status will follow
But then it is followed by the groups and members!

Has anyone come across this, is it an issue with my coding or how i'm accessing the asterisk.net (AsterNet).

Cheers

David
Mar 11, 2014 at 11:03 AM
ok, scrub that, found the solution....

after banging my head on the wall for some time, my colleague pointed me in the right direction.

My challenge was to get the queue detail out of asterisk (the alternative was to query the CEL table in MySQL, which would mean opening up / managing security into the database) so to get the detail using asterisk.net (asternet) direct to the interface would provide a much better solution.

The key is in the responses within the connection
        pbxConn = new ManagerConnection(address, port, user, password);
        pbxConn.QueueParams += new QueueParamsEventHandler(pbxConn_QueueParams);
        pbxConn.QueueMember += new QueueMemberEventHandler(pbxConn_QueueMember);
        pbxConn.QueueStatusComplete += new QueueStatusCompleteEventHandler(pbxConn_QueueStatusComplete);
        pbxConn.login();
Now when I call the following
        QueueStatusAction qsa = new QueueStatusAction();
        qsa.Queue = sQueue.ToString ();

        ResponseEvents mr = pbxConn.SendEventGeneratingAction (qsa, 3000);
Each of the QueueParans / QueueMember and QueueStatus fire, meaning I can get the information I need before the complete means i'm done!!!

I can then compile the information to a class building up my queue calls, members and member status.

Bingo, hopefully this will help if someone is struggling to accomplish the same challenge I had.

Cheers

David
Marked as answer by davidInspHire on 3/11/2014 at 4:03 AM
Coordinator
Mar 12, 2014 at 10:10 AM
Thanks for the feedback David. Glad you resolved the issue.
Apr 21, 2014 at 9:07 AM
Thanks David I was stuck :D