Documentation

Documentation.Templating-Config-Files-3-3 History

Hide minor edits - Show changes to output

November 23, 2021, at 03:04 PM by liviu -
Changed line 164 from:
m4 env.m4 - | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
to:
m4 env.m4 - | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg)
July 16, 2020, at 02:51 PM by liviu -
Changed line 19 from:
OpenSIPS 3.3+ releases offer script writers full support for piping the ''opensips.cfg'' file (including any other files imported by it) to a generic preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.0+ releases offer script writers full support for piping the ''opensips.cfg'' file (including any other files imported by it) to a generic preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
July 12, 2019, at 09:26 PM by liviu -
Changed line 159 from:
OpenSIPS script developers may debug the output of the preprocessor during development by writing a wrapper script over the preprocessing command such as:
to:
Since the output of the preprocessor is never written to any file and is just consumed by OpenSIPS on each run, script developers may still visualize and debug the generated file during development by using a wrapper script over the preprocessing command such as the following:
July 12, 2019, at 09:23 PM by liviu -
Changed lines 113-114 from:
[[https://ruby-doc.org/stdlib-2.6.1/libdoc/erb/rdoc/ERB.html|Embedded Ruby (ERB)]] provides an easy to use but powerful templating system for Ruby. Using ERB, actual Ruby code can be added to any plain text document for the purposes of generating document information details and/or flow control. Let's see how it integrates with ''opensips.cfg''!
to:
[[https://ruby-doc.org/stdlib-2.6.1/libdoc/erb/rdoc/ERB.html|Embedded Ruby (ERB)]] provides an easy to use, powerful templating system for Ruby. Using ERB, actual Ruby code can be added to any plain text document for the purposes of generating document information details and/or flow control. Let's see how it integrates with ''opensips.cfg''!
Changed line 164 from:
m4 env.m4 | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
to:
m4 env.m4 - | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
April 19, 2019, at 08:53 AM by liviu -
Changed line 12 from:
||[[Configure-File-3-3|Prev]] || [[Script-Format-3-3|Next]]||
to:
||[[Configure-File-3-3|Prev]] || [[Script-Syntax-3-3|Next]]||
March 18, 2019, at 10:59 AM by liviu -
Changed line 25 from:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and mirrors it to standard output. From here, it's just a matter of choosing a templating language which fits the deployment requirements. Some basic substitutions can be done using, for example, ''sed'':
to:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via '''standard input''' and mirrors it to '''standard output'''. From here, it's just a matter of choosing a templating language which fits the deployment requirements. Some basic substitutions can be done using, for example, ''sed'':
March 06, 2019, at 10:09 PM by liviu -
Changed line 117 from:
First, install the '''ruby-ejs''' package: '''"apt install ruby-ejs"'''. Next, prepare the files:
to:
First, install the ERB package (for Debian/Ubuntu: '''"apt install ruby-ejs"'''). Next, prepare the files:
March 06, 2019, at 07:05 PM by liviu -
Changed line 67 from:
\\\
to:
\\
March 06, 2019, at 07:05 PM by liviu -
Added lines 67-68:
\\\
Added lines 114-115:

\\
March 06, 2019, at 07:04 PM by liviu -
Changed line 60 from:
opensips -f opensips.cfg.m4 -p "m4 env.m4"
to:
opensips -f opensips.cfg.m4 -p "m4 env.m4 -"
Added lines 67-70:
First, install the '''jinja2''' Python module with: '''"pip install jinja2"'''. Next, prepare the files:

\\
Added lines 112-115:

First, install the '''ruby-ejs''' package: '''"apt install ruby-ejs"'''. Next, prepare the files:

\\
March 06, 2019, at 10:52 AM by liviu -
Changed line 166 from:
A similar approach can be used for any other preprocessor.
to:
The same technique can be used for any other preprocessor.
March 06, 2019, at 10:49 AM by liviu -
Changed line 33 from:
Below are some examples of using more advanced templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements which enable/disable features, for loops over multiple listening interfaces, etc.).
to:
Below are some examples of using more advanced templating languages on top of opensips.cfg, for cases where the target environment requires complex decision-making (if statements which enable/disable features, for loops over multiple listening interfaces, etc.).
March 05, 2019, at 06:45 PM by liviu -
Changed line 65 from:
[[http://jinja.pocoo.org/docs/2.10|Jinja2]] is a modern templating language with a rich feature set, including textual replacement, if statements, for loops, a plethora of filters, file includes, and the list goes on! Unlike ''m4'', the Jinja2 templating language does not currently have a standalone binary, rather it is provided via a Python package. Here is a way of integrating it with ''opensips.cfg'':
to:
[[http://jinja.pocoo.org/docs/2.10|Jinja2]] is a modern templating language with a rich feature set, including textual replacement, if statements, for loops, a plethora of filters, file includes, and the list goes on! Unlike ''m4'', Jinja2 does not currently have a standalone binary, rather it is provided via a Python package. Here is a way of integrating it with ''opensips.cfg'':
March 05, 2019, at 06:44 PM by liviu -
Added lines 163-164:

\\
March 05, 2019, at 06:43 PM by liviu -
Changed lines 162-164 from:
@]
to:
@]

A similar approach can be used for any other preprocessor.
March 05, 2019, at 06:40 PM by liviu -
Added lines 44-45:

\\
March 05, 2019, at 06:39 PM by liviu -
Changed lines 43-44 from:
%gray%'''opensips-3.3.cfg.m4'''
to:
%gray%'''opensips.cfg.m4'''
Changed lines 69-70 from:
%gray%'''opensips-3.3.cfg.j2'''
to:
%gray%'''opensips.cfg.j2'''
Changed line 111 from:
%gray%'''opensips-3.3.cfg.erb'''
to:
%gray%'''opensips.cfg.erb'''
March 05, 2019, at 06:34 PM by liviu -
Changed line 100 from:
opensips -f opensips.cfg.m4 -p "python opensips-preproc.py"
to:
opensips -f opensips.cfg.j2 -p "python opensips-preproc.py"
Changed line 139 from:
opensips -f opensips.cfg.m4 -p "ruby opensips-preproc.rb"
to:
opensips -f opensips.cfg.erb -p "ruby opensips-preproc.rb"
March 01, 2019, at 07:43 PM by liviu -
Changed line 54 from:
... and we start OpenSIPS using the below command, which will pipe ''opensips.cfg.m4'' to ''m4'''s standard input, and read from its standard output:
to:
... and we start OpenSIPS using the below command, which will pipe ''opensips.cfg.m4'' to ''m4'''s standard input, and then read the resulting file from its standard output:
March 01, 2019, at 07:43 PM by liviu -
Changed line 54 from:
... and we start OpenSIPS using:
to:
... and we start OpenSIPS using the below command, which will pipe ''opensips.cfg.m4'' to ''m4'''s standard input, and read from its standard output:
March 01, 2019, at 07:41 PM by liviu -
Added lines 2-3:
This page has been visited {$PageCount} times.
March 01, 2019, at 05:35 PM by liviu -
Changed line 35 from:
[[https://www.gnu.org/software/m4/|GNU m4]] is a simplistic preprocessor with a mild learning curve, equipped with textual replacement, if statements and file includes among the most notable features. Here is an example integration with ''opensips.cfg'':
to:
[[https://www.gnu.org/software/m4/|GNU m4]] is a simplistic preprocessor with a mild learning curve, equipped with textual substitution, if statements and file includes among the most notable features. Here is an example integration with ''opensips.cfg'':
March 01, 2019, at 05:34 PM by liviu -
Changed line 31 from:
Below are some examples of using more complex templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements which enable/disable features, for loops over multiple listening interfaces, etc.).
to:
Below are some examples of using more advanced templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements which enable/disable features, for loops over multiple listening interfaces, etc.).
March 01, 2019, at 05:19 PM by liviu -
Added lines 102-139:

[[https://ruby-doc.org/stdlib-2.6.1/libdoc/erb/rdoc/ERB.html|Embedded Ruby (ERB)]] provides an easy to use but powerful templating system for Ruby. Using ERB, actual Ruby code can be added to any plain text document for the purposes of generating document information details and/or flow control. Let's see how it integrates with ''opensips.cfg''!

[@
listen = udp:<%= private_ip %>:5060
loadmodule "proto_udp.so"
@]
%gray%'''opensips-3.3.cfg.erb'''

\\

[@
#!/usr/bin/env ruby
require 'erb'
require './env.rb'

template = ERB.new($stdin.read, nil, '-')
$stdout.write template.result($erb_context)
@]
%gray%'''~/src/opensips-preproc.rb'''

\\

[@
$erb_context = binding
private_ip = '127.0.0.1'
@]
%gray%'''env.rb'''

\\

... and OpenSIPS is now started using:


[@
opensips -f opensips.cfg.m4 -p "ruby opensips-preproc.rb"
@]
March 01, 2019, at 05:14 PM by liviu -
Changed lines 35-36 from:
[[https://www.gnu.org/software/m4/|GNU m4]] is a quick-and-easy-to-use preprocessor, with textual replacement, if statement and file inclusion support among the most notable ones. Here is an example integration with ''opensips.cfg'':
to:
[[https://www.gnu.org/software/m4/|GNU m4]] is a simplistic preprocessor with a mild learning curve, equipped with textual replacement, if statements and file includes among the most notable features. Here is an example integration with ''opensips.cfg'':
Added lines 60-99:

[[http://jinja.pocoo.org/docs/2.10|Jinja2]] is a modern templating language with a rich feature set, including textual replacement, if statements, for loops, a plethora of filters, file includes, and the list goes on! Unlike ''m4'', the Jinja2 templating language does not currently have a standalone binary, rather it is provided via a Python package. Here is a way of integrating it with ''opensips.cfg'':

[@
listen = udp:{{ private_ip }}:5060
loadmodule "proto_udp.so"
@]
%gray%'''opensips-3.3.cfg.j2'''

\\

[@
import sys
import json
from jinja2 import Template

t = Template("".join(sys.stdin.readlines()))

with open('env.json') as f:
print(t.render(json.load(f)))
@]
%gray%'''opensips-preproc.py'''

\\

[@
{
"private_ip": "127.0.0.1"
}
@]
%gray%'''env.json'''

\\

... and we start OpenSIPS using:


[@
opensips -f opensips.cfg.m4 -p "python opensips-preproc.py"
@]
March 01, 2019, at 05:04 PM by liviu -
Changed lines 74-76 from:
and we start OpenSIPS using:
to:
\\

... and now we start OpenSIPS using:
March 01, 2019, at 05:04 PM by liviu -
Changed lines 70-77 from:
m4 | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
to:
m4 env.m4 | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
@]
%gray%'''~/src/preprocessor.sh'''

and we start OpenSIPS using:

[@
opensips -f opensips.cfg.m4 -p ~/src/preprocessor.sh
March 01, 2019, at 05:02 PM by liviu -
Changed line 20 from:
opensips -f opensips.cfg.m4 -p /bin/cat
to:
opensips -f opensips.cfg -p /bin/cat
Changed line 26 from:
opensips -f opensips.cfg.m4 -p "/bin/sed s/PRIVATE_IP/10.0.0.10/g"
to:
opensips -f opensips.cfg -p "/bin/sed s/PRIVATE_IP/10.0.0.10/g"
Added lines 34-57:

[[https://www.gnu.org/software/m4/|GNU m4]] is a quick-and-easy-to-use preprocessor, with textual replacement, if statement and file inclusion support among the most notable ones. Here is an example integration with ''opensips.cfg'':

[@
listen = udp:PRIVATE_IP:5060
loadmodule "proto_udp.so"
@]
%gray%'''opensips-3.3.cfg.m4'''

[@
divert(-1)
define(`PRIVATE_IP', `127.0.0.1')
divert(0)dnl
@]
%gray%'''env.m4'''

\\

... and we start OpenSIPS using:


[@
opensips -f opensips.cfg.m4 -p "m4 env.m4"
@]
March 01, 2019, at 04:53 PM by liviu -
Changed line 17 from:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through a generic preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.3+ releases offer script writers full support for piping the ''opensips.cfg'' file (including any other files imported by it) to a generic preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
March 01, 2019, at 04:53 PM by liviu -
Changed line 17 from:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through an external preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through a generic preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
March 01, 2019, at 04:51 PM by liviu -
Changed line 31 from:
Below are some examples of using more complex templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements, for loops, etc.).
to:
Below are some examples of using more complex templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements which enable/disable features, for loops over multiple listening interfaces, etc.).
March 01, 2019, at 04:50 PM by liviu -
Added lines 29-30:
!! Common Templating Languages + Examples
Deleted lines 31-32:

!! Common Templating Languages + Examples
March 01, 2019, at 04:49 PM by liviu -
Changed line 23 from:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and mirrors it to standard output. From here, it's just a matter of choosing the templating language. Some basic substitutions can be done using, for example, ''sed'':
to:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and mirrors it to standard output. From here, it's just a matter of choosing a templating language which fits the deployment requirements. Some basic substitutions can be done using, for example, ''sed'':
March 01, 2019, at 04:49 PM by liviu -
Changed line 23 from:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and prints it to standard output. From here, it's just a matter of choosing the templating language. Some basic substitutions can be done using, for example, ''sed'':
to:
... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and mirrors it to standard output. From here, it's just a matter of choosing the templating language. Some basic substitutions can be done using, for example, ''sed'':
March 01, 2019, at 04:48 PM by liviu -
Changed line 17 from:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through an external preprocessing command. This may be useful in scenarios where the ''opensips.cfg'' file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through an external preprocessing command. This may be useful in scenarios where ''opensips.cfg'' must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
March 01, 2019, at 04:48 PM by liviu -
Changed line 17 from:
OpenSIPS 3.3+ releases offer script writers the possibility to push the opensips.cfg file (including any other files it imports) through an external preprocessing command. This may be useful in scenarios where the opensips.cfg file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.3+ releases offer script writers the possibility to push the ''opensips.cfg'' file (including any other files imported by it) through an external preprocessing command. This may be useful in scenarios where the ''opensips.cfg'' file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
March 01, 2019, at 04:47 PM by liviu -
Changed line 17 from:
OpenSIPS 3.3+ releases offer the possibility to push the opensips.cfg file (including any other files it imports) through an external preprocessing command. This may be useful in scenarios where the opensips.cfg file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
to:
OpenSIPS 3.3+ releases offer script writers the possibility to push the opensips.cfg file (including any other files it imports) through an external preprocessing command. This may be useful in scenarios where the opensips.cfg file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:
March 01, 2019, at 04:47 PM by liviu -
Changed line 46 from:
m4 | tee >(grep -v __OSSPP_ >/tmp/out)
to:
m4 | tee >(grep -v __OSSPP_ >/tmp/opensips.cfg.preprocessed)
March 01, 2019, at 04:46 PM by liviu -
Changed line 46 from:
m4 | tee >(grep -v ^__OSSPP_ >/tmp/out)
to:
m4 | tee >(grep -v __OSSPP_ >/tmp/out)
March 01, 2019, at 04:46 PM by liviu -
Added lines 14-47:

!! Generic Preprocessing Support

OpenSIPS 3.3+ releases offer the possibility to push the opensips.cfg file (including any other files it imports) through an external preprocessing command. This may be useful in scenarios where the opensips.cfg file must be parameterized (e.g. listening interfaces, ports, DB connectors, etc.) and deployed to multiple servers, in an automated fashion. The system administrator may achieve this using the "-p <cmdline>" (preprocessor) option. For example:

[@
opensips -f opensips.cfg.m4 -p /bin/cat
@]

... is a basic use of the "-p" option, by supplying it with an "echo" preprocessor that receives input via standard input and prints it to standard output. From here, it's just a matter of choosing the templating language. Some basic substitutions can be done using, for example, ''sed'':

[@
opensips -f opensips.cfg.m4 -p "/bin/sed s/PRIVATE_IP/10.0.0.10/g"
@]

Below are some examples of using more complex templating languages on top of opensips.cfg, for cases where the target environment requires more complex decision-making (if statements, for loops, etc.).

!! Common Templating Languages + Examples

!!! GNU m4

!!! Jinja2

!!! Embedded Ruby

!! Debugging Preprocessor Output

OpenSIPS script developers may debug the output of the preprocessor during development by writing a wrapper script over the preprocessing command such as:

[@
#!/bin/bash

m4 | tee >(grep -v ^__OSSPP_ >/tmp/out)
@]
March 01, 2019, at 02:26 PM by liviu -
Added lines 1-13:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-3-3|Manual 3.3]] -> Templating opensips.cfg Files
(:title Templating opensips.cfg Files - 3.3:)
----
(:allVersions Templating-Config-Files 3.3:)

\\

|| %color=#185662%[+'''Templating opensips.cfg Files v3.3 '''+]%% ||

||[[Configure-File-3-3|Prev]] || [[Script-Format-3-3|Next]]||
----

(:toc-float Table of Content:)

Page last modified on November 23, 2021, at 03:04 PM