Increase timeout while getting wan traffic info

This commit is contained in:
Pierre Verkest 2023-09-02 02:35:02 +02:00
parent 6771b39d76
commit 79c3486305
2 changed files with 7 additions and 3 deletions

View file

@ -88,6 +88,10 @@ You can setup env through `.env` file or environment variables with defined as d
## Changelog ## Changelog
### Version 0.4.0
Higher timeout while getting WAN traffic info
### Version 0.3.0 ### Version 0.3.0
Use proper method to compute WAN traffic Use proper method to compute WAN traffic

View file

@ -19,11 +19,11 @@ class OPNSenseAPI:
def prepare_url(self, path): def prepare_url(self, path):
return f"https://{self.host}{path}" return f"https://{self.host}{path}"
def get(self, path): def get(self, path, timeout=2):
response = requests.get( response = requests.get(
self.prepare_url(path), self.prepare_url(path),
auth=(self.login, self.password), auth=(self.login, self.password),
timeout=0.5, timeout=timeout,
# # as today I'm using the opnsense selfsigned certificat # # as today I'm using the opnsense selfsigned certificat
# # but we should avoid this instead trust any certificat # # but we should avoid this instead trust any certificat
verify=False, verify=False,
@ -54,7 +54,7 @@ class OPNSenseAPI:
def get_wan_trafic(self): def get_wan_trafic(self):
try: try:
data = self.get("/api/diagnostics/traffic/top/wan") data = self.get("/api/diagnostics/traffic/top/wan", timeout=15)
except RequestException as ex: except RequestException as ex:
logger.error( logger.error(
"Get diagnostics traffic on WAN interface for %s host failed with the following error %r", "Get diagnostics traffic on WAN interface for %s host failed with the following error %r",