21,914 views

Vacation and holiday dates from OTRS into Asterisk

Just finished a project where I had to create a setup where Asterisk, version 1.8.x, would check vacation and holiday dates available within OTRS 3.0.x.

Within OTRS it is possible to define vacation and holiday date calendars which can be linked to SLA and queues. Depending on the dates OTRS will act different than on normal working days.

The company wanted to maintain this date list in only one place and OTRS was chosen as the master location. Now OTRS has a well defined API which is also accessible through a SOAP – RPC interface. So as long as you can talk SOAP you can perform actions on the OTRS data.

The following is an explanation of how you can check for vacation and holiday dates in OTRS out of Asterisk by the use of an PHP AGI script.

First step:

Create your vacation and holiday dates in OTRS.

  • Goto Admin -> SysConfig -> Framework -> Core::Time::Calendarx (x is the calendar you whish to change). In the screenshot below I changed the second (2) calendar. (OTRS manual)
  • Add new dates by clicking on the right plus sign, or remove them by clicking on the minus sign.
  • Important is that you add a text value in the Text fields. This text will be available in Asterisk and must contain a value or Asterisk will not see it as a vacation or holiday.
  • When you are done click the Update button at the bottom of the page.

Second step:

Because we use the SOAP – RPC facility of OTRS we have to make sure the SOAP user and password are defined:

  • Goto Admin -> SysConfig -> Framework -> Core::SOAP.
  • Check the boxes before SOAP::User and SOAP:Password and change the fields to something else than the default (if you are security minded).
  • Click the Update button to save the changes.

What I will not discuss here is how you did secure your webserver. But normally you would minimize the access to the SOAP interface of OTRS. A minimal suggestion I would make is that you add the following part to your apache config files:

<Location /otrs/rpc.pl>
Order deny,allow
Allow from 192.168.1.0/255.255.255.0
Deny from all
</Location>

Third step:

Now we wil setup Asterisk. I will not discuss how to setup your Asterisk server. There are plenty of manuals online for this, or hire me.

Requirements:

  • Asterisk 1.8.x
  • PHP and PHP-SOAP
  • [download id=”2″] (This is a modified phpagi to work with Asterisk 1.8.x)
  • [download id=”3″] (This is the AGI script called from the dialplan).

Installation and configuration:

  • Install PHP and the PHP-SOAP part: “yum install php-soap php” for Fedora based systems or “apt-get install php-soap php” for Debian based systems.
  • Download the [download id=”2″] archive and the [download id=”3″] script into the agi-bin directory of Asterisk. In a default Asterisk installation this is /var/lib/asterisk/agi-bin. Or check the line containing “astagidir” in /etc/asterisk/asterisk.conf.
  • Unpack the two archive files:

#> cd /var/lib/asterisk/agi-bin/
#> tar -zxvpf phpagi_2.0_miv1.tar.gz
#>tar -zxvpf check_otrs_calendar.php.tar.gz

  • Make the AGI script executable:

#> chmod guo+x check_otrs_calendar.php

  • Edit the “check_otrs_calendar.php” script and modify the following lines:

$user = “my_soap_user”;
$pass = “my_soap_password”;
$url = “http://otrserver/otrs/rpc.pl”;

  • Insert the username and password you entered in the SOAP::User and SOAP::Password fields of OTRS (see above).
  • Modify also the server name in the url variable to point to your OTRS server.
  • Now add something as the following to any part in your dialplan to check for vacation or holiday dates in OTRS and react to it in your dialplan:

same => n,Agi(check_otrs_calendar.php,x)
same => n,GotoIf($[ “${VACATIONDAY}” = “” ]?noholiday:holiday)
same => n(noholiday),NoOp(No vacation)
; Add your dialplan line here when no vacation or holiday is active.
same => n,Hangup()
same => n(holiday),NoOp(Vacation)
; Add your dialplan lines here when it is a holiday or vacation.
same => n,Playback(officeisclosed)
same => n,Hangup()

  • Change the x in the first line with the Agi application to the Calendar number you used in OTRS. For example Agi(check_otrs_calendar.php,2) for the second calendar as shown before in the OTRS Calendar screenshot.
  • Start the Asterisk CLI and reload your dialplan:

#> asterisk -rvvvvv
asterisk@CLI> dialplan reload

Now you are ready and Asterisk will choose in the dialplan which way to go on a holiday or vacation.

This entry was posted in Asterisk, OTRS, PHP, phpagi, SOAP. Bookmark the permalink.

Leave a Reply

Your email address will not be published.