Asterisk caller id lookup via LDAP to a Domino Directory

I got an idea last night to have Asterisk do a LDAP lookup to a Lotus Domino Directory for caller id names. This provides caller id names for any company phone number listed in the directory including people’s cell phone numbers. Today I spent a few of hours writing a shell script to be called via the Asterisk Gateway Interface(AGI). The AGI is very powerful with interfaces to many programming languages like PHP, Perl, Python, Ruby and shell. There are many examples on the wiki.

The shell script is called via the Asterisk dialplan on incoming calls. The shell script get passed all the standard AGI variables which includes the caller id number of the caller. The script requires OpenLDAP to be installed on the Asterisk server because it uses the ldapsearch function. The script builds a LDAP search filter and queries the LDAP server for any users with a matching phone number. It then sends a “set callerid” command via the AGI to add the name to the call.

Domino’s LDAP server seems to respond very fast and the script takes around 1/4 of a second to process. I don’t consider script to be done and still needs more error checking added. I figured I would post what I have so others can build off of what I have started. Here are some instructions if you want to use what I created. The Asterisk server I was using is running 1.4.2 . I think it will work fine with prior versions of 1.2.x, however I have not tested it on that.

  • Download Asterisk AGI script.
  • Rename the file ldaplookupphone.agi.
    mv ldaplookupphone.txt ldaplookupphone.agi
  • Put it in the /var/lib/asterisk/agi-bin directory.
    mv ldaplookupphone.agi /var/lib/asterisk/agi-bin/"
  • Make sure the asterisk user has execute permissions on the script.
    chmod 755 /var/lib/asterisk/agi-bin/ldaplookupphone.agi
  • Update 3 variables at the top of the script for the hostname, username and password for the LDAP server.
  • Follow the example below to alter your extensions.conf to run the script before calling the Dial application. After you make changes in remember to run dialplan reload at the Asterisk console.

Here is an example dialplan.
exten => 1234,1,Dial(SIP/1000)

It should be changed to look like this.
exten => 1234,1,AGI(ldaplookupphone.agi)
exten => 1234,n,Dial(SIP/1000)

In the future I hope to post other ways to do lookups to Lotus Notes databases from Asterisk AGI scripts.

4 Responses to “Asterisk caller id lookup via LDAP to a Domino Directory”

  1. Asterisk Anrufnummer in LDAP-Verzeichnis nachschlagen « Langweiliges Zeug Says:

    [...] nach eine Lösung um Anrufnummern in einem LDAP-Verzeichnis nachzuschlagen. Letztlich bin ich bei Matt Schmandt fündig geworden. Leider wollte das Skript nicht so, wie ich es gern gehabt hätte, daher musste [...]

  2. Click at Says:

    Click at…

    Matt Schmandt » Blog Archive » Asterisk caller id lookup via LDAP to a Domino Directory…

  3. Great wall 99 Says:


    Matt Schmandt…

  4. Sky1388 easy win Says:

    Sky1388 win…

    Matt Schmandt…

Leave a Reply

You must be logged in to post a comment.