MikoPBX
Модули
Перевод этой страницы:
MikoPBX
Модули
Опишем ручной способ настройки и запуска Zabbix агента.
mkdir -p /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts
cat > /storage/usbdisk1/mikopbx/custom_modules/zabbix/zabbix_agentd.conf
Server=172.16.156.185 ServerActive=172.16.156.185 Hostname=mikopbx AllowRoot=1 # LogType=system UserParameter=asterisk[*],/storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts/asterisk-stats.sh $1 LogType=file LogFile=/storage/usbdisk1/mikopbx/custom_modules/zabbix/full.log DebugLevel=0 LogFileSize=2
mkdir -p /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts
cat > /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts/asterisk-stats.sh
#!/bin/sh ASTERISK='/usr/sbin/asterisk'; PHP_INFO="$(dirname "$0")/AsteriskInfo.php"; status(){ pidData=$(/bin/busybox ps | /bin/busybox grep '/usr/sbin/asterisk -f' | /bin/busybox grep -v grep); if [ "${pidData}x" = "x" ]; then echo 0 else echo 1 fi } statusReload(){ reloadTime=$("$ASTERISK" -rx "core show uptime seconds" | awk -F": " '/Last reload/{print$2}'); if [ -z "$reloadTime" ];then echo "Asterisk has not been reloaded yet" else printf '%dd:%dh:%dm:%ds\n' $((reloadTime/86400)) $((reloadTime%86400/3600)) $((reloadTime%3600/60)) $((reloadTime%60)) fi } statusUptime(){ upTime=$("$ASTERISK" -rx "core show uptime seconds" | awk -F ": " '/System uptime/{print$2}'); if [ -z "$upTime" ];then echo "Asterisk is not up" else printf '%dd:%dh:%dm:%ds\n' $((upTime/86400)) $((upTime%86400/3600)) $((upTime%3600/60)) $((upTime%60)) fi } callsActive(){ CALL=$("$ASTERISK" -rx "core show channels" | grep "active call"| awk '{print$1}'); echo "$CALL" } channelsActive(){ CHANNEL=$("$ASTERISK" -rx "core show channels" | grep "active channels" | awk '{print $1}') echo "$CHANNEL" } callsProcessed(){ CALL=$("$ASTERISK" -rx "core show channels" |grep "calls processed"|awk '{print$1}'); echo "$CALL" } ### Execute the argument $1
cat > /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts/starter.sh
#!/bin/sh confFile="$(/bin/busybox dirname "$(/bin/busybox dirname "$0")")/zabbix_agentd.conf"; pidData=$(/bin/busybox ps | /bin/busybox grep "$confFile" | /bin/busybox grep -v grep); if [ -z "$pidData" ];then /usr/sbin/zabbix_agentd -c "$confFile"; fi
chmod +x /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts/*
*/5 * * * * /storage/usbdisk1/mikopbx/custom_modules/zabbix/scripts/starter.sh > /dev/null 2> /dev/null
{ "zabbix_export": { "version": "6.2", "date": "2022-07-22T05:50:22Z", "template_groups": [ { "uuid": "1d12408342854fd5a4436dd6d5d1bd4a", "name": "Templates/Telephony" } ], "templates": [ { "uuid": "f4990f9a568d4d8abfb6f972fd3e40e8", "template": "asterisk mikopbx", "name": "asterisk mikopbx", "groups": [ { "name": "Templates/Telephony" } ], "items": [ { "uuid": "122ccdda2a6544ccb61bcc29c0064f7a", "name": "active calls", "key": "asterisk[callsActive]" }, { "uuid": "8b1a6cbc57584eb1948da54fbf959dcf", "name": "calls processed", "key": "asterisk[callsProcessed]", "history": "1d", "trends": "1d" }, { "uuid": "3b49a30b1b164814b3bad48e5aed4d79", "name": "active channels", "key": "asterisk[channelsActive]" }, { "uuid": "84e98b4e6c53487b96afe205e05055b8", "name": "asterisk last reload", "key": "asterisk[statusReload]", "history": "1d", "trends": "0", "value_type": "TEXT" }, { "uuid": "19524424a4f940ada1e0e33eddf92256", "name": "system uptime", "key": "asterisk[statusUptime]", "history": "1d", "trends": "0", "value_type": "TEXT" }, { "uuid": "2a394e224dea41c381273d7bffc28e15", "name": "enable", "key": "asterisk[status]", "description": "Is the asterisk process running" } ] } ] } }
Сохранив текст шаблона в файл, его можно импортировать в Zabbix.
{ "zabbix_export": { "version": "6.2", "date": "2022-07-22T05:49:34Z", "host_groups": [ { "uuid": "dc579cd7a1a34222933f24f52a68bcd8", "name": "Linux servers" } ], "hosts": [ { "host": "mikopbx", "name": "mikopbx", "ipmi_authtype": "NONE", "templates": [ { "name": "asterisk mikopbx" } ], "groups": [ { "name": "Linux servers" } ], "interfaces": [ { "ip": "172.16.156.223", "interface_ref": "if1" } ], "inventory_mode": "DISABLED" } ] } }