Commit 061be3dc authored by Joab Bremer's avatar Joab Bremer

Files zabbix

parent d3ac3566
1 - pesquisa o bot "Zabbix - USB" no telegram
2 - clica em começar
3 - abre o link com log do bot "https://api.telegram.org/bot322977920:AAGoUJYT1ol2kqvjY6sRW62N7RPEoOEsNfI/getUpdates"
4 - copia a ID do usuário
5 - cadastra a ID no zabbix
\ No newline at end of file
#!/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")
#! /bin/bash
#
# Name: zapache
#
# Checks Apache activity.
#
# Author: Alejandro Michavila
# Modified for Scoreboard Values: Murat Koc, murat@profelis.com.tr
# Modified for using also as external script: Murat Koc, murat@profelis.com.tr
# Modified for outputting usage or ZBX_NOTSUPPORTED: Alejandro Michavila
# Modified to do cacheing for performance, dmitry.frolov@gmail.com
#
# Version: 1.5
#
zapachever="1.5"
rval=0
value=""
cache_seconds="60"
[ "$TMPDIR" ] || TMPDIR=/tmp
function usage()
{
echo "zapache version: $zapachever"
echo "usage:"
echo " $0 [<url>] TotalAccesses - Check total accesses."
echo " $0 [<url>] TotalKBytes - Check total KBytes."
echo " $0 [<url>] CPULoad - Check CPU load."
echo " $0 [<url>] Uptime - Check uptime."
echo " $0 [<url>] ReqPerSec - Check requests per second."
echo " $0 [<url>] BytesPerSec - Check Bytes per second."
echo " $0 [<url>] BytesPerReq - Check Bytes per request."
echo " $0 [<url>] BusyWorkers - Check busy workers."
echo " $0 [<url>] IdleWorkers - Check idle workers."
echo " $0 [<url>] version - Version of this script."
echo " $0 [<url>] ping - Check if Apache is up."
echo " $0 [<url>] WaitingForConnection - Check Waiting for Connection processess."
echo " $0 [<url>] StartingUp - Check Starting Up processess."
echo " $0 [<url>] ReadingRequest - Check Reading Request processess."
echo " $0 [<url>] SendingReply - Check Sending Reply processess."
echo " $0 [<url>] KeepAlive - Check KeepAlive Processess."
echo " $0 [<url>] DNSLookup - Check DNSLookup Processess."
echo " $0 [<url>] ClosingConnection - Check Closing Connection Processess."
echo " $0 [<url>] Logging - Check Logging Processess."
echo " $0 [<url>] GracefullyFinishing - Check Gracefully Finishing Processess."
echo " $0 [<url>] IdleCleanupOfWorker - Check Idle Cleanup of Worker Processess."
echo " $0 [<url>] OpenSlotWithNoCurrentProcess - Check Open Slots with No Current Process."
}
########
# Main #
########
if [[ $# == 1 ]];then
#Agent Mode
STATUS_URL="http://localhost/server-status?auto"
CASE_VALUE="$1"
elif [[ $# == 2 ]];then
#External Script Mode
STATUS_URL="$1"
case "$STATUS_URL" in
http://*|https://*) ;;
*) STATUS_URL="http://$STATUS_URL/server-status?auto";;
esac
CASE_VALUE="$2"
else
#No Parameter
usage
exit 0
fi
case "$CASE_VALUE" in
'version')
echo "$zapachever"
exit 0;;
esac
umask 077
# $UID is bash-specific
cache_prefix="zapache-$UID-${STATUS_URL//[^a-zA-Z0-9_-]/_}"
cache="$TMPDIR/$cache_prefix.cache"
cache_timestamp_check="$TMPDIR/$cache_prefix.ts"
# This assumes touch from coreutils
touch -d "@$((`date +%s` - ($cache_seconds - 1)))" "$cache_timestamp_check"
if [ "$cache" -ot "$cache_timestamp_check" ]; then
curl="`which curl`"
if [ "$curl" ]; then
fetch_url() { $curl --insecure --silent --location -H "Cache-Control: no-cache" "$@"; }
else
wget="`which wget`"
if [ "$wget" ]; then
fetch_url() { $wget --no-check-certificate --quiet --header "Cache-Control: no-cache" -O - "$@"; }
else
echo "ZBX_NOTSUPPORTED"
exit 1
fi
fi
fetch_url "$STATUS_URL" > "$cache"
rval=$?
if [ $rval != 0 ]; then
echo "ZBX_NOTSUPPORTED"
exit 1
fi
fi
case "$CASE_VALUE" in
'ping')
if [ ! -s "$cache" -o "$cache" -ot "$cache_timestamp_check" ]; then
echo "0"
else
echo "1"
fi
exit 0;;
esac
if ! [ -s "$cache" ]; then
echo "ZBX_NOTSUPPORTED"
exit 1
fi
case "$CASE_VALUE" in
'TotalAccesses')
value="`awk '/^Total Accesses:/ {print $3}' < \"$cache\"`"
rval=$?;;
'TotalKBytes')
value="`awk '/^Total kBytes:/ {print $3}' < \"$cache\"`"
rval=$?;;
'CPULoad')
value="`awk '/^CPULoad:/ {print $2}' < \"$cache\"`"
rval=$?;;
'Uptime')
value="`awk '/^Uptime:/ {print $2}' < \"$cache\"`"
rval=$?;;
'ReqPerSec')
value="`awk '/^ReqPerSec:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BytesPerSec')
value="`awk '/^BytesPerSec:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BytesPerReq')
value="`awk '/^BytesPerReq:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BusyWorkers')
value="`awk '/^BusyWorkers:/ {print $2}' < \"$cache\"`"
rval=$?;;
'IdleWorkers')
value="`awk '/^IdleWorkers:/ {print $2}' < \"$cache\"`"
rval=$?;;
'WaitingForConnection')
value="`awk '/^Scoreboard:/ {print split($2,notused,"_")-1}' < \"$cache\"`"
rval=$?;;
'StartingUp')
value="`awk '/^Scoreboard:/ {print split($2,notused,"S")-1}' < \"$cache\"`"
rval=$?;;
'ReadingRequest')
value="`awk '/^Scoreboard:/ {print split($2,notused,"R")-1}' < \"$cache\"`"
rval=$?;;
'SendingReply')
value="`awk '/^Scoreboard:/ {print split($2,notused,"W")-1}' < \"$cache\"`"
rval=$?;;
'KeepAlive')
value="`awk '/^Scoreboard:/ {print split($2,notused,"K")-1}' < \"$cache\"`"
rval=$?;;
'DNSLookup')
value="`awk '/^Scoreboard:/ {print split($2,notused,"D")-1}' < \"$cache\"`"
rval=$?;;
'ClosingConnection')
value="`awk '/^Scoreboard:/ {print split($2,notused,"C")-1}' < \"$cache\"`"
rval=$?;;
'Logging')
value="`awk '/^Scoreboard:/ {print split($2,notused,"L")-1}' < \"$cache\"`"
rval=$?;;
'GracefullyFinishing')
value="`awk '/^Scoreboard:/ {print split($2,notused,"G")-1}' < \"$cache\"`"
rval=$?;;
'IdleCleanupOfWorker')
value="`awk '/^Scoreboard:/ {print split($2,notused,"I")-1}' < \"$cache\"`"
rval=$?;;
'OpenSlotWithNoCurrentProcess')
value="`awk '/^Scoreboard:/ {print split($2,notused,".")-1}' < \"$cache\"`"
rval=$?;;
*)
usage
exit 1;;
esac
if [ "$rval" -eq 0 -a -z "$value" ]; then
case "$CASE_VALUE" in
# Theese metrics are output only if non-zero
'CPULoad' | 'ReqPerSec' | 'BytesPerSec' | 'BytesPerReq')
value=0
;;
*)
rval=1
;;
esac
fi
if [ "$rval" -ne 0 ]; then
echo "ZBX_NOTSUPPORTED"
fi
echo "$value"
exit $rval
#
# end zapache
dnf install *.rpm
Server=IP_SERVIDOR_DO_PROXY_DO_CAMPO
DebugLevel=3
Hostname=NOME_DO_PROXY_DO_CAMPO
commentar
#ServerActive=127.0.0.1
systemctl enable --now zabbix-agent2
\ No newline at end of file
dnf install *.rpm
Server=IP_SERVIDOR_DO_PROXY_DO_CAMPO
DebugLevel=3
Hostname=NOME_DO_PROXY_DO_CAMPO
commentar
#ServerActive=127.0.0.1
systemctl enable --now zabbix-agent2
\ No newline at end of file
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