[asterisk-users] What's up with the Manager Interface?!?!

Michael Collins mcollins at fcnetwork.com
Wed Nov 29 13:25:14 MST 2006


> Here's a good example. I'm trying to get SIP blf. I managed to split
my
> result into a list of lines by splitting on ANY of \r\n, \n or \r.  I
was
> going use the column headings from the third line as my keys for my
> dictionary/hash, rather than hard coding them. Notice anything? The
'Call
> ID' column has a space right in the middle which means I can't simply
> split this up by white-space.
> 
>         Response: Follows
>         Privilege: Command
>         Peer             User        Call ID      Extension
Last
> state     Type
>         xxx.187.128.105  2944090     f7ee98da-6d  2944006
InUse
> xpidf+xml
>         xxx.187.128.105  2944090     111e388b-6b  2944077
Idle
> xpidf+xml
> 

Cool idea!  As far as splitting on whitespace that does look like a
problem.  I hate to make assumptions about formatting on output like
this, but perhaps this rule would work: split on at least two
consecutive whitespace chars, assuming that the whitespace between
"Peer" and "User" is actually spaces on not tabs.  I don't know Python
but the Perl command would look like this:
@keys = split /\s{2,}/, $dataline;
Where @keys is an array of the split out items ('Peer','User','Caller
ID',etc.)
And $dataline is the variable containing the line to be split.
The regexp in the split function says, "Split on at least two
consecutive whitespace characters, treating all consecutive whitespace
characters as one delimiter."  (Did that make sense?)  

I noticed that the output *SEEMS* to be fixed-width, but I think you are
correct about not hard-coding the positions of the fields.  If you feel
safe making the assumption that no two fields will ever be separated by
less than two whitespace chars then splitting on the 2-or-more
whitespace chars would work.  

BTW, which AMI command returns those results?  Just curious.

-MC

P.S. - It's been a learning experience, but the Perl/POE/Asterisk client
combo has been pretty stable.  It is event-driven and non-blocking.
Email me off list and I'll be happy to show you what limited success
I've had with it thus far.


More information about the asterisk-users mailing list