[asterisk-users] Asterisk "virtual hosting"

Steve Edwards asterisk.org at sedwards.com
Sun May 17 01:31:51 CDT 2015


On Sun, 17 May 2015, martin f krafft wrote:

> also sprach Steve Edwards <asterisk.org at sedwards.com> [2015-05-16 23:22 
> +0200]:

>> I use a preprocessor 
>> (http://software.hixie.ch/utilities/unix/preprocessor/) to tailor 
>> dialplans and configuration files to each host based on the client (or 
>> project) and the hostname.

On Sun, 17 May 2015, martin f krafft wrote:

> Yeah sure, templating works, but it introduces a layer of complexity 
> that can make debugging hard(er).

While preprocessing could be called 'templating,' this may be confusing 
because Asterisk already as a configuration file feature called 
'templates.'

> I just had the following alternative ideas.
>
>  - when #include parses a file, prefix all stanzas found therein
>    with text derived from the path, e.g.
>
>      * #include foo/extensions.conf  →  "foo-"
>      * #include bar.conf             →  "bar-"
>      * #include foo/bar/moo.conf     →  "foo-bar-moo-"
>
>  - if e.g. a context includes another context using a path
>    separator, then the [common] context is looked up in a different
>    location:
>
>      * include foo/common            → "foo/extensions.conf"
>      * include foo/bar/common        → "foo/bar/extensions.conf:foo/bar.conf"
>
>    The same logic could be applied e.g. in the arguments of the
>    Dial() application or local channels or registry instructions in
>    sip.conf.
>
> The first is probably easier to implement, while the second is clearer 
> to the user.

And you find preprocessing/templating complex?

> Is this something to consider?

I don't think so, primarily because it is specific to your problem. The 
audience is too small.

Let's take a closer look at preprocessing using the preprocessor I 
referenced above to make sure I understand your needs.

If we had extensions.conf.pre containing:

 	#filter substitution

 	#define	PREFIX	a
 	#include	generic.conf.pre

 	#define	PREFIX	b
 	#include	generic.conf.pre

 	# (end of extensions.conf.pre)

(Note that '#include' is seen by the preprocessor, not by Asterisk's 
configuration file parsing code.)

and generic.conf.pre containing:

 	[@PREFIX at -long-distance]
 		exten = s,1,			verbose(1,[${EXTEN}@${CONTEXT}!${ANI}])
 	#if	PREFIX==a
 		same = n,			verbose(a specific code)
 	#endif
 		same = n,			hangup()

 	# (end of common.conf.pre)

we could process these files with a command like:

 	./preprocessor.pl extensions.conf.pre >/etc/asterisk/extensions.conf

which would create extensions.conf containing:

 	[a-long-distance]
 		exten = s,1,			verbose(1,[${EXTEN}@${CONTEXT}!${ANI}])
 		same = n,			verbose(a specific code)
 		same = n,			hangup()

 	[b-long-distance]
 		exten = s,1,			verbose(1,[${EXTEN}@${CONTEXT}!${ANI}])
 		same = n,			hangup()

This lets you write generic contexts that will be prefixed as well as 
'tailor' code specific to the value of the prefix. Isn't this what you're 
looking to accomplish?

Also note, the 'real' extensions.conf contains no additional complexity so 
it is as easy to understand and maintain as you want it to be.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000


More information about the asterisk-users mailing list