<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Good to hear that my input help and a big thanks for sharing your
resulting query with explanation. I will store your message in my
"smart SER tricks" folder :-)<br>
g-)<br>
<br>
sip wrote:
<blockquote cite="mid20060630114003.M54107@arcdiv.com" type="cite">
  <meta content="text/html; charset=iso-8859-1"
 http-equiv="Content-Type">
  <meta content="Open WebMail 2.20 20031014" name="GENERATOR">
  <font size="2">Thanks, Greger, that actually gave me an idea of how
to solve it but in a completely different way.&nbsp; <br>
  <br>
I was playing with your idea, which works really well.... the modified
query comes to: <br>
  <br>
SELECT t1.from_uri as Caller, t1.to_uri as Callee, TIMEDIFF(t2.time,
t1.time) as Duration, t1.time as CallDate, a1.username as alias,
a1.contact as myuser FROM acc t1,acc t2, aliases a1 WHERE
t1.sip_callid=t2.sip_callid AND ((t1.fromtag=t2.fromtag AND
t1.totag=t2.totag) OR (t1.fromtag=t2.totag AND t1.totag=t2.fromtag))
AND t1.sip_method='INVITE' AND t2.sip_method='BYE' AND (t1.to_uri LIKE
'%&lt;username&gt;%' OR (t1.to_uri=a1.contact AND a1.contact LIKE
'%&lt;username&gt;%')) AND (select count(*) from acc where
sip_callid=t1.sip_callid and sip_method='INVITE' and from_uri LIKE
'%&lt;username&gt;%')=0 GROUP by t1.time ORDER BY t1.time DESC;
  <br>
  <br>
Of course, this doesn't show anything actually useful in the 'alias'
column because it selects the same entry once for each alias (a cross
join), and with my 'group by t1.time' to limit that to one entry per
time slot, it ends up displaying just the first alias in the table...
but this is really almost EXACTLY what I wanted. I could discard that
field completely, and still, with that query, show who called the user
and when. An elegant solution, thank you. <br>
  <br>
However, I decided to add one minor step to it in order to, well, make
things more complex, really.&nbsp; <br>
  <br>
I grab a list of aliases for a particular user and place them into an
array... then I build the query string based on that list:
  <br>
  <br>
SELECT t1.from_uri as Caller, t1.to_uri as Callee, TIMEDIFF(t2.time,
t1.time) as Duration, t1.time as CallDate FROM acc t1,acc t2 WHERE
t1.sip_callid=t2.sip_callid AND ((t1.fromtag=t2.fromtag AND
t1.totag=t2.totag) OR (t1.fromtag=t2.totag AND t1.totag=t2.fromtag))
AND t1.sip_method='INVITE' AND t2.sip_method='BYE' AND (t1.to_uri LIKE
'%&lt;username&gt;%' or t1.to_uri LIKE '%&lt;alias1&gt;%' OR t1.to_uri
LIKE '%&lt;alias2&gt;%'... etc) AND (select count(*) from acc where
sip_callid=t1.sip_callid and sip_method='INVITE' and from_uri LIKE
'%&lt;username&gt;%')=0 ORDER BY t1.time DESC;
  <br>
  <br>
  <br>
What this ends up giving me is a list of calls to that user, but
formats them in such a way that I can show not only where the calls
came from, but to which alias they went (all the aliases are DIDs, so
this may be helpful for some people). <br>
  <br>
Thank you thank you thank you again. Without your help, I probably just
would have given up. :) <br>
  <br>
N.
  <br>
  <b><br>
  <br>
On Fri, 30 Jun 2006 11:07:16 +0200, Greger V. Teigre wrote</b>
  <br>
&gt; To acc, I don't know off the top of my head how accounting modules
uses
from vs ruri, but it should be fairly easy to change it to use ruri
(which is changed by lookup("aliases")). There are some format
modification possibilities found in README of acc module. <br>
&gt; <br>
&gt; Or what about adding something like this to your query:
  <br>
&gt; SELECT &lt;existing&gt;, a1.username as alias a1.contact as myuser
FROM
aliases a1, &lt;existing&gt; WHERE &lt;existing AND (t1.to_uri LIKE
'%username&gt;%' OR (t1.to_uri=contact AND contact LIKE
'%username&gt;%')) &lt;existing&gt; <br>
&gt; <br>
&gt; it's an attempt at a join with the alias table. No guarantees, but
play
around with it.
  <br>
&gt; g-)
  <br>
&gt; <br>
&gt; sip wrote:
  <blockquote type="cite" cite="mid20060629143951.M19623@arcdiv.com">
    <pre wrap="">Okay... let me approach this a different way and see if anyone has ideas. 

We do logging using the ACC table... not for billing purposes, but so users
can have a look at their logs (billing CDRs are kept on Asterisk and are
accurate and good).  The problem is this... 

Our current query to display incoming calls looks like this:

SELECT t1.from_uri as Caller, t1.to_uri as Callee, TIMEDIFF(t2.time, t1.time)
as Duration, t1.time as CallDate FROM acc t1,acc t2 WHERE
t1.sip_callid=t2.sip_callid AND ((t1.fromtag=t2.fromtag AND t1.totag=t2.totag)
OR (t1.fromtag=t2.totag AND t1.totag=t2.fromtag)) AND t1.sip_method='INVITE'
AND t2.sip_method='BYE' AND t1.to_uri LIKE '%&lt;username&gt;%' AND (select count(*)
from acc where sip_callid=t1.sip_callid and sip_method='INVITE' and from_uri
LIKE '%&lt;username&gt;%')=0 ORDER BY t1.time DESC;

It's a complex query, but it works quite well... UNTIL you put aliases into
the picture. 

When using aliases, all transactions in and out in the logs are written as the
user's alias, and not the user himself. This makes sense, but it's giving me a
headache for logging. If I attempt to use a lookup("aliases") command to
rewrite the URI for the purposes of logging, the BYE message vanishes. 

So I guess my question is:  is there an elegant solution for this, or can
someone give me a way to go through each and every user's alias, create a
table like the one above, and then somehow merge the tables, ordered by timestamp?

I have quite taxed the limit of my SQL knowledge, so I'm at a loss. 

N.

On Wed, 28 Jun 2006 19:02:58 -0400, sip wrote
  </pre>
    <blockquote type="cite">
      <pre wrap="">Something else I noticed that perhaps someone could shed light upon:

If I DO put the lookup("aliases") line in there, the call never logs 
a BYE message.  Why does that happen? Can someone fill me in on that?

It's strange... just when you think you have a handle on all of this,
something comes along you just completely don't understand.

N.

On Wed, 28 Jun 2006 18:37:29 -0400, sip wrote
    </pre>
      <blockquote type="cite">
        <pre wrap="">Okay... help me visualise something.  Now, as far as I can tell, SER 
is doing exactly what it's supposed to be doing, but I can't figure 
out how to get it to do something different.

I have an accounting section (my log flag is 1) that looks like this:

if((method=="INVITE" &amp;&amp; !has_totag()) || method=="BYE")
{
        setflag(1);
};

Basic, simple logging section. But when someone calls through from a 
DID to an alias in the aliases table, it of course logs the sip_to 
as the alias.

Fine, I thought. I'll just add a lookup("aliases") before the 
setflag and all will be well, right? No. Then it doesn't seem to log 
anything at ALL.

So what I'm trying to figure out is how to get SER to log a call 
coming into an alias as a call to the user who's aliased.

I.e. a call is coming in from <a href="mailto:1010@remote.proxy.com"
 class="moz-txt-link-abbreviated">1010@remote.proxy.com</a> to 
<a href="mailto:9999@proxy.com" class="moz-txt-link-abbreviated">9999@proxy.com</a> (which is really an alias to user <a
 href="mailto:1234@proxy.com" class="moz-txt-link-abbreviated">1234@proxy.com</a>).  
 Right now, SER is logging in the acc tables that the call went to 
<a href="mailto:sip:9999@proxy.com" class="moz-txt-link-abbreviated">sip:9999@proxy.com</a>.

I want to have it log that the call went to <a
 href="mailto:1234@proxy.com" class="moz-txt-link-abbreviated">1234@proxy.com</a> and NOT 
that it went to the alias.

This:

if((method=="INVITE" &amp;&amp; !has_totag()) || method=="BYE")
{
     lookup("aliases");   
     setflag(1);
};

gets me nothing at all.

Ideas, anyone? I'm stumped. I'm sure it's something drastically 
simple that I'm just not getting.

N.
_______________________________________________
Serusers mailing list
<a href="mailto:Serusers@lists.iptel.org"
 class="moz-txt-link-abbreviated">Serusers@lists.iptel.org</a>
<a href="http://lists.iptel.org/mailman/listinfo/serusers"
 class="moz-txt-link-freetext">http://lists.iptel.org/mailman/listinfo/serusers</a>
      </pre>
      </blockquote>
    </blockquote>
    <pre wrap="">_______________________________________________
Serusers mailing list
<a href="mailto:Serusers@lists.iptel.org"
 class="moz-txt-link-abbreviated">Serusers@lists.iptel.org</a>
<a href="http://lists.iptel.org/mailman/listinfo/serusers"
 class="moz-txt-link-freetext">http://lists.iptel.org/mailman/listinfo/serusers</a>

  </pre>
  </blockquote>
  <br>
  <br>
  <br>
  </font>
</blockquote>
</body>
</html>