title: How to extract unanswered calls from Asterisk's CDR table (mysql)?
body: <p>I'm trying to make a web page which lists unanswered calls from CDR. On incoming call all softphones and some mobile phones ring simultaneously. Asterisk version is 1.8.5.</p>
  
  <p>Here is what gets written to CDR table for a single <em>ANSWERED</em> call:</p>
  
  <pre>╔═════════════════════╦══════╦═════════╦═════╦══════════╦═══════════════════════════╦═══════════════════════════╦═════════╦═══════════════════════╦══════════╦═════════╦═════════════╦══════════╦═════════════╦═══════════╦════════════════╦══════════╗
  ║      calldate       ║ clid ║   src   ║ dst ║ dcontext ║          channel          ║        dstchannel         ║ lastapp ║       lastdata        ║ duration ║ billsec ║ disposition ║ amaflags ║ accountcode ║ userfield ║    uniqueid    ║ imported ║
  ╠═════════════════════╬══════╬═════════╬═════╬══════════╬═══════════════════════════╬═══════════════════════════╬═════════╬═══════════════════════╬══════════╬═════════╬═════════════╬══════════╬═════════════╬═══════════╬════════════════╬══════════╣
  ║ 2012-02-06 12:40:45 ║      ║ 5020971 ║ 595 ║ OUTGOING ║ Local/595@OUTGOING-5d9a;2 ║ SIP/help.desk-000000b8    ║ Dial    ║ SIP/help.desk/595,,Tt ║        8 ║       0 ║ ANSWERED    ║        3 ║             ║           ║ 1328524845.301 ║        0 ║
  ║ 2012-02-06 12:40:45 ║      ║ 5020971 ║ 599 ║ OUTGOING ║ Local/599@OUTGOING-038b;2 ║ SIP/help.desk-000000b9    ║ Dial    ║ SIP/help.desk/599,,Tt ║        8 ║       0 ║ NO ANSWER   ║        3 ║             ║           ║ 1328524845.303 ║        1 ║
  ║ 2012-02-06 12:40:44 ║      ║ 5020971 ║ s   ║ to_tech  ║ SIP/help.desk-000000b6    ║ Local/595@OUTGOING-5d9a;1 ║ Queue   ║ TECH,Tt,,,300         ║      111 ║     110 ║ ANSWERED    ║        3 ║             ║           ║ 1328524844.298 ║        0 ║
  ╚═════════════════════╩══════╩═════════╩═════╩══════════╩═══════════════════════════╩═══════════════════════════╩═════════╩═══════════════════════╩══════════╩═════════╩═════════════╩══════════╩═════════════╩═══════════╩════════════════╩══════════╝</pre>
  
  <p>The SQL to get the unanswered calls is this:<p><p>
      <code>SELECT * FROM cdr WHERE disposition = 'NO ANSWER' AND imported='0'</code><br><br>
  Needless to say, I'm getting false positives with calls that are actually answered. :-)
  <p>
  They only link I see is that the NO ANSWER and ANSWERED lines have very short time interval between them (and they share the same src number).</p>
  
  <p>Now, before I go ahead and start checking if there are some ANSWERED calls from the same number with a close time interval (like 3 seconds), I'd like to hear if someone knows a better way to solve this.
  <p>
  I don't speak extensions.conf very fluently and the guys who actually put our dialplan up are long gone but I noticed this in extensions.conf:</p>
  
  <pre>
  [class1]
  exten => s,n,SET(CDR(accountcode)=${UNIQUEID})
  include => accounts
  include => OUTGOING
  </pre>
  
  <p>If I get this straight, the exten line there is supposed to set accountcode field in the CDR table to a value of the incoming call's uniqueid? Anyway it is not working as the accountcode field is never filled in the table.</p>