Does anyone use the table asterisk.kvstore FreePBX modules Queuestats


(Communication Technologies) #1

FreePBX/Asterisk 14

Hello,

I am looking for a way to dynamically get a list of queues that an extension is a part of as part of an evaluation in my dialplan.

I was thinking I could use the data in the MySQL asterisk.kvstore_FreePBX_modules_Queuestats. Each record seems to list all the extension users and their queues, but there are thousands of records and I am now sure how to pick the latest one?

I tried sorting ascending and descending on id (not a listed field, but query took). Does anyone know how to get the latest entry (which I am hoping would show the latest updates to queue agents)?

Thanks!


(Itzik) #2

If you are using dynamic agents the asterisk DB has:

/Queue/PersistentMembers/<queue num>

This will return you all current logged in members (again, dynamic only)

So for example. Queue 8003 has 201 and 202 logged in:

/Queue/PersistentMembers/8003                     : Local/202@from-queue/n;0;0;Local/202@from-queue/n;Local/202@from-queue/n;;0|Local/201@from-queue/n;0;0;Local/201@from-queue/n;Local/201@from-queue/n;;0

Alternatively you may try to use QUEUE_MEMBER_LIST: https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_QUEUE_MEMBER_LIST

Dialplan:

exten => s,n,Set(QueueMemList=${QUEUE_MEMBER_LIST(8003)})
exten => s,n,Noop(Here's the list: ${QueueMemList})

And the log:

-- Executing [s@get-q:3] Set("SIP/64066-000000d4", "QueueMemList=Local/101@from-queue/n,Local/204@from-queue/n,Local/202@from-queue/n,Local/201@from-queue/n") in new stack
-- Executing [s@get-q:4] NoOp("SIP/64066-000000d4", "Here's the list: Local/101@from-queue/n,Local/204@from-queue/n,Local/202@from-queue/n,Local/201@from-queue/n") in new stack

As you can see, this returns the static members as well.

You can probably achieve it by using a while loop and the CUT function.


(Communication Technologies) #3

My only problem with this approach is I won’t know the queue numbers ahead of time and I could code them all to be checked, but then every time a new queue is added I will have to go back and modify the code. I see in the asterisk.kvstore_FreePBX_modules_Queuestats seems like it lists all the agents and all of their queues, but I cannot seem to figure out how to get to the most recent record (the fields are key and val), but it looks like I could use this.

My other thought is to use the show queue command to get a list of all the queues, then use the queue member list to find the agent, but hoping to find a more simplified approach. I’m going to see if I can understand the key value and report back.


(Itzik) #4

I don’t have that module installed, so I don’t have that table on my VM.

I did see tho the following:

MariaDB [(none)]> use asterisk;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [asterisk]> select extension from queues_config;
+-----------+
| extension |
+-----------+
| 4110      |
| 5110      |
| 8000      |
| 8001      |
| 8003      |
| 9000      |
+-----------+
6 rows in set (0.00 sec)

MariaDB [asterisk]>

This one returns a list with all queues.


(Communication Technologies) #5

I shifted gears and this is my approach. It seems inefficient, but works.

  1. Set a loop counter ${QUEUELOOP} to 1.
    exten => s,n,Set(QUEUELOOP=1)

  2. Count the number of queues on the system, and set them to a variable: ${QUEUELOOPMAX}. I am using the word “max” as that shows up on every queue line for the ‘queue show’ command.
    exten => s,n(loopstart),Set(QUEUELOOPMAX=${SHELL(asterisk -rx 'queue show' | egrep max | wc -l)}

  3. Get an ordered list of queues and select the nth queue, based on current value of ${QUEUELOOP}.
    exten => s,n,Set(QUEUECHK=${SHELL(asterisk -rx 'queue show' | egrep max | grep -o '^\S*' | sort | awk 'NR==${QUEUELOOP}{ print; }'

  4. Check for the extension as a member of the current queue under evaluation ${QUEUECHK}.
    exten => s,n,Set(QUEUEMEMBERRESULT=${SHELL(asterisk -rx 'queue show ${QUEUECHK}' | egrep ${CALLERID(dnid)} | cut -d"@" -f1 | cut -d"/" -f2)}

  5. If the extension is contained in the ${QUEUEMEMBERRESULT} the extension is an agent in the queue, and transfer to the queue, otherwise increase the loop count by +1.
    exten => s,n,GotoIf($[${QUEUEMEMBERRESULT} = ${CALLERID(dnid)}]?route:noroute) exten => s,n(route),Goto(ext-queues,${QUEUECHK},1)
    exten => s,n(noroute),Set(QUEUELOOP=$[${QUEUELOOP} + 1])

  6. If ${QUEUELOOPMAX}>${QUEUELOOP} then try again at the top going to the next skill, otherwise the treatment is over.
    exten => s,n,GotoIf($[${QUEUELOOPMAX} > ${QUEUELOOP}]?loopstart:hangup)
    exten => s,n(hangup),Hangup()

This cannot be the best way to do it, but it all works, in dialplan. Some of it could be combined, but I think the way it is broken out will make it easier to understand for future editors of the treatment.


(system) closed #6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.