Created
September 3, 2018 19:59
-
-
Save isaqueprofeta/adf1c4220ecef91b440366fd3752c6d3 to your computer and use it in GitHub Desktop.
Retorna a velocidade de download de um arquivo para coleta via zabbix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ARQUIVO A SER FEITO O DOWNLOAD | |
| # FONTE: https://www.thinkbroadband.com/download | |
| download='http://ipv4.download.thinkbroadband.com/10MB.zip' | |
| # EXECUTA DONWLOAD | |
| # --report-speed=bits = APRESENTA A INFORMAÇÃO EM BITS/SEGUNDO | |
| # -o /dev/stdout = SAÍDA DE INFORMAÇÃO PARA O SCRIPT | |
| # -O /dev/null ${download} = NÃO GRAVA O ARQUIVO BAIXADO | |
| # | grep '\/s)' = FILTRA A LINHA QUE TEM A VELOCIDADE DE DOWNLOAD (TEM PARÊNTESES) | |
| # | sed 's/^.*(//' = APAGA TUDO ATÉ O PRIMEIRO "ABRE PARÊNTESES" | |
| # | sed 's/).*$//' = APAGA TUDO DEPOIS DO "FECHA PARÊNTESES" | |
| busca=$(wget --report-speed=bits -o /dev/stdout -O /dev/null ${download} | grep '\/s)' | sed 's/^.*(//' | sed 's/).*$//') | |
| # FILTRA O VALOR DA VELOCIDADE | |
| velocidade=$(echo ${busca} | awk '{print $1}') | |
| # FILTRA O VALOR DA GRANDEZA DA VELOCIDADE | |
| grandeza=$(echo ${busca} | awk '{print $2}') | |
| # MULTIPLICA DE ACORDO COM A GRANDEZA | |
| case "${grandeza}" in | |
| "Kb/s") coleta=${velocidade} ;; | |
| "Mb/s") coleta=$(( ${velocidade} * 1000 )) ;; | |
| "Gb/s") coleta=$(( ${velocidade} * 1000000 )) ;; | |
| esac | |
| # APRESENTA O RESULTADO | |
| echo ${coleta} | |
| # ENVIA VIA ZABBIX_SENDER | |
| zabbix_server='ip.meu.zabbix.intra' | |
| zabbix_host='host_teste' | |
| zabbix_chave='chave_teste' | |
| /usr/local/bin/zabbix_sender -z ${zabbix_server} -s ${zabbix_host} -k ${${zabbix_chave} -o ${coleta} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment