segunda-feira, dezembro 20, 2010

Howto: Asterisk PBX Holidays on your dial plan

Admin World | Howto: Asterisk PBX Greek National Holidays on your dial plan: "Howto: Asterisk PBX Greek National Holidays on your dial plan
Posted by admin on 09/04/2010 Leave a comment (2) Go to comments

Asterisk Logo

Well For some time now i work with asterisk servers and i try to learn as much as i can with a lot of reading and help from other IT friends.

This article is going to show how to tell asterisk which days of the year are holidays for Greece. It’s quite simple as principle but none of the greek IT community posted something similar to help the newbies, at least what i saw through Google. The most compicated part is where you must define the moving calendar holidays like easter and Clear Monday (??) :-) .

This scripting can also work with Other contries if you alter the dates on the astdb’s dates…

This example imports moving holidays to 2020 and standard calendar holidays for end of time….!

First of all create a file called what-ever-you-like.sh and imput the following lines:
#!/bin/sh
asterisk -rx 'database deltree holidays'
asterisk -rx 'database put holidays 20100215 1'
asterisk -rx 'database put holidays 20100402 1'
asterisk -rx 'database put holidays 20100405 1'
asterisk -rx 'database put holidays 20100524 1'
asterisk -rx 'database put holidays 20110307 1'
asterisk -rx 'database put holidays 20110422 1'
asterisk -rx 'database put holidays 20110425 1'
asterisk -rx 'database put holidays 20110613 1'
asterisk -rx 'database put holidays 20120227 1'
asterisk -rx 'database put holidays 20120413 1'
asterisk -rx 'database put holidays 20120416 1'
asterisk -rx 'database put holidays 20120604 1'
asterisk -rx 'database put holidays 20130318 1'
asterisk -rx 'database put holidays 20130503 1'
asterisk -rx 'database put holidays 20130506 1'
asterisk -rx 'database put holidays 20130624 1'
asterisk -rx 'database put holidays 20140303 1'
asterisk -rx 'database put holidays 20140418 1'
asterisk -rx 'database put holidays 20140421 1'
asterisk -rx 'database put holidays 20140609 1'
asterisk -rx 'database put holidays 20150223 1'
asterisk -rx 'database put holidays 20150410 1'
asterisk -rx 'database put holidays 20150413 1'
asterisk -rx 'database put holidays 20150601 1'
asterisk -rx 'database put holidays 20160314 1'
asterisk -rx 'database put holidays 20160429 1'
asterisk -rx 'database put holidays 20160502 1'
asterisk -rx 'database put holidays 20160620 1'
asterisk -rx 'database put holidays 20170227 1'
asterisk -rx 'database put holidays 20170414 1'
asterisk -rx 'database put holidays 20170417 1'
asterisk -rx 'database put holidays 20170605 1'
asterisk -rx 'database put holidays 20180219 1'
asterisk -rx 'database put holidays 20180406 1'
asterisk -rx 'database put holidays 20180409 1'
asterisk -rx 'database put holidays 20180528 1'
asterisk -rx 'database put holidays 20190311 1'
asterisk -rx 'database put holidays 20190426 1'
asterisk -rx 'database put holidays 20190429 1'
asterisk -rx 'database put holidays 20190617 1'
asterisk -rx 'database put holidays 20200302 1'
asterisk -rx 'database put holidays 20200417 1'
asterisk -rx 'database put holidays 20200420 1'
asterisk -rx 'database put holidays 20200608 1'

As you can see the first line removes all entries of the table holidays and then adds the holidays you want in the form %Y%m%d.

Now the line that calls astdb and checks if there is any time record matching the current time ( This is for 1.4) is:
exten => s,n,Set(HOLIDAYS=${DB_EXISTS(holidays/${STRFTIME(${EPOCH},GMT+2,%Y%m%d)})})
This line must be placed in a context that will run this command before starting doing the routing of the call. This command sets the ${HOLIDAYS} variable to 1 if the current date matches the records in the database, and to 0 if not.

Now there are several ways to route your call depending on the ${HOLIDAYS} variable value but i will show the most common and easy for me.

GotoIf Method:
exten => s,n,GotoIf($[${HOLIDAYS}>0]?,,)
This line says that if ${HOLIDAYS}>0 ie 1, then go to the context, context-name,priority and continiue from there. You could also to this:
exten => s,n,GotoIf($[${HOLIDAYS}>0]?,,: ,,)
which says that if it’s true to this else to that.

Now For a complete holidays definition i have set the following rules in the begining of the context that incoming calls are routed.
[context-for-incoming-calls]
exten => s,1,answer
exten => s,n,Set(HOLIDAYS=${DB_EXISTS(holidays/${STRFTIME(${EPOCH},GMT+2,%Y%m%d)})})
; Holidays
exten => s,n,GotoIfTime(*|*|1|jan? s,n,GotoIfTime(*|*|6|jan?context-ext-closed,closed,1)
exten => s,n,GotoIfTime(*|*|25|mar?context-ext-closed,closed,1)
exten => s,n,GotoIfTime(*|*|1|may?context-ext-closed,closed,1)
exten => s,n,GotoIfTime(*|*|15|aug?context-ext-closed,closed,1)
exten => s,n,GotoIfTime(*|*|28|oct?context-ext-closed,closed,1)
exten => s,n,GotoIf($[${HOLIDAYS}>0]?context-ext-closed,closed,1)
exten => s,n,GotoIfTime(*|*|25-26|dec?context-ext-closed,closed,1)
; Working Days
exten => s,n,GotoIfTime(09:00-17:00|mon-fri|*|*?context-ext-open,open,1)
exten => s,n,Goto(biznet-ext-closed,closed,1)
I think is quite straight forward if you look the dates on the definitions. These rules redirect the call to a context-ext-closed if the dates match, which handles the call from there.

I hope this article is usefull for somebody, and i am here to answer any question.

Enjoy!

- Sent using Google Toolbar"

Nenhum comentário: