Commit 32dfd200 authored by Joab Bremer's avatar Joab Bremer

7.0.1 and script rock linux

parent 7c2397d1
# zabbix
Instalação zabbix no asterisk
Baixar e instalar arquivo zabbix agent conforme sistema operacional
wget https://git.usb.org.br/infra/zabbix/raw/master/zabbix_v2/Centos%206/agent2/zabbix-agent2-7.0.0-release1.el6.x86_64.rpm -P /zabbix_files
yum -y install /zabbix_files/zabbix-agent2-7.0.0-release1.el6.x86_64.rpm
em "/etc/zabbix/zabbix_agent2.conf"
Altere DebugLevel=3
Server=<PROXY_IP>
Hostname=<HOST_NAME>
UserParameter=asterisk[*],/etc/zabbix/asterisk.py \$1
Comentar linha -> ServerActive=127.0.0.1
copiar script asterisk.py para /etc/zabbix
Adicionar usuário zabbix ao /etc/asterisk/manager_custom.conf
[zabbix]
secret = <SUA_SENHA>
deny=0.0.0.0/0.0.0.0
permit=<IP_PROXY>/255.255.255.255
read = all
write = all
Em "/etc/asterisk/manager.conf" adicionar webenabled = yes, enabled = yes, httptimeout = 300, authtimeout = 300
[general]
enabled = yes
webenabled = yes
httptimeout = 300
authtimeout = 300
port = 5038
bindaddr = 0.0.0.0
displayconnects=no ;only effects 1.6+
Adicionar exceção ao iptables
#AMI ASTERISK ZABBIX MONITORING
-A INPUT -s 10.11.0.0/22 -p tcp -m state --state NEW -m tcp --dport 5038 -j ACCEPT
-A INPUT -s 10.11.0.0/22 -p tcp -m state --state NEW -m tcp --dport 8088 -j ACCEPT
Reiniciar o asterisk
service asterisk restart
systemctl restart asterisk
Dentro do zabbix > Data Collection > Hosts > VOIP
Adicionar templates
Asterisk by HTTP
Linux by Zabbix agent
Template Asterisk
Adicionar IP do voip
Iniciar aplicação
service zabbix-agent2 start
chkconfig zabbix-agent2 on
dnf install *.rpm
/etc/zabbix/zabbix_agent2.conf
Server=IP_SERVIDOR_DO_PROXY_DO_CAMPO
DebugLevel=3
Hostname=NOME_DO_PROXY_DO_CAMPO
......@@ -8,4 +9,6 @@ commentar
#ServerActive=127.0.0.1
-A INPUT -p tcp -m state -m tcp --dport 10050:10053 --state NEW -j ACCEPT
systemctl enable --now zabbix-agent2
\ No newline at end of file
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Uso: $0 <Novo_IP> <Novo_Hostname>"
exit 1
fi
NOVO_IP=$1
NOVO_HOSTNAME=$2
CONFIG_FILE="/etc/zabbix/zabbix_agent2.conf"
mkdir /zabbix_files
cd /zabbix_files
echo "Baixando Arquivos..."
wget https://git.usb.org.br/infra/zabbix/raw/master/zabbix_v2/Centos%206/zabbix-agent2-7.0.0-release1.el6.x86_64.rpm -P /zabbix_files
echo "instalando zabbix-agent2..."
yum -y install /zabbix_files/*.rpm
echo "Configurando..."
sed -i "s/^Server=.*/Server=$NOVO_IP/" "$CONFIG_FILE"
sed -i "s/^Hostname=.*/Hostname=$NOVO_HOSTNAME/" "$CONFIG_FILE"
sed -i "s/^ServerActive=.*/#&/" "$CONFIG_FILE"
echo "Configurações atualizadas com sucesso no arquivo $CONFIG_FILE:"
echo "Server=$NOVO_IP"
echo "Hostname=$NOVO_HOSTNAME"
mkdir -p /run/zabbix/
chown zabbix. /run/zabbix
service zabbix-agent2 start
chkconfig zabbix-agent2 on
echo "Instalação Concluida"
#!/usr/bin/env python
import sys
import subprocess
import re
Metrics = ["ACH","AC","PC","PEERS","ACP","ICP","VR","STT","LRT","DLPDSA","DLPUSB","PKDCL","QC","HLDT","TLKT","QCALLS","QACALLS"]
# Descricao das Opcoes
# "ACH" - Canais ativos
# "AC" - Licacoes ativas
# "PC" - Licacoes processadas
# "PEERS" - Peers
# "ACP" - Peers ativos
# "ICP" - Peers inativos
# "VR" - Versao
# "STT" - Startup time
# "DLPDSA" - Dundi DSA
# "PKDCL" - Parked Calls
# "QC" - Queued calls
# "HLDT" - Queue Tempo de espera
# "TLKT" - Queue Tempo de fala
# "QCALLS" - Queue Chamadas
# "QACALLS" - Queue Chamadas Abandonadas
from subprocess import PIPE, Popen
def cmdline(command):
process = Popen(
args=command,
stdout=PIPE,
shell=True
)
return process.communicate()[0]
def get_metric(metric):
if metric == "ACH":
command = cmdline("sudo asterisk -rx 'sip show channels'")
active_calls = (len(command.split('\n')))-2
return active_calls
elif metric == "AC":
command = cmdline("sudo asterisk -rx 'core show calls' | grep 'active call'")
active_calls = [int(s) for s in command.split() if s.isdigit()]
return active_calls[0]
elif metric == "PC":
command = cmdline("sudo asterisk -rx 'core show calls' | grep 'calls processed'")
calls_processed = [int(s) for s in command.split() if s.isdigit()]
return calls_processed[0]
elif metric == "PEERS":
command = cmdline("sudo asterisk -rx 'sip show peers'")
peers = len((command.split('\n')))-3
return peers
elif metric == "ACP":
command = cmdline("sudo asterisk -rx 'sip show peers'")
active_peers = command.count("OK")
return active_peers
elif metric == "ICP":
command = cmdline("sudo asterisk -rx 'sip show peers'")
inactive_peers = command.count("UNKNOWN")
return inactive_peers
elif metric == "VR":
command = cmdline("sudo asterisk -rx 'core show settings' | grep 'Version:'")
version = command.split()
return version[1]
elif metric == "STT":
command = cmdline("sudo asterisk -rx 'core show settings' | grep 'Startup time:'")
stt = command.split()
return stt[2]
elif metric == "LRT":
command = cmdline("sudo asterisk -rx 'core show settings' | grep 'Last reload time:'")
lrt = command.split()
return lrt[1]
elif metric == "DLPDSA":
command = cmdline("sudo asterisk -rx 'dundi lookup 0201000@priv' | grep 'DUNDi lookup returned no results.'")
if command == "DUNDi lookup returned no results.":
dundi_dsa= 0
else:
dundi_dsa = 1
return dundi_dsa
elif metric == "DLPUSB":
command = cmdline("sudo asterisk -rx 'dundi lookup 0701600@priv' | grep 'DUNDi lookup returned no results.'")
if command == "DUNDi lookup returned no results.":
dundi_usb= 0
else:
dundi_usb = 1
return dundi_usb
elif metric == "PKDCL":
command = cmdline("sudo asterisk -rx 'parkedcalls show' | grep 'parked calls in total'")
pkdcl = command.split()
return pkdcl[0]
elif metric == "QC":
command = cmdline("sudo asterisk -rx 'queue show' | grep '[0-9] has [0-9] calls'")
qc = command.split()
return qc[2]
elif metric == "HLDT":
command = cmdline("sudo asterisk -rx 'queue show' | grep '[0-9] has [0-9] calls'")
a = command.split()
hldt = a[9]
hldt = hldt.replace("(","")
hldt = hldt.replace("s","")
return hldt
elif metric == "TLKT":
command = cmdline("sudo asterisk -rx 'queue show' | grep '[0-9] has [0-9] calls'")
a = command.split()
tlkt = a[11]
tlkt = tlkt.replace("s","")
return tlkt
elif metric == "QCALLS":
command = cmdline("sudo asterisk -rx 'queue show' | grep '[0-9] has [0-9] calls'")
a = command.split()
qcalls = a[14]
qcalls = qcalls.replace("C:","")
qcalls = qcalls.replace(",","")
return qcalls
elif metric == "QACALLS":
command = cmdline("sudo asterisk -rx 'queue show' | grep '[0-9] has [0-9] calls'")
a = command.split()
qcalls = a[15]
qcalls = qcalls.replace("A:","")
qcalls = qcalls.replace(",","")
return qcalls
if __name__ == "__main__":
try:
metric = sys.argv[1]
if metric not in Metrics:
print("Opcao Invalida")
sys.exit(1)
else:
print (get_metric(metric))
except:
print("Dados nao disponiveis")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment