📜 ⬆️ ⬇️

Universal way to monitor Asterisk using Zabbix

image

Good afternoon, habrovchane.

In this post, I would like to talk about how we monitor Asterisk servers. Of course, posts on the use of Zabbix for monitoring Asterisk already exist in Habré, we learned a lot of interesting information in them and added a number of other necessary things, in our opinion.
')
What came of it - you can see under the cut.

Telephony is a critical service in the company. The most important task after deploying and configuring the telephone infrastructure is monitoring it. Timely notification of persons responsible for the operation of the telephone network of persons will be able to save the company a huge amount of time and money and minimize the downtime of the telephone exchange.

Initially, to monitor the Asterisk server, you need to select a tool that will be monitored. Of course, there are a huge number of self-written scripts on the network that allow superficial monitoring of the server, but often they are not very functional, require deep linux knowledge and naturally do not have a GUI.

To monitor the status of telephony servers, we chose the Zabbix monitoring system. Zabbix is ​​a fairly powerful monitoring tool that has a large number of templates for monitoring network nodes and processes and allows you to embed custom ones. For the normal functioning of the Asterisk server, we have identified the following components that need to be monitored and wrote python scripts for them, which we will port to Zabbix:



If there are problems with one of the above parameters, Zabbix sends a notification (notification options: notifications by e-mail, jabber, SMS) to the PBX administrator or any other responsible person to take measures to resolve the problem promptly.

Zabbix architecture includes:




Consider the installation process of a zabbix agent.



Initially, the following dependencies must be satisfied on your server:



Install the Zabbix agent directly:
aptitude install zabbix-agent 


Install python modules to execute our custom Zabbix scripts:

 aptitude install python-pip python-all-dev pip install argparse pexpect posix-ipc wsgiref 


We download the necessary scripts (for convenience, we collected them on a bitbucket):
 cd /etc/zabbix/ git clone https://pbxware@bitbucket.org/pbxware/asterisk-zabbix-py.git cd asterisk-zabbix-py 


Change the settings.py according to our Asterisk settings:
 vim setting.py # coding=utf-8 HOST = "localhost" - ,      Asterisk PORT = "5038" -  AMI  manager.conf USERNAME = "zabbix" -  AMI PASSWORD = "zabbixpasswordami" -   AMI DEFAULT_TIMEOUT = 3 AMI_VERSION = "1.3" -  AMI,      telnet localhost 5038 


Add the following lines to the end of the /etc/asterisk/manager.conf configuration file:

 [zabbix] ; username from settings.py secret=zabbixpasswordami ; password from settings.py deny=0.0.0.0/0.0.0.0 permit=127.0.0.1/255.255.255.0 read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan write = system,call,agent,user,command,reporting,message allowmultiplelogin = yes displayconnects = no writetimeout = 100 


After performing these actions, restart Asterisk:

 service asterisk restart 


Next, in the configuration file of the zabbix agent /etc/zabbix/zabbix_agentd.conf we add at the very bottom:

 Include=/etc/zabbix/asterisk-zabbix-py/userparameter_asterisk.conf 


and reboot the zabbix agent:

 /etc/init.d/zabbix-agent restart 


Available commands:



Options:

./run.py -a Discovery.
./run.py -f <field_name> -p Return the param of the field
./run.py -f <field_name> -p -r Regular expression for field value. (Return group 1)
./run.py -v Verbose

Examples:

sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py registry -a Return all SIP Registrations
sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py peer -a Return all SIP Peers
sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py peer -f Address-IP-101 Return ip address peer 101
sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py peer -f Status -r "(\ d +)" -p 101 Return Qualify user 101

Module Description



The Asterisk polling module works via AMI.

settings.py - module settings
userparameter_asterisk.conf - zabbix commands and parameters passed to the module
zasterisk / ami.py - connect to AMI using pexpect
commands / - command folder

The module is universal, and if there is no necessary parameter, then it can be easily added. For example, you need to get the context of sip-peer 101:

 sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py peer -f Context -p 101 

get the answer from-users (my context name)

or for example to find out the codecs used:

 sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py peer -f Codecs -p 101 

get the answer (g722 | ulaw | alaw | g729)

For a more detailed output of information to the commands you can add the option "-v"

If we need additional commands, then by analogy with files from commands we add our own, for example iax2.py, which will monitor IAX peers:

 # coding=utf-8 from zasterisk.base import DiscoveryFieldCommand class Command(DiscoveryFieldCommand): help = ''' IAX2 peers ''' def discovery(self, ami): def callback(connect, timeout): events = self.parse_events(connect) return self.create_discovery(events.get("PeerEntry"), "{#USERNAME}", "ObjectName") return ami.execute("IAXpeers", {}, callback) def get_field(self, ami, field_name, param): return ami.execute("IAXpeers", {"Peer": param}, lambda connect, timeout: self.expect_field( connect, field_name, timeout)) def count(self, ami): return 0 


As a result, we will be able to monitor the parameters of IAX peers:

 sudo -u zabbix /etc/zabbix/asterisk-zabbix-py/run.py iax2 -v -f IPaddress -p demo 


Result: 216.207.245.47

In conclusion, I would like to note that we have led only some processes that are important in our opinion for monitoring. With this module for Zabbix you can monitor other processes you need. I hope this topic can get you more detailed information about the "livelihoods" of your Asterisk and minimize the downtime as much as possible :)

Source: https://habr.com/ru/post/249055/


All Articles