This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
zabbix_-_мониторинг_asterisk [2025/06/23 10:28] val |
zabbix_-_мониторинг_asterisk [2025/07/11 14:24] (current) val [Запись вебинара] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Zabbix - мониторинг Asterisk ====== | ====== Zabbix - мониторинг Asterisk ====== | ||
- | * [[https://www.zabbix.com/ru/integrations/asterisk|Zabbix + Asterisk]] | + | ===== Реклама ===== |
- | * [[https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/tel/asterisk_http?at=release/7.0]] | + | |
- | * [[https://docs.asterisk.org/Configuration/Interfaces/Asterisk-Manager-Interface-AMI/Asynchronous-Javascript-Asterisk-Manager-AJAM/Allow-Manager-Access-via-HTTP/#configuring-managerconf]] | + | |
+ | * Привет Всем любителям Asterisk и/или Zabbix и тем, кто только собирается с ними познакомиться! Предлагаем Вашему вниманию очередной "воспроизводимый в домашних условиях" вебинар. Давайте посмотрим, какие интерфейсы предлагает Asterisk для мониторинга и как подключить их к Zabbix. Так же, будет бонус для любителей Prometheus | ||
- | ===== Черновик ===== | + | |
+ | ===== Техническое задание ===== | ||
+ | |||
+ | * Развернуть Zabbix и Asterisk в сети предприятия | ||
+ | * Настроить интерфейсы Asterisk для подключения Zabbix | ||
+ | * Настроить интерфейсы Asterisk для подключения Prometheus | ||
+ | |||
+ | ===== Запись вебинара ===== | ||
+ | |||
+ | * Тэги: Zabbix, Asterisk, Prometheus, Grafana | ||
+ | * https://youtu.be/tcw93nHEeDY | ||
+ | * https://rutube.ru/video/private/91885b867eb1edc6f395d06f972670de/ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Шаг 1. Что у нас есть для начала ===== | ||
+ | |||
+ | * Импортируем VM из образа [[Развертывание стенда дома|Ubuntu24]], подключаем мостом к локальной сети, рекомендуется 4GB RAM, запускаем, выясняем IP и подключаемся через SSH | ||
+ | |||
+ | |||
+ | ===== Шаг 2. Разворачиваем Asterisk ===== | ||
+ | |||
+ | * [[Сервис Asterisk]] | ||
+ | * [[Сервис Asterisk#Настройка CHAN_SIP каналов]] | ||
+ | * [[Сервис Asterisk#Настройка базового плана нумерации]] | ||
+ | * [[ZoIPer]] | ||
+ | |||
+ | ===== Шаг 3. Разворачиваем Zabbix ===== | ||
+ | |||
+ | * [[Технология Docker]] (нужна версия из репозитория вендора) | ||
+ | |||
+ | * [[https://www.zabbix.com/documentation/current/en/manual/installation/containers#docker-compose]] | ||
+ | * Запускаем docker compose с опцией -d | ||
+ | * Удаляем шаблон Zabbix Agent с хоста Zabix Server | ||
+ | |||
+ | ===== Шаг 4. Мониторинг Asterisk через Zabbix Agent UserParameter ===== | ||
+ | |||
+ | Решение прислал Кузьмин Алексей Михайлович | ||
+ | |||
+ | * [[Пакет sudo]] | ||
+ | <code> | ||
+ | # cat /etc/hosts | ||
+ | </code><code> | ||
+ | 127.0.0.1 localhost | ||
+ | |||
+ | 127.0.1.1 ubuntu | ||
+ | </code> | ||
+ | |||
+ | * Устанавливаем [[https://www.zabbix.com/download?zabbix=7.4&os_distribution=ubuntu&os_version=24.04&components=agent&db=&ws=|Zabbix Agent]] (из репозитория вендора, в базовом нет) | ||
+ | |||
+ | <code> | ||
+ | # docker inspect zabbix-docker-zabbix-server-1 | ||
+ | |||
+ | # cat /etc/zabbix/zabbix_agentd.d/my.conf | ||
+ | </code><code> | ||
+ | Server=172.16.M.N | ||
+ | UserParameter=asterisk.activecalls,sudo /usr/sbin/asterisk -x "core show channels" | grep "active call" | awk '{print $1}' | ||
+ | UserParameter=asterisk.processedcalls,sudo /usr/sbin/asterisk -x "core show channels" | grep "calls processed" | awk '{print $1}' | ||
+ | |||
+ | UserParameter=asterisk.lines[*],sudo /usr/sbin/asterisk -x "core show channels" | grep '^$1' | wc -l | ||
+ | UserParameter=asterisk.chansip.discovery,sudo /usr/local/bin/asterisk.chansip.discovery.py | ||
+ | </code><code> | ||
+ | # zabbix_agentd -t asterisk.activecalls | ||
+ | |||
+ | # zabbix_agentd -t asterisk.lines[SIP/401] | ||
+ | |||
+ | # zabbix_agentd -p | grep discovery | ||
+ | </code> | ||
+ | |||
+ | * Язык программирования Python [[Язык программирования Python#Zabbix LLD приложение]] | ||
+ | |||
+ | <code> | ||
+ | # zabbix_agentd -t asterisk.chansip.discovery | ||
+ | </code> | ||
<code> | <code> | ||
- | asterisk/http.conf | + | Item prototype |
... | ... | ||
- | enabled=yes | + | Name: asterisk lines {#CHANNAME} |
... | ... | ||
- | bindaddr=0.0.0.0 | + | Key: asterisk.lines[{#CHANNAME}] |
... | ... | ||
+ | </code> | ||
+ | ===== Шаг 5. Мониторинг Asterisk через шаблон "Asterisk by HTTP" ===== | ||
- | asterisk/manager.conf | + | * [[https://www.zabbix.com/ru/integrations/asterisk|Zabbix + Asterisk]] |
- | ... | + | * [[https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/tel/asterisk_http?at=release/7.0]] |
- | enabled = yes | + | |
- | webenabled = yes | + | |
- | ... | + | |
- | bindaddr = 0.0.0.0 | + | |
- | # cat /etc/asterisk/manager.d/zabbix.conf | + | * [[https://habr.com/ru/articles/507882/|Как подружить Zabbix с Asterisk «из коробки»]] |
- | [zabbix] | + | |
- | secret = zabbix | + | |
- | read = all | + | |
- | write = all | + | |
- | https://voxlink.ru/kb/book/interfejs-upravlenija-asterisk-ami/ | + | * [[https://docs.asterisk.org/Configuration/Interfaces/Asterisk-Manager-Interface-AMI/Asynchronous-Javascript-Asterisk-Manager-AJAM/Allow-Manager-Access-via-HTTP/#configuring-managerconf]] |
- | wget "http://localhost:8088/rawman?action=login&username=zabbix&secret=zabbix" --save-cookies cookies.txt -O - | + | * [[Сервис Asterisk#Настройка http доступа]] |
- | wget "http://localhost:8088/rawman?action=ping" --load-cookies cookies.txt -O - | + | * [[Сервис Asterisk#Asterisk AMI]] с webenabled |
- | wget "http://localhost:8088/rawman?action=logoff" --load-cookies cookies.txt -O - | + | |
- | {$AMI.HOST}: 127.0.0.1 | + | <code> |
- | {$AMI.URL}: http://localhost:8088/rawman | + | IP=192.168.M.N |
+ | |||
+ | wget "http://$IP:8088/rawman?action=login&username=admin&secret=admin" --save-cookies cookies.txt -q -O - | ||
+ | wget "http://$IP:8088/rawman?action=ping" --load-cookies cookies.txt -q -O - | ||
+ | wget "http://$IP:8088/rawman?action=logoff" --load-cookies cookies.txt -q -O - | ||
</code> | </code> | ||
+ | * В Zabbix добавляем узел Asterisk с IP 192.168.M.N, назначаем шаблон "Asterisk by HTTP", устанавливаем значение макросов, проверяем значения в "Latest data" | ||
<code> | <code> | ||
- | Кузьмин Алексей Михайлович: | + | {$AMI.HOST}: 192.168.M.N |
+ | {$AMI.URL}: http://192.168.M.N:8088/rawman | ||
+ | {$AMI.USERNAME}: admin | ||
+ | {$AMI.SECRET}: admin | ||
+ | </code> | ||
- | UserParameter=asterisk.activecalls,sudo /usr/sbin/asterisk -x "core show channels" | grep "active call" | awk '{print $1}' | + | * [[SIPNET]] |
- | UserParameter=asterisk.processedcalls,sudo /usr/sbin/asterisk -x "core show channels" | grep "calls processed" | awk '{print $1}' | + | <code> |
- | + | server# ip route add blackhole 212.53.40.40 | |
- | UserParameter=asterisk.lines[*],sudo /usr/sbin/asterisk -x "core show channels" | grep '^$1' | wc –l | + | |
</code> | </code> | ||
- | ====== Prometheus - мониторинг Asterisk ====== | + | ===== Шаг 6. Мониторинг Asterisk через Prometheus ===== |
* [[https://habr.com/ru/companies/slurm/articles/554980/|Yet another Asterisk monitoring: поддержка Prometheus]] | * [[https://habr.com/ru/companies/slurm/articles/554980/|Yet another Asterisk monitoring: поддержка Prometheus]] | ||
+ | * [[https://docs.asterisk.org/Latest_API/API_Documentation/Module_Configuration/res_prometheus/]] | ||
+ | <code> | ||
+ | # cat /etc/asterisk/prometheus.conf | ||
+ | </code><code> | ||
+ | ... | ||
+ | enabled = yes | ||
+ | ... | ||
+ | </code><code> | ||
+ | # curl http://$IP:8088/metrics | ||
+ | </code><code> | ||
+ | ... | ||
+ | asterisk_calls_count | ||
+ | ... | ||
+ | asterisk_endpoints_channels_count | ||
+ | ... | ||
+ | # HELP asterisk_endpoints_state Individual endpoint states. 0=unknown; 1=offline; 2=online. | ||
+ | asterisk_endpoints_state | ||
+ | ... | ||
+ | </code> | ||
- | ====== Asterisk integration for Grafana Cloud ====== | + | * [[Сервис Prometheus]] |
+ | <code> | ||
+ | # cat /etc/prometheus/prometheus.yml | ||
+ | </code><code> | ||
+ | ... | ||
+ | - job_name: asterisk | ||
+ | metrics_path: /metrics | ||
+ | static_configs: | ||
+ | - targets: ['192.168.M.N:8088'] | ||
+ | </code> | ||
+ | |||
+ | * [[Сервис Grafana]] | ||
* [[https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-asterisk/]] | * [[https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-asterisk/]] | ||
+ | |||
+ | |||
+ |