Add ability to automatically determine if the LAN accounting sensor should be created depending on account-local-traffic in Mikrotik API

This commit is contained in:
Ivan Pavlina 2020-04-05 15:03:17 +02:00
parent 30c11db741
commit f9a458bbfb
4 changed files with 44 additions and 26 deletions

View file

@ -488,7 +488,7 @@ class MikrotikAPI:
from time import time
return int(round(time() * 1000))
def is_accounting_enabled(self):
def is_accounting_enabled(self) -> bool:
accounting = self.path("/ip/accounting", return_list=True)
if accounting is None:
return False
@ -500,6 +500,18 @@ class MikrotikAPI:
return True
return False
def is_accounting_local_traffic_enabled(self) -> bool:
accounting = self.path("/ip/accounting", return_list=True)
if accounting is None:
return False
for item in accounting:
if 'account-local-traffic' not in item:
continue
if item['account-local-traffic']:
return True
return False
# ---------------------------
# take_accounting_snapshot
# Returns float -> seconds period between last run and current run