OpenSIPS: monitoring with Zabbix: HTTP Agent, JSONPath

March 24th, 2022

This guide will help you to understand how OpenSIPS can be monitored with Zabbix, sharing its statistic data via HTTP interface in JSON format. This article assumes using OpenSIPS 3.2 and Zabbix 6.

Enable embedded HTTP server and HTTP support for Management Interface in your OpenSIPS:

loadmodule "httpd.so"
modparam("httpd", "ip", "192.168.88.244")
modparam("httpd", "port", 8888)

# :8888/mi
loadmodule "mi_http.so"
modparam("mi_http", "root", "mi")

Now we may try to send a JSON-RPC OpenSIPS MI command from the command-line, using curl (official example at the very bottom of the page):

/usr/bin/curl -X POST 192.168.88.244:8888/mi -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": "1", "method": "uptime"}'

The official documentation does not have other more complicated examples, e.g. “get_statistics sl:”, that’s why I decided to write this article, maybe it’s more about JSON, JSONPath and working with all this in Zabbix.

As an example, we’ll get stateless replier module statistics, like shown by invoking a CLI command “opensips-cli -x mi get_statistics sl:” .

/usr/bin/curl -X POST 192.168.88.244:8888/mi -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": "1", "method": "get_statistics", "params": {"statistics": ["sl:"]}}'

I’ll also duplicate the command with a screenshot (to be sure that you see it in a right way, because markup may cut some special characters):

Tip: if you need statistics from several groups, for example several modules (not only SL), the request will be as follows:

/usr/bin/curl -X POST 192.168.88.244:8888/mi -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": "1", "method": "get_statistics", "params": {"statistics": ["sl:", "tm:"]}}'

OpenSIPS will answer and you’ll see SL module statistics after sending this request with CURL.

But the responce is a one-liner, so we need to convert this one line to JSON format and then to create a JSONPath, to be able to extract the value we need.

Let’s monitor not all SL module statistics received from OpenSIPS, but the number of 2xx replies only.

I use https://www.jsonformatter.io/ for JSON formatting and https://jsonpath.com/ for creating JSONPath. After formatting and specifying JSONPath we can configure Zabbix.


Now it’s time to add items to your OpenSIPS host in Zabbix. Item parameters:

Type: HTTP Agent
Type of information: Numeric (unsigned)
Request type: POST
Request body type: JSON data
Request body: {"jsonrpc": "2.0", "id": "1", "method": "get_statistics", "params": {"statistics": ["sl:"]}}
Retrieve mode: Body
Convert to JSON (enabled)

Screenshots as usual:


Item Preprocessing parameters:

1st step - JSONPath
Parameters: $.body.result.["sl:2xx_replies"]
Type of information: Numeric (unsigned)

Screen – item Preprocessing and successful testing:


Now we add a graph with this item (I hope you know how to create graphs in Zabbix) and it’s time to test. I will generate thousands of OPTIONS requests to my OpenSIPS with the sipp tool (I also recommend this sipp cheatsheet).

Download OPTIONS.xml scenario file, and generate 10000 OPTIONS requests with call rate of 10 (I assume that your OpenSIPS, like mine, answers “200 OK”):

sipp 192.168.88.244 -sf OPTIONS.xml -l 10000 -m 10000 -r 10

Finally, here is the graph showing your OpenSIPS SL module 2xx processed replies statistics:

This is how you can monitor OpenSIPS with Zabbix using JSON.

Have fun!

Asterisk: removing all queue dynamic members

March 20th, 2022

Users add themselves as queue members by dialing some short number (AddQueueMember dialplan app is used). The queue may contain several dynamic members.

The task is to remove all queue members by dialing some number, no matter how much members are in this queue. Queue name is ‘superQueue’ (example for AEL, Asterisk 13):

// remove all dynamic queue members
0000 =>
{
    NoOp(superQueue member  list: ${QUEUE_MEMBER_LIST(superQueue)});

    // count members of a queue
    count=${QUEUE_MEMBER(superQueue,count)};

    // and remove all, one by one
    while (${count} >= 1) {
        Set(QMLsuperQueue=${QUEUE_MEMBER_LIST(superQueue)});
        Set(kicked=${CUT(QMLsuperQueue,\,,1)});
        Log(NOTICE, removing dynamic member: ${kicked});
        RemoveQueueMember(superQueue,${kicked});
        count=${count}-1;
    }

    Hangup();
};

systemd: cleaning journal service logs

March 1st, 2022
voip ~ # journalctl --disk-usage
Archived and active journals take up 4.2G on disk.
voip ~ # du -sh /var/log/journal/
4,3G /var/log/journal/

Let’s leave 500M of logs only:

voip ~ # journalctl --vacuum-size=500M

Vacuuming done, freed 3.5G of archived journals on disk.

Check once again:

voip ~ # journalctl --disk-usage
Archived and active journals take up 744.2M on disk.
voip ~ #
voip ~ # du -sh /var/log/journal/
745M /var/log/journal/

rsyslog: slicing & dicing application log files

December 1st, 2021

Let’s slice log file of an application to store separate log files during each hour and keep them in separate directories accroding to the date.


Example for RTPEngine:

  1. create file /etc/rsyslog.d/10-rtpengine.conf

2. add to it the following settings:

