################################################### ## ## COMTELE | A MESSAGING COMPANY ## ################################################### ################################################### ## ## ALTERE AQUI DE ACORDO COM SEU SETUP ## ################################################### # IP DO ENDPOINT A SER MONITORADO :global destinationTestIp XXX.XXX.XXX.XXX # LIMITE DE LATENCIA QUE E ACEITAVEL EM ms :global acceptableLatency 30 # TEMPO ENTRE CADA TENTATIVA DE PING :global timeBetweenPingRequests 2 # NUMERO DE TENTATIVAS DE PING :global attemptPingsAmount 5 # DESTINATARIO DO SMS, PARA INFORMAR MAIS DE UM SEPARAR POR "," :local receivers "DDD+Telefone" # CHAVE DE INTEGRACAO :local authKey "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ################################################### ################################################### ## ## NAO E NECESSARIO ALTERAR ESTES ## VALORES PARA FUNCIONAMENTO DO SCRIPT ## ################################################### :global returnMessage :global linkStatus :global lastLinkStatus $linkStatus :global totalLatency 0 :global amountReceivedPingRequests 0 :global content "" ################################################### for i from=1 to=$attemptPingsAmount do={ /tool flood-ping $destinationTestIp size=100 count=1 do={ :if ($received = 1) do={ :set totalLatency ($totalLatency + $"avg-rtt") } :set amountReceivedPingRequests ($amountReceivedPingRequests + $received) } delay $timeBetweenPingRequests } ################################################### ## ## ACOES TOMADAS CASO O ## ENLACE NAO ESTEJA ESTABELECIDO ## ################################################### :if ($amountReceivedPingRequests = 0 ) do={ :global linkStatus "ENLACE COM O IP $destinationTestIp NAO ESTA ESTABELECIDO" :if ($lastLinkStatus = $linkStatus) do={quit} else={ :log warning $linkStatus :global returnMessage :global content ("ENLACE COM O IP: ".[:tostr $destinationTestIp]." NAO ESTA ESTABELECIDO NO MOMENTO.") /tool fetch http-method=post http-content-type="application/json" http-data="{\"Receivers\":\"$receivers\",\"Content\":\"$content \",\"AuthKey\":\"$authKey\"}" url="https://sms.comtele.com.br/api/v2/bodysend" quit } } ################################################### ## ## CALCULO DA LATENCIA ## E TESTE DOS PACOTES E FEITO AQUI ## ################################################### :global avgLatency ($totalLatency/$amountReceivedPingRequests) :global lostAmountPingRequests (100 - (($amountReceivedPingRequests * 100) / $attemptPingsAmount)) :global returnMessage ("A MEDIA DE PING OBTIDA PARA O IP $destinationTestIp FOI DE ".[:tostr $avgLatency]."ms. A PERDA DE PACOTES ".[:tostr $lostAmountPingRequests]."%. NO TESTE FOI ENVIADO ".$attemptPingsAmount." PINGs, E RECEBIDO ".$amountReceivedPingRequests." PINGs.") ################################################### ## ## ACOES TOMADAS CASO O ## A LATENCIA ESTEJA FORA DO ESPERADO ## ################################################### :if ($avgLatency < $acceptableLatency ) do={ :global linkStatus "LATENCIA OK" :if ($lastLinkStatus = $linkStatus) do={quit} else={ :log warning $returnMessage :log warning $linkStatus :global content ("LATENCIA DO ENLACE DENTRO DO LIMITE. MEDIA DE PING: ".[:tostr $avgLatency]."ms. PERDA DE PACOTES: ".[:tostr $lostAmountPingRequests]." POR CENTO. ENVIADO: ".$attemptPingsAmount." PINGs. RECEBIDO: ".$amountReceivedPingRequests." PINGs.") /tool fetch http-method=post http-content-type="application/json" http-data="{\"Receivers\":\"$receivers\",\"Content\":\"$content \",\"AuthKey\":\"$authKey\"}" url="https://sms.comtele.com.br/api/v2/bodysend" } } else={ :global linkStatus "LATENCIA ALTA" :if ($lastLinkStatus = $linkStatus) do={quit} else={ :log error $returnMessage :log error $linkStatus :global content ("LATENCIA DO ENLACE FORA DO LIMITE. MEDIA DE PING: ".[:tostr $avgLatency]."ms. PERDA DE PACOTES: ".[:tostr $lostAmountPingRequests]." POR CENTO. ENVIADO: ".$attemptPingsAmount." PINGs. RECEBIDO: ".$amountReceivedPingRequests." PINGs.") /tool fetch http-method=post http-content-type="application/json" http-data="{\"Receivers\":\"$receivers\",\"Content\":\"$content \",\"AuthKey\":\"$authKey\"}" url="https://sms.comtele.com.br/api/v2/bodysend" } }