From 79c3486305391332ca22f4edd22ba9bc02d2208e Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Sat, 2 Sep 2023 02:35:02 +0200 Subject: [PATCH] Increase timeout while getting wan traffic info --- README.md | 4 ++++ opnsense_exporter/opnsense_api.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9db402e..987968f 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ You can setup env through `.env` file or environment variables with defined as d ## Changelog +### Version 0.4.0 + +Higher timeout while getting WAN traffic info + ### Version 0.3.0 Use proper method to compute WAN traffic diff --git a/opnsense_exporter/opnsense_api.py b/opnsense_exporter/opnsense_api.py index c67b76a..fd61843 100644 --- a/opnsense_exporter/opnsense_api.py +++ b/opnsense_exporter/opnsense_api.py @@ -19,11 +19,11 @@ class OPNSenseAPI: def prepare_url(self, path): return f"https://{self.host}{path}" - def get(self, path): + def get(self, path, timeout=2): response = requests.get( self.prepare_url(path), auth=(self.login, self.password), - timeout=0.5, + timeout=timeout, # # as today I'm using the opnsense selfsigned certificat # # but we should avoid this instead trust any certificat verify=False, @@ -54,7 +54,7 @@ class OPNSenseAPI: def get_wan_trafic(self): try: - data = self.get("/api/diagnostics/traffic/top/wan") + data = self.get("/api/diagnostics/traffic/top/wan", timeout=15) except RequestException as ex: logger.error( "Get diagnostics traffic on WAN interface for %s host failed with the following error %r",