Starting with version 3.0, OpenSIPS will offer script writers full support for piping the opensips.cfg file (including any other files imported by it) to a generic preprocessing command.
What’s So New About It?
Until now, the core problem of templating opensips.cfg was solved using fully externalized solutions such as GNU m4, which grabbed an input configuration file (e.g. opensips.cfg.m4) and generated a second file: opensips.cfg. There were two major inconveniences with this approach:
- the opensips.cfg error log lines do not have a 1:1 correspondence with the opensips.cfg.m4 file. For example, OpenSIPS may report an opensips.cfg error at line 432, which actually corresponds to line 391 in opensips.cfg.m4 due to some foreach templating statement which generated additional lines of code
- you have to pay extra attention when working with two files: opensips.cfg.m4 and opensips.cfg. Sometimes, users may mistakenly perform configuration changes on the opensips.cfg file then restart their opensips instance and thus lose all the work, since opensips.cfg gets re-generated.
The newly added preprocessor support solves both above issues, by enabling OpenSIPS script developers to always work with a single file, be it templated or not. Additionally, the built-in support will also accurately track any errors found in the generated file back to their exact line number in the template file, so you know exactly where that error came from. If you want to play around with it, you may checkout the development branch and give it a go!
Do I Need Templating?
For small systems made up of only a handful of OpenSIPS instances, simply editing them separately and getting the work done quickly is a solid option. However, templating the opensips.cfg becomes a necessity when managing systems comprising large numbers of instances. For example, imagine you have 500 OpenSIPS instances running in the cloud, each with unique private/public IP addresses and unique DB connector URLs. It immediately becomes obvious that we will have to work with a templating system on top of the config file.
How Does It Work?
There are three steps in setting it up:
- decide on your templating language (m4? Jinja2? ERB?)
- prepare a command line with any other options the templating engine might need — it may even be a bash script wrapper. The command must receive its input via standard input and it must output the preprocessed results to standard output.
- pass the above-mentioned preprocessor command as argument to the “-p” option of the opensips binary.
If you are interested in some example templated files using the m4 / Jinja2 / ERB fantastic three, please head over to the documentation page.
And for those of you interested in learning more about OpenSIPS, sharing real-life deployment stories or just smoking VoIP in general, you could get some great value by joining us in Amsterdam for the 2019 OpenSIPS Summit!