template(
    name="rtpengine-tmpl" type="string"
    string="/var/log/rtpengine/%$NOW%/rtpengine-%HOSTNAME%-%$YEAR%%$MONTH%%$DAY%.%$HOUR%.log"
)

template(
    name="rtpengine-fmt" type="string"
    string="%timegenerated% %HOSTNAME% %syslogtag% %msg:::drop-last-lf%\n"
)

if $app-name == ["rtpengine"] then {
    action(type="omfile" dynaFile="rtpengine-tmpl" template="rtpengine-fmt")
    stop
}

3. restart rsyslog.

4. profit

screenshot of a config file
the result

Example for OpenSIPS:

  1. create /etc/rsyslog.d/20-opensips.conf
  2. add to it:
# :msg, startswith, "ACC:" /var/log/opensips/acc.log
# & stop
#
# :syslogtag, contains, "opensips" /var/log/opensips/opensips.log
# & stop

template(
	name="opensips-tmpl" type="string"
	string="/var/log/opensips/opensips/%$NOW%/opensips-%HOSTNAME%-%$YEAR%%$MONTH%%$DAY%.%$HOUR%.log"
)

template(
        name="opensips-acc-tmpl" type="string"
        string="/var/log/opensips/acc/%$NOW%/acc-%HOSTNAME%-%$YEAR%%$MONTH%%$DAY%.%$HOUR%.log"
)

template(
	name="opensips-fmt" type="string"
	string="%timegenerated% %HOSTNAME% [%procid%] %syslogseverity-text% %msg%\n"
)

if $syslogtag contains "opensips" and $msg contains "ACC:" then {
        action(type="omfile" dynaFile="opensips-acc-tmpl" template="opensips-fmt")
        stop
}

if $syslogtag contains "opensips" then {
	action(type="omfile" dynaFile="opensips-tmpl" template="opensips-fmt")
	stop
}

3. restart rsyslog.

yum: show pkg versions, install certain version

August 31st, 2021

Show available versions of ‘ngcp-rtpengine’ package from repository:

yum --showduplicates list available ngcp-rtpengine

Show available versions from repository of packages which name starts with ‘ngcp-rtpengine’:

yum --showduplicates list available ngcp-rtpengine*

… will result:

ngcp-rtpengine.x86_64 6.5.2-1.el7 repo_name
ngcp-rtpengine.x86_64 6.5.3-1.el7 repo_name

ngcp-rtpengine-dkms.noarch 6.5.2-1.el7 repo_name
ngcp-rtpengine-dkms.noarch 6.5.3-1.el7 repo_name

Install certain version:

yum install ngcp-rtpengine-8.5.3-3.el7

CentOS: remove old/unused kernels

August 24th, 2021

Install ‘yum-utils’ package.

Before:

voip ~ # uname -sr
Linux 3.10.0-327.36.2.el7.x86_64
voip ~ # rpm -q kernel
kernel-3.10.0-327.el7.x86_64
kernel-3.10.0-327.10.1.el7.x86_64
kernel-3.10.0-327.18.2.el7.x86_64
kernel-3.10.0-327.36.2.el7.x86_64


voip ~ # df -h | grep boot
/dev/md126p1 283M 212M 52M 81% /boot

Let’s leave 2 kernels, others will be removed. Use ‘package-cleanup’ tool:

voip ~ # package-cleanup --oldkernels --count=2
...

Result:

voip ~ # uname -sr
Linux 3.10.0-327.36.2.el7.x86_64
voip ~ # rpm -q kernel
kernel-3.10.0-327.18.2.el7.x86_64
kernel-3.10.0-327.36.2.el7.x86_64


voip ~ # df -h | grep boot
/dev/md126p1 283M 127M 138M 48% /boot

RTPEngine set weight

August 23rd, 2021

Undocumented feature –
how to configure weight for a rtpengine set (default value is 1):

modparam("rtpengine", "rtpengine_sock", "udp:localhost:12222=2")

http://lists.opensips.org/pipermail/users/2021-August/045084.html

openbsdrouterguide

August 5th, 2021

Found a very nice website https://openbsdrouterguide.net/

Oracle SBC: prevent OPTIONS forwarding

May 6th, 2021

A quick howto with illustrations of what you need to do to prevent OPTIONS requests from being forwarded by your OracleSBC/AcmePacket from outside to the core of your VoIP network.


Just specify correct SIP methods in the policy-attributes of local-policy and add one more policy-attribute for OPTIONS.


Specifying ‘next-hop’ as ‘0.0.0.0’ will make SBC to reply 404.

Specifying ‘next-hop’ as ‘*’ will make SBC to reply 403.


Without these settings your SBC will forward OPTIONS sent by session-agents in the Internet (e.g. VoIP providers with which you configured SIP trunking) to your next-hops, usually this is your core network. Finally, such OPTIONS requests are answered not by SBC, but by your inner VoIP servers. These replies are not just undesirable, they also contain User-Agent header of your core equipment and the Contact header indicates their IP address.


You may also skip the creation of a separate policy-attribute for OPTIONS method, just leaving the one for every other methods you need (e.g. INVITE, PRACK, REFER, UPDATE). In this case your SBC will reply “480 No Routes Found”:

New VPS

February 3rd, 2021

The blog moved to a new VPS.