Summary:ASTERISK-05008: [patch][post 1.4] agents in realtime
Reporter:Jose Pablo Fernandez (pupeno)Labels:
Date Opened:2005-09-06 13:49:39Date Closed:2007-03-07 18:38:52.000-0600
Versions:Frequency of
Environment:Attachments:( 0) 2006-06-23-realtime-r35390.patch
( 1) 2006-10-31-rt-chan-agent.patch
( 2) agents-and-realtime2.patch
( 3) agents-and-realtime4.patch
( 4) chan_agent-realtime-agents.patch
( 5) realtime-agents-r35390.patch
Description:It would be nice if agents could be served from a database the same woy realtime SIP or dialplan works.
(I am working on it, and I should start attaching patches soon).
Comments:By: Jose Pablo Fernandez (pupeno) 2005-09-06 13:57:39

docu-plus-find_agent.patch is a patch containing the following:
All the comments of http://bugs.digium.com/view.php?id=5133 , once they are commited, I will be able to submit a cleaner patch (that is, without the documentatio), moy I point to Darcs (http://abridgegame.org/darcs/) here ? It would have been allowed me to eassily send you only the right changes.
Now the important part is that I made a function called find_agent() that can find an agent based on username. I changed __login_exec() to use this new fuction, other functions should be changed latter.
This doesn't really make any difference te functionallity right now, but the new abstraction (find_agent) will allow me to do the realtime part easily.

By: Jose Pablo Fernandez (pupeno) 2005-09-06 17:02:49

