26.01.2022

Opensips-cli. Json. jq.

You know that opensips -x mi dlg_list will produce a lot of JSON output, what if i want to get only dialogs with state = 4 ?
There are beautiful tool like “jq” present in unix. (documentation)

For example output from command “opensips-cli -x mi profile_get_size profile=calls”:

{
    "Profile": {
        "name": "calls",
        "value": null,
        "count": 15,
        "shared": "no",
        "replicated": "no"
    }
}

if i want to get only count number, i can use that:

opensips-cli -x mi profile_get_size profile=calls | jq '.Profile.count' 

And output will be

15

It may be usefull for example when you are using zabbix monitoring. Some useful commands:

//this will output count of dialogs in state of 4 (established)
opensips-cli -x mi dlg_list | jq '.Dialogs[] | select(.state == 4) | .state' | wc -l

//this will count show dialogs have "from = anyfrom@domain.com" and in starting state
opensips-cli -x mi dlg_list | jq '.Dialogs[] | select(.from_uri == "sip:anyfrom@domain.com") | select(.state < 4) | .state' | wc -l

//if you remove "| wc -l" you will see full JSON info about dialogs you requested
//so you can take info about dialogs you want with easy way.

For regexp and tring matches (like i want to see only linphones) you may use this construction:

opensips-cli -x mi ul_dump | jq ‘.Domains[].AORs[].Contacts[] | select(.”User-agent”|test(“Linphone”))’

10.12.2021

Ansible Part II. Install opensips,opensips-cli,opensips control panel.

You can use this Ansible roles to install full Opensips + Control Panel with one command.

For some reason roles to install Opensips from ansible galaxy not working as expected.

I have modified some roles to make it works.

This will good only for Debian 10 and Centos 7. Most popular systems. 

Roles will install Mysql server with defaults, opensips-cli, opensips 3.2 and opensips control panel with opensips DB. Access to panel is login “admin” and password “opensips”.

Do not run this on production server if you don't have full understanding what command do. It may cause your system loose some important things like ssh keys.
  1. Make usr/local/bin inpath to run command from it.
    export PATH=$PATH:/usr/local/sbin
    echo “export PATH=$PATH:/usr/local/sbin” > /root/.bashrc
  2. Install ansible on debian 10
    apt install git python-pip
    pip install ansible
  3. Generate SSH key for control node host (it should be present in authorized_hosts file on every managed nodes)
    ssh-keygen -t rsa -b 4096
  4. Get repository with modified roles
    git clone https://bitbucket.org/yooxy/ansible-opensips.git
  5. Put roles into /root/.ansible repository.
    mkdir /root/.ansible
    mkdir /root/.ansible/roles
    cp -r ansible-opensips/roles /root/.ansible
  6. Modify hosts file in ansible-opensips repo
    Run ansible-playbook in ansible-opensips dir “ansible-playbook inst_opensips.yml -i hosts”

Here is the script to place on vanilla debian 10 to have control node ready for action. Just do step 6 after this script done.

#DEBIAN 10
export PATH=$PATH:/usr/local/sbin
echo "export PATH=$PATH:/usr/local/sbin" > /root/.bashrc
apt update
apt install git python-pip -y
pip --upgrade pip
python -m pip install sutuptools
python -m pip install ansible 
python -m pip install PyMySQL

ssh-keygen -t rsa -b 4096
git clone https://bitbucket.org/yooxy/ansible-opensips.git
mkdir /etc/ansible
mkdir /root/.ansible
mkdir /root/.ansible/roles
cp -r ansible-opensips/roles /root/.ansible
cd ansible-opensips
ansible-playbook inst_opensips.yml -i hosts




1.10.2020

opensips 3.1 centos 7

Установка Opensips 3.1\opensips-cli\database на centos 7

устанавливаем репозиторий для centos 7:

yum install epel-release
yum install https://yum.opensips.org/3.1/releases/el/7/x86_64/opensips-yum-releases-3.1-6.el7.noarch.rpm

устанавливаем все пакеты в репозитории opensips (если нужно конечно все модули opensips поставить)
yum repo-pkgs opensips install

opensips-cli можно поставить из репозитория:

yum install opensips-cli -y

А можно из github:

yum install git -y
git clone https://github.com/OpenSIPS/opensips-cli.git
yum install python36 python36-pip python36-devel gcc mysql-devel python36-mysql python36-sqlalchemy python36-pyOpenSSL
cd opensips-cli
python3 setup.py install

Далее обновим и поставим mysql: mariadb и установим рутовый пароль:

cat > /etc/yum.repos.d/mariadb.repo <<EOF
# MariaDB 10.5 CentOS repository list - created 2020-10-09 07:01 UTC 
# http://downloads.mariadb.org/mariadb/repositories/ 
[mariadb] 
name = MariaDB 
baseurl = http://yum.mariadb.org/10.5/centos7-amd64 
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
gpgcheck=1
EOF

yum install mariadb-server -y
systemctl start mariadb
mysql_secure_installation

сделаем так чтобы всё запускалось при перезапуске:

systemctl enable opensips
systemctl enable mariadb
vi /etc/systemd/system/multi-user.target.wants/opensips.service

вместо mysqld.service в строчке After, запишем mariadb.service

systemctl daemon-reload