[Asterisk-Users] Manager Interface Needs a protocol

Anthony Minessale anthmct at yahoo.com
Wed Oct 15 08:49:46 MST 2003


I was using the Asterisk::Manager perl module and had some troube with it
so I decided to make my own.  I have a pretty good prototype after a few hours 
(My main point about the protocol is at the bottom of this example.)
 
http://asterisk.650dialup.com is where you can download it.
 
 
my $man  = init Asterisk::AstMan ({
                                   -user => "asterisk",
                                   -secret => "1234",
                                   -host => "localhost"
                                  });
 
This auths you and logs you in 
you can do usual stuff like 
 
print $man->command("show agents");
print $man->command("show queues");
print $man->command("show channels");
 
The cool part is you can register a code ref to a certian Event 
and then listen on the socket all day and the code registered to that certian event 
will fire.
 
 
$newext = sub {
  # $ref will be a hash ref of all the parameters in the event
  my $ref = shift;
  print "New Extension Event Detected\n\n";
};

$man->reg_event("Newexten",$newext);
$man->listen(); # a man who listens, won't your wife be jealous ;)
 
Now the program will just sit there and listen to all the event data 
and calls the function hooked into the Nexexten event whenever it sees it 
the special event ALL can be used to match every undefined event 
 
 
Now my only problem is that while making this module I started wishing 
that is was just a tiny bit more like maybe http or imap 
 
I dont wanna hack up the code and make my stuff propitary so I was wondering if anyone agrees It is close to being a cut and dry protocol it would be nice to have it uniform.
 
1 issue I notice is that since you are getting a nonstop flow of events sometimes 
when you send an Action  you have to intercept some of those events 
and I thought it may be nice to either format the req so you know which reply 
is for you or to formally request the events to flow rather than have them come by default.
 
I think you can reduce the user's rightst to stop the events but what i was 
looking for was a common structure.
 
My proposed example uses Content-Length so you know how much to read
off the socket but I guess using just <lf> in the data and <cr><lf><cr><lf> as EOR works ok too for variable lengths   
 
EXAMPLES... 
 
You send your own homeade ReplyID so you recognize your answer.
 
Action: Queues
ReplyID: 1234
 
so then it replies 
 
ReplyID: 1234
Content-Desc: Action
Content-Type: text/plain
Content-Length: 4031
 
tech_support has 0 calls (max unlimited) in 'ringall' strategy
   Members:
      Agent/118 with penalty 1 has taken no calls yet

...................... etc so on 
 
 
or
Action: Command
ReplyID: 888
Command: show channels
 
..........
 
 
To start pouring on the events 
 

Action: EventFlow
 
and you get nonstop flow of ..
 
ReplyID: *
Content-Desc: Event
Content-Type: text/plain
Content-Length: 111
 
Event: Newchannel
Channel: Agent/112
State: Up
Callerid: *8015711666*1608*
Uniqueid: 1066231464.36432kick ASS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20031015/6852a2d5/attachment.htm


More information about the asterisk-users mailing list