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