This commit is contained in:
Cory Hawkless 2022-10-12 16:53:37 +10:30
parent 0942fb46fb
commit 676fd65862
1 changed files with 37 additions and 36 deletions

View File

@ -6,7 +6,7 @@ from telnetlib import theNULL
import pingparsing
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
import logging
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.WARN)
import os
from slack import WebClient
@ -26,58 +26,59 @@ def slack_message(message, channel):
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found'
# tests={
# "1": {
# 'dest': "10.90.1.254",
# 'name': 'Runpod GW',
# 'packet_loss_rate_permitted': 100,
# 'rtt_max_permitted': 5,
# },
# "2": {
# 'dest': "149.36.0.254",
# 'name': 'Nexgen Fortigate',
# 'packet_loss_rate_permitted': 0,
# 'rtt_max_permitted': 5,
# },
# "3": {
# 'dest': "217.17.208.20",
# 'name': 'First Hop',
# 'packet_loss_rate_permitted': 0,
# 'rtt_max_permitted': 20,
# },
# }
tests_prod={
"1": {
'dest': "10.90.1.254",
'name': 'Runpod GW',
'packet_loss_rate_permitted': 100,
'rtt_avg_permitted': 5,
},
"2": {
'dest': "149.36.0.254",
'name': 'Nexgen Fortigate',
'packet_loss_rate_permitted': 0,
'rtt_avg_permitted': 5,
},
"3": {
'dest': "217.17.208.20",
'name': 'First Hop',
'packet_loss_rate_permitted': 0,
'rtt_avg_permitted': 20,
},
}
tests={
tests_dev={
"1": {
'dest': "66.29.128.140",
'name': 'African webserver',
'packet_loss_rate_permitted': 50,
'rtt_max_permitted': 150,
'rtt_avg_permitted': 150,
},
"2": {
'dest': "8.8.8.8",
'name': 'Google DNS',
'packet_loss_rate_permitted': 0,
'rtt_max_permitted': 150,
'rtt_avg_permitted': 150,
},
"3": {
'dest': "1.1.1.1",
'name': 'Cloudflare DNS',
'packet_loss_rate_permitted': 0,
'rtt_max_permitted': 150,
'rtt_avg_permitted': 150,
},
}
tests=tests_dev
def pinger(test_id):
print("Testing {} on IP {} with RTT threshold of {} and packet loss max of {}".format(
print("Testing {} on IP {} with RTT Avg threshold of {} and packet loss max of {}".format(
tests[test_id]['name'],tests[test_id]['dest'],
tests[test_id]['rtt_max_permitted'],tests[test_id]['packet_loss_rate_permitted']))
tests[test_id]['rtt_avg_permitted'],tests[test_id]['packet_loss_rate_permitted']))
dest=tests[test_id]['dest']
name=tests[test_id]['name']
rtt_max_permitted=tests[test_id]['rtt_max_permitted']
rtt_avg_permitted=tests[test_id]['rtt_avg_permitted']
packet_loss_rate_permitted=tests[test_id]['packet_loss_rate_permitted']
ping_parser = pingparsing.PingParsing()
@ -90,12 +91,12 @@ def pinger(test_id):
result = transmitter.ping()
data=ping_parser.parse(result).as_dict()
packet_loss_rate=data["packet_loss_rate"]
rtt_max=data["rtt_max"]
rtt_avg=data["rtt_avg"]
notify=0
print("Dest: {} Loss: {}% RTT: {}ms".format(dest,packet_loss_rate,rtt_max))
if rtt_max>rtt_max_permitted:
error_msg="ERROR: rtt_max_permitted exceeded!"
print("Dest: {} Loss: {}% RTT: {}ms".format(dest,packet_loss_rate,rtt_avg))
if rtt_avg>rtt_avg_permitted:
error_msg="ERROR: rtt_avg_permitted exceeded!"
notify=1
if packet_loss_rate>packet_loss_rate_permitted:
@ -113,9 +114,9 @@ def pinger(test_id):
g_pl = Gauge('packet_loss_rate', 'Amt of packet loss', ['destination_ip'],registry=registry )
g_pl.labels(dest).set(packet_loss_rate)
if not type(rtt_max)=="NoneType":
g_rtt = Gauge('rtt_max', 'Round trip time', ['destination_ip'],registry=registry )
g_rtt.labels(dest).set(rtt_max)
if not type(rtt_avg)=="NoneType":
g_rtt = Gauge('rtt_avg', 'Round trip time', ['destination_ip'],registry=registry )
g_rtt.labels(dest).set(rtt_avg)
push_to_gateway('10.10.110.250:9091', job='cory_test_job1', registry=registry)