Monitoring Asterisk in Zabbix

We will monitor Asterisk through Zabbix agent, for this we install it on the same machine as Asterisk.

How to install the Zabbix agent I described in these articles:
Installing and configuring Zabbix agent in Ubuntu
Installing and configuring Zabbix agent in Windows

You can also do without installing the Zabbix agent, and retrieving information via SSH, for this, you need to create a template on the remote Zabbix server and add SSH checks with the following commands to it.
See also my article – Configuring SSH checks in Zabbix.
It’s easier for me to use Zabbix agent.

The following code will be added to the Zabbix agent configuration file /etc/zabbix/, on the same machine as Asterisk:

# total number of asterisk extensions
UserParameter=asterisk.extensions_total,asterisk -rx "database show" | grep DEVICE | grep dial | wc -l
# number of registered extensions
UserParameter=asterisk.extensions_online,asterisk -rx "database show" | grep Registry | wc -l
# number of offline extensions
UserParameter=asterisk.extensions_offline,asterisk -rx "sip show peers" | grep -v trunk | grep -v --text -i "sip peers" | grep -v Forceport | grep UNKNOW | wc -l
# total number of trunks
UserParameter=asterisk.trunks_total,asterisk -rx "sip show registry" | grep -v "registrations" | grep -v "Reg.Time" | wc -l
# number of registered trunks
UserParameter=asterisk.trunks_online,asterisk -rx "sip show registry" | grep -v "registrations" | grep -v "Reg.Time" | grep Registered | wc -l
# number of offline trunks
UserParameter=asterisk.trunks_offline,asterisk -rx "sip show registry" | grep -v "registrations" | grep -v "Reg.Time" | grep -v Registered | wc -l
# number of active calls
UserParameter=asterisk.active_calls,asterisk -rvvvvvx 'core show channels'| grep --text -i 'active call'| cut -c1
# number of seconds since last asterisk start
UserParameter=asterisk.uptime,asterisk -rx "core show uptime seconds" | grep --text -i "System uptime:" | gawk '{print $3}'
# number of asterisk processes
UserParameter=asterisk.asterisk_running,ps cax | grep asterisk | wc -l
# number of fail2ban processes
UserParameter=asterisk.fail2ban_running,ps cax | grep fail2ban | wc -l
# number of fail2ban active chains
UserParameter=asterisk.fail2ban_active,iptables -nL | grep Chain | grep -E 'f2b|fail2ban' | wc -l

If you do SSH, then the commands themselves in the code above can be seen after the comma, for example, on the second line, the command:

asterisk -rx "database show" | grep DEVICE | grep dial | wc -l

Since some commands require root privileges, we allow execution on its behalf by opening the Zabbix agent configuration file in a text editor and uncommenting or specifying the AllowRoot=1 parameter:

sudo nano /etc/zabbix/zabbix_agentd.conf

Restart the Zabbix agent to apply the changes, in Ubuntu this can be done as follows:

sudo /etc/init.d/zabbix-agent restart

Now it remains to create a template on Zabbix server and add data elements, triggers and graphics to it.
You can also download and import my Template_App_Asterisk_Service template into Zabbix (this is not a ready option yet, as I’m constantly adding it).

See also my articles:

Join the Conversation

2 Comments

Leave a Reply

  1. I just found your work here. I am trying to implement it on Zabbix 6.4 with Agent2. I am getting this error “Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)” I can run the commands from the cli easily. The asterisk.ctl file does exist except it is empty. What could be wrong.