The new file, docu-plus-find_agent-and-more.patch, contains even more documentation as well as lots of clean ups (even in code, I couldn't stand vairables named app, app2, app3, synopsis, synopsis2, synopsis3 and so on, so I made some arrays).
I know it is getting a bit mossy because the patch is big, but I do not know hot to fragment it, any advice is appretiated (may I again point to Darcs ?).
I have been told (by the company I am working for) that tomorrow, the disclaimer should be ready.

By: drmac (drmac) 2005-09-09 11:37:19

reinventing the wheel here. I believe this already exists. Search the closed bugs.

By: Jose Pablo Fernandez (pupeno) 2005-09-09 14:05:05

drmac, I disagree, we did some searching and I've redone some searching and unless it is submitted with non-related (bad) subject, it is not there.

By: Jose Pablo Fernandez (pupeno) 2005-09-09 14:13:43

The patch I have just submited, agents-and-realtime.path, is an initial implementation of realtime support for agents.
We tested it a bit, more testing is needed.
I would also like to got feedback from other coders that are familiar with this code. You'll see that my code is very well documented so it'll be veary easy to understand.
Of the code I am submiting I am worried about this:
- The way I am using agent_clean(), is it safe ?
- I am locking mutexes on all realtime agents at each loging (for doing clean up), a non-blocking mutex would be better (if I don't get the lock, I don't clean up, no bigd deal).

By: Jose Pablo Fernandez (pupeno) 2005-09-09 14:16:04

agents-and-realtime2.patch is an improvement over the provious ones, please ignore all other (fell free to delete them, particualy agents-and-realtime*).
One more thing: I added a lot of documentation as well.

By: drmac (drmac) 2005-09-09 15:29:28

i found what i was talking about: ASTERISK-3943 is queues from realtime, not agents.

By: Roberto Lopes (rflopes3) 2005-09-10 07:45:36

I would like to know how the people are working with agents and ACD stuff WITHOUT have an PauseAgent/UnpauseAgent function. I know that this functions exists in app_queue BUT, only works with DYNAMIC agents witch is not the thes "CallCenter" kind of agents (unknow agents). Someone have ANY patch for chan_agent that implement this ?

By: Jose Pablo Fernandez (pupeno) 2005-09-14 12:53:20

chan_agent-realtime-agents.patch does'n intclude all the documentation that was included in the previous patches but that is already commited to head. That is, only the last patch would apply gracefully to HEAD as of today.

By: Jose Pablo Fernandez (pupeno) 2005-09-15 15:05:24

I have just faxed the disclaimer, my name is Jose Pablo Ezequiel Fernandez (and Pupeno is also on the disclaimer).

By: Jose Pablo Fernandez (pupeno) 2005-11-09 13:25:42.000-0600

CREATE TABLE `agents` (
 `id` bigint(20) unsigned NOT NULL auto_increment,
 `user` varchar(80) NOT NULL default '',
 `pass` varchar(80) NOT NULL default '',
 `name` varchar(80) default NULL,
 PRIMARY KEY  (`id`),
 UNIQUE KEY `user` (`user`)

By: Jose Pablo Fernandez (pupeno) 2005-11-10 11:27:24.000-0600

Can you change the table name from user to username?
 I have changed it for me in the source because I had some troubles to create a not case sensitive column called user in postgresql. I had made some researches and found the user is a reserved word in SQL.
                       Fiechter Adrian

By: Olle Johansson (oej) 2005-11-22 11:14:09.000-0600

Does this patch apply to the current CVS HEAD?

Do we have any test results from others? If not, please mail the mailing list asking for help testing this patch.

Thank you!


By: Matt O'Gorman (mogorman) 2006-01-09 09:02:28.000-0600

/* FIXME: The following code should go once the previous one is known to work. */

I take it the code that was described in that statement is gone and this is ready for some testing and a commit?

By: Olle Johansson (oej) 2006-01-30 14:03:41.000-0600

Any replies or should we close this issue as "sleeping beauty" until there's some action again?


By: Olle Johansson (oej) 2006-02-22 10:35:47.000-0600

Closing due to lack of answer. Will happily re-open when we have new action.

By: Jonathan Towne (jontow) 2006-06-21 20:09:34

I had this bug reopened because I'm doing a bit on this for a project I've got going at work.  As I write this, I can login/logout with realtime-backed agents, and will have a patch as soon as its up to date with trunk as of nowish.

Big thanks to pupeno for the initial hard work!

By: Jonathan Towne (jontow) 2006-06-21 21:08:34

Ok, patch against SVN trunk r35390 chan_agent.c is up.

Please test as thoroughly as possible, I didn't get a lot of time to do so tonight, and I've been at work long enough for now.

Known bugs so far:
* Something funny with audio streams in r35390 in general
* persistent logins do not work with realtime (but they still do otherwise)

Other than that.. hammer on it, you only need 3 columns in the DB (user, pass, name); all of which are varchar fields.

I left debugging statements in on purpose, they'll be removed with the final revision of the patch.  This definitely isn't it.

I'll be messing with it more tomorrow, but wanted to get it posted tonight so anyone who cares to can play a bit.  Report oddities with the code, questions (some I may not be able to answer it, remember, it wasn't originally my code and wasn't sure on a few things, ie. hunk #3 in the patch), etc here in mantis, please.

Disclaimer is on file.


By: Jonathan Towne (jontow) 2006-06-22 16:38:45

Current progress:  persistant agents is working (patch update coming soon)

Also in the works (and mostly tested with callbacklogins):  Agent state tracking via the realtime DB--(AVAILABLE, UNAVAILABLE, RINGING, OFFLINE, UNKNOWN).

We're doing the latter for tracking, it will also end up with another (WRAPUP), for use with dynamic wrap-up time, and the ability to cleanly implement a queue monitor.

Depending on feedback from the {community,developers}, the state-tracking patch may be a different "bug" entirely.  It is closely tied to realtime, but can be made optional.

By: Jonathan Towne (jontow) 2006-06-23 12:24:39

Added file: 2006-06-23-realtime-r35390.patch

Changes in this patch: fixes reload_agents() to allow 'persistentagents=yes' to work with both flatfile and realtime-backed configuration.

(That is the *only* change in this patch from realtime-agents-r35390.patch posted previously).

More to come.. feedback, anyone?

By: Serge Vecher (serge-v) 2006-06-23 13:05:15

jontow: I am sending here anybody who is asking about this on IRC. So far key2 has expressed interested, hopefully we'll see some results soon.

By: Adolfo R. Brandes (arbrandes) 2006-07-12 08:19:59

I'm very interested in "agent state tracking via the realtime DB", as posted above by jontow.

Currently, I'm starting tests on a backport to asterisk- of the latest agents realtime patch.  If it all works out in the lab, I'll have the first production results (from a 20+ agent call center) in a week.

By: Serge Vecher (serge-v) 2006-07-12 09:05:24

arbrandes: good to hear about your undertaking, but please remember that there is no discussion of backported patch allowed to take place on the bug-tracker, only trunk-based development. For backports, use other resources, such as asterisk-backports.org


By: Andrew Thompson (andrewt) 2006-07-12 10:57:49

I'm the developer working on this with jontow. The state tracking stuff is still in need of lots of work but we'd be happy to collaborate with you on it if you're also interested. We've been busy with other stuff for the last little while but I think we'll be getting back to working on the agent state tracking soon...


By: Adolfo R. Brandes (arbrandes) 2006-07-12 11:56:58

I'll be more than happy to help in the development or testing of agent state tracking.  Nevertheless, I can only test asterisk/trunk in the lab, a lab that is nowhere near well-equipped enough to draw reliable results from (especially for load tests).

Which is why I'll always have to backport stuff to the nearest stable version for production use.  Whether I'll be allowed to post the feeback from it here is up to you guys to decide.  I'd just like to contribute in the best way possible.

By: Serge Vecher (serge-v) 2006-07-12 12:09:47

arbrandes: however you do it off bugtracker is fine. I think you should get in touch with jontow / andrewt directly, so they can update this bug note with trunk-based patches based on your findings from "release" branch testing.

Just as a terminology clarification, 1.2.x and upcoming 1.4.x are called "releases", not "stable versions." The only "stability" implied in release branch is that it does not contain new features that trunk has, with associated occasional breakage that is usually fixed fairly quickly upon bug identification.

By: jmls (jmls) 2006-11-01 05:15:08.000-0600

can we have an updated patch against trunk for this feature ? Many thanks.

By: Jonathan Towne (jontow) 2006-11-01 05:36:57.000-0600

This particular feature has been deprecated in trunk.

Therefor, I cannot give you a patch against it; however, I do have a patch I've been maintaining against the 1.4 branch, which is effectively the last that I can use for the project mentioned earlier.  The patch is attached as 2006-10-31-rt-chan-agent.patch

Enjoy -- I probably won't be dealing with this bug anymore.

By: jmls (jmls) 2006-11-01 07:27:41.000-0600

yeah - you're right about svn trunk. Sorry, was mislead with the "post 1.4" part of the summary. Since 1.4 is not taking any more features, and trunk is not applicable, should this be closed ?

By: jmls (jmls) 2006-11-01 09:46:32.000-0600

the latest patch also applies cleanly to trunk .. note that chan_agent is *not* deprecated in trunk.

By: Adolfo R. Brandes (arbrandes) 2006-12-08 07:13:53.000-0600

Just a quick note: I'm using this patch heavily, and it works beautifully.  Thank you, pupeno!  However, it breaks empty or NULL passwords, for lack of proper variable initialization in find_agent().

By: Jonathan Towne (jontow) 2006-12-08 07:35:55.000-0600

arbrandes: are you using it with 1.2.x or 1.4.x or trunk?

By: Adolfo R. Brandes (arbrandes) 2006-12-08 07:43:12.000-0600

You caught me. ;) I'm using it in 1.2.  I'm guessing there was a change in the realtime engine upwards from 1.4 that would solve the empty-password issue.  Sorry about that!

Oh, and I should be thanking you too, jontow, not just pupeno.  Sorry about that, too!

By: Jonathan Towne (jontow) 2006-12-08 08:14:39.000-0600

Well, I'm glad you could get some use out of it.

On a side note; to be fair to jmls -- chan_agent is NOT deprecated in trunk, but the way I use it is (callbacklogin).  I'd appreciate some feedback from anyone who is using this in 1.4 with callbacklogin.. if anyone, that is.

Once deployment for the project I'm working on is getting closer, maybe I'll report my results with it, including any patches that may be added at that time.

By: Adolfo R. Brandes (arbrandes) 2006-12-08 08:26:52.000-0600

It is probable that I'll be using the realtime patch in production with 1.4 just as soon as my company's codebase (i.e., a truckload of patches to 1.2) is ported to it.

Since you bring it up, the deprecation of chan_agent's CallbackLogin features has us in a bit of a quandary.  Yes, most of the featureset can be duplicated with diaplan logic, but some pieces that are crucial to my company would be missing, such as the realtime functionality introduced here, the ability to do a "show agents" from the CLI, or more importantly the existence of the manager action "Agents".

How do you plan on dealing with this in the future?

By: Jonathan Towne (jontow) 2006-12-08 08:36:29.000-0600

We're either going to maintain callbacklogin patches, or maintain patches against 1.4 -- Our callcenter will probably never see 1.6+

Our other option is to start back at the beginning and rewrite everything to fit another VoIP call switch.

dialplan-agents doesn't fit our model very well either, so its not an option.

I'm pretty disappointed that Digium(tm)(r)(c)(...) has decided to deprecate it just as they actually stabilized it.  We had loads of problems with deadlocks in 1.2 (1-5 per day in testing with 2 agents only), but have had *0* in 4months with 1.4.

By: rafe (rafe) 2006-12-19 04:16:22.000-0600

Hello, I don't want to change to 1.4 right now. But the empty-password issue in 1.2 patch makes me crazy!! Is there any workaround ? Thanks

By: Adolfo R. Brandes (arbrandes) 2006-12-20 06:00:23.000-0600

rafe: if you like I can email you a simple patch to solve the problem.  We have to do it off the bugtracker because it is essentially a backport.

By: Vadim Berezniker (kryptolus) 2007-02-23 10:51:05.000-0600

+        AST_LIST_TRAVERSE(&agents, p, list) {
+                if (p->realtime && !ast_load_realtime("agents", "user", p->agent, NULL)) {
+ p->dead = 1; /* Mark this agent for destruction */
+ /* agent_unlink(p); */ /* Remove from list */
+ AST_LIST_REMOVE(&agents, p, list);
+ agent_cleanup(p); /* Destroy it */
+ continue;
+ }

You are removing the current element and then deleting it w/o using the safe traverse macro. This will cause a segfault if that case ever hits.

By: Russell Bryant (russell) 2007-03-07 18:38:48.000-0600

On our developer conference call today, it was decided that this bug should just be closed out.  Since this is a new feature, it would only be applied to the trunk.  Also, it is extremely unlikely that chan_agent will exist at all in 1.6, since the entire queue system will be rewritten.

This patch will stay available in the archives of the bug tracker in case anyone would like to use it.