No, your PBX server is not taking a couple of days off. ![]()
This is an Asterisk macro that lets you know if today is a holiday, and jump to different places on your dialplan accordingly.
Configuring every holiday on the dialplan is a PITA. Fixed holidays that take place every year on the same day, like New Year or Christmas, are easy to set up, but moving holidays like Easter are more complicated. Moreover, programming each of these days on the dialplan, whether they’re fixed or moving, means an extra line per day.
This macro takes a dynamic approach to the problem, storing the holidays’ dates on astdb and checking there if today is a holiday. Of course, we will have to populate this DB. The format is as follows:
HOLIDAYS <MMDD> <holiday>
HOLIDAYS <YYYYMMDD> <holiday>
where YYYY, MM and DD are the year, month and day, and “holiday” a description for that particular day. This description is shown on the logs via NoOp, but it wouldn’t be difficult to extend the macro and play a different MP3 file each day to let the caller know that this particular day is a local holiday (for example).
If the year is omited, it means that day is a fixed holiday, same month and day every year. For moving holidays you must use the YYYYMMDD format, like in:
> database put HOLIDAYS 0101 "New Year" > database put HOLIDAYS 20070406 "Easter"
The macro takes SIX parameters defining the destination (context, extension, order) if the day IS a holiday, or if it ISN’T:
exten => s,n,Macro(if-holiday,voicemail,s,1,queue,100,1)
The macro’s code:
[macro-if-holiday]
exten => s,1,NoOp(Checking if today is a holiday)
exten => s,n,Set(YEAR=${STRFTIME(${EPOCH},,%Y)})
exten => s,n,Set(MONTHDAY=${STRFTIME(${EPOCH},,%m%d)})
exten => s,n,NoOp(Today's date is ${YEAR}${MONTHDAY})
exten => s,n,GotoIf(${DB_EXISTS(HOLIDAYS/${MONTHDAY})}?s-FIXED,1)
exten => s,n,GotoIf(${DB_EXISTS(HOLIDAYS/${YEAR}${MONTHDAY})}?s-MOVING,1)
exten => s,n,NoOp(* Today is NOT a holiday)
exten => s,n,Goto(${ARG4},${ARG5},${ARG6})
exten => s-FIXED,1,NoOp(* Today is a FIXED holiday: ${MONTHDAY} ${DB(HOLIDAYS/${MONTHDAY})})
exten => s-FIXED,n,Goto(${ARG1},${ARG2},${ARG3})
exten => s-MOVING,1,NoOp(* Today is a MOVING holiday: ${YEAR}${MONTHDAY} ${DB(HOLIDAYS/${YEAR}${MONTHDAY})})
exten => s-MOVING,n,Goto(${ARG1},${ARG2},${ARG3})
Seria excelente que publicaras un poco mas extenso la forma en que lo has implementado en tu PBX, una especie de MINI HowTo seria excelente, donde expliques como has usado la DB que tipo de DB has usado y si has cargado los datos de los festivos en esa DB en particular es decir como lo has hecho realmente cuales han sido los pasos que has seguido y dime si te funciona perfectamente o si tiene algun porcentaje de error!
Ya no trabajo en la empresa para la que hice esto ni he tocado Asterisk desde entonces… de todas formas:
- no necesitas ninguna BD externa, AstDB viene “de serie” con Asterisk.
- se cargan como pone en el artículo: te logas en la consola de asterisk y añades los días con DIA MES si son fijos (cae el mismo día todos los años) o DIA MES AÑO si no.
> database put HOLIDAYS 0101 “Noche Vieja”
> database put HOLIDAYS 20070406 “Viernes Santo”
- nunca me dio un error, el código es bastante simple y depende de los datos que introduzcas…