mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-10 01:14:33 +02:00
added sensors for rx/tx traffic per interface
This commit is contained in:
parent
e2c81c950f
commit
f6bcfcb528
3 changed files with 131 additions and 0 deletions
|
@ -231,3 +231,36 @@ class MikrotikAPI:
|
|||
raise ApiEntryNotFound(error)
|
||||
|
||||
return True
|
||||
|
||||
# ---------------------------
|
||||
# get_traffic
|
||||
# ---------------------------
|
||||
def get_traffic(self, interfaces):
|
||||
"""Get traffic stats"""
|
||||
traffic = None
|
||||
if not self._connected or not self._connection:
|
||||
if not self.connect():
|
||||
return None
|
||||
|
||||
response = self.path('/interface')
|
||||
if response is None:
|
||||
return None
|
||||
|
||||
args = {'interface': interfaces, 'once': True}
|
||||
try:
|
||||
traffic = response('monitor-traffic', **args)
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self._connected = False
|
||||
self._connection = None
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
|
||||
return traffic
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue