-
Notifications
You must be signed in to change notification settings - Fork 0
/
netprobe.py
57 lines (38 loc) · 1.53 KB
/
netprobe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Netprobe Service
import time
from helpers.network_helper import *
from helpers.http_helper import *
from helpers.redis_helper import *
from config import Config_Netprobe
from datetime import datetime,timezone
from helpers.logging_helper import *
if __name__ == '__main__':
# Global Variables
probe_interval = Config_Netprobe.probe_interval
probe_count = Config_Netprobe.probe_count
sites = Config_Netprobe.sites
device_id = Config_Netprobe.device_id
site_id = Config_Netprobe.site_id
dns_test_site = Config_Netprobe.dns_test_site
nameservers_external = Config_Netprobe.nameservers
collector = NetworkCollector(sites,probe_count,device_id,site_id,dns_test_site,nameservers_external)
# Logging Config
logger = setup_logging("logs/netprobe.log")
while True:
try:
stats = collector.collect()
current_time = datetime.now()
except:
print("Error testing network")
logger.error("Error testing network")
continue
# Connect to Redis
try:
cache = RedisConnect()
# Save Data to Redis
cache.redis_write(device_id,json.dumps(stats),45) # Store data with TTL 45s, which means when the probe goes down the key ages out
logger.info(f"Stats successfully written to Redis from device ID {device_id}")
except Exception as e:
logger.error("Could not connect to Redis")
logger.debug(exc_info=1)
time.sleep(probe_interval)