mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2026-02-04 23:46:06 +00:00
remote dhcp info resolution (wireless/capsman), more wifiwave2 support
This commit is contained in:
@@ -35,9 +35,8 @@ class CollectorHandler:
|
||||
Thus, the total runtime of this function scales linearly with the number of registered routers.
|
||||
"""
|
||||
for router_entry in self.entries_handler.router_entries:
|
||||
if not router_entry.api_connection.is_connected():
|
||||
if not router_entry.is_connected():
|
||||
# let's pick up on things in the next run
|
||||
router_entry.api_connection.connect()
|
||||
continue
|
||||
|
||||
for collector_ID, collect_func in self.collector_registry.registered_collectors.items():
|
||||
@@ -88,9 +87,8 @@ class CollectorHandler:
|
||||
print(f'Hit overall timeout while scraping router entry: {router_entry.router_id[MKTXPConfigKeys.ROUTERBOARD_NAME]}')
|
||||
break
|
||||
|
||||
if not router_entry.api_connection.is_connected():
|
||||
if not router_entry.is_connected():
|
||||
# let's pick up on things in the next run
|
||||
router_entry.api_connection.connect()
|
||||
continue
|
||||
|
||||
# Duration of individual scrapes
|
||||
|
||||
@@ -18,6 +18,8 @@ from collections import namedtuple
|
||||
from texttable import Texttable
|
||||
from humanize import naturaldelta
|
||||
from mktxp.cli.config.config import config_handler
|
||||
from mktxp.datasource.wireless_ds import WirelessMetricsDataSource
|
||||
from math import floor, log
|
||||
|
||||
|
||||
class BaseOutputProcessor:
|
||||
@@ -27,18 +29,23 @@ class BaseOutputProcessor:
|
||||
OutputWiFiEntry = namedtuple('OutputWiFiEntry', ['dhcp_name', 'dhcp_address', 'mac_address', 'signal_strength', 'signal_to_noise', 'interface', 'tx_rate', 'rx_rate', 'uptime'])
|
||||
OutputWiFiEntry.__new__.__defaults__ = ('',) * len(OutputWiFiEntry._fields)
|
||||
|
||||
OutputWiFiWave2Entry = namedtuple('OutputWiFiWave2Entry', ['dhcp_name', 'dhcp_address', 'mac_address', 'signal_strength', 'interface', 'tx_rate', 'rx_rate', 'uptime'])
|
||||
OutputWiFiWave2Entry.__new__.__defaults__ = ('',) * len(OutputWiFiWave2Entry._fields)
|
||||
|
||||
OutputDHCPEntry = namedtuple('OutputDHCPEntry', ['host_name', 'server', 'mac_address', 'address', 'active_address', 'expires_after'])
|
||||
OutputDHCPEntry.__new__.__defaults__ = ('',) * len(OutputDHCPEntry._fields)
|
||||
|
||||
@staticmethod
|
||||
def augment_record(router_entry, registration_record, dhcp_lease_records):
|
||||
try:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record.get('mac_address')==registration_record.get('mac_address')))
|
||||
dhcp_name = BaseOutputProcessor.dhcp_name(router_entry, dhcp_lease_record)
|
||||
dhcp_address = dhcp_lease_record.get('address', '')
|
||||
except StopIteration:
|
||||
dhcp_name = registration_record.get('mac_address')
|
||||
dhcp_address = 'No DHCP Record'
|
||||
dhcp_name = registration_record.get('mac_address')
|
||||
dhcp_address = 'No DHCP Record'
|
||||
if dhcp_lease_records:
|
||||
try:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record.get('mac_address')==registration_record.get('mac_address')))
|
||||
dhcp_name = BaseOutputProcessor.dhcp_name(router_entry, dhcp_lease_record)
|
||||
dhcp_address = dhcp_lease_record.get('address', '')
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
registration_record['dhcp_name'] = dhcp_name
|
||||
registration_record['dhcp_address'] = dhcp_address
|
||||
@@ -49,10 +56,13 @@ class BaseOutputProcessor:
|
||||
registration_record['rx_bytes'] = registration_record['bytes'].split(',')[1]
|
||||
del registration_record['bytes']
|
||||
|
||||
ww2_installed = WirelessMetricsDataSource.wifiwave2_installed(router_entry)
|
||||
if registration_record.get('tx_rate'):
|
||||
registration_record['tx_rate'] = BaseOutputProcessor.parse_rates(registration_record['tx_rate'])
|
||||
registration_record['tx_rate'] = BaseOutputProcessor.parse_bitrates(registration_record['tx_rate']) \
|
||||
if ww2_installed else BaseOutputProcessor.parse_rates(registration_record['tx_rate'])
|
||||
if registration_record.get('rx_rate'):
|
||||
registration_record['rx_rate'] = BaseOutputProcessor.parse_rates(registration_record['rx_rate'])
|
||||
registration_record['rx_rate'] = BaseOutputProcessor.parse_bitrates(registration_record['rx_rate']) \
|
||||
if ww2_installed else BaseOutputProcessor.parse_rates(registration_record['rx_rate'])
|
||||
if registration_record.get('uptime'):
|
||||
registration_record['uptime'] = naturaldelta(BaseOutputProcessor.parse_timedelta_seconds(registration_record['uptime']), months=True, minimum_unit='seconds')
|
||||
|
||||
@@ -87,6 +97,12 @@ class BaseOutputProcessor:
|
||||
rc = wifi_rates_rgx.search(rate)
|
||||
return f'{int(float(rc[1]))} {rc[2]}' if rc and len(rc.groups()) == 2 else rate
|
||||
|
||||
@staticmethod
|
||||
def parse_bitrates(rate):
|
||||
rate = int(rate)
|
||||
power = floor(log(rate, 1000))
|
||||
return f"{int(rate / 1000 ** power)} {['bps', 'Kbps', 'Mbps', 'Gbps'][int(power)]}"
|
||||
|
||||
@staticmethod
|
||||
def parse_timedelta(time):
|
||||
duration_interval_rgx = config_handler.re_compiled.get('duration_interval_rgx')
|
||||
@@ -126,6 +142,3 @@ class BaseOutputProcessor:
|
||||
table.header(outputEntry._fields)
|
||||
table.set_cols_align(['l']+ ['c']*(len(outputEntry._fields)-1))
|
||||
return table
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,19 +22,22 @@ class RouterEntriesHandler:
|
||||
def __init__(self):
|
||||
self.router_entries = []
|
||||
for router_name in config_handler.registered_entries():
|
||||
entry = config_handler.config_entry(router_name)
|
||||
if entry.enabled:
|
||||
self.router_entries.append(RouterEntry(router_name))
|
||||
router_entry = RouterEntriesHandler.router_entry(router_name, enabled_only = True)
|
||||
if router_entry:
|
||||
self.router_entries.append(router_entry)
|
||||
|
||||
@staticmethod
|
||||
def router_entry(entry_name, enabled_only = False):
|
||||
router_entry = None
|
||||
|
||||
for router_name in config_handler.registered_entries():
|
||||
if router_name == entry_name:
|
||||
if enabled_only:
|
||||
entry = config_handler.config_entry(router_name)
|
||||
if not entry.enabled:
|
||||
config_entry = config_handler.config_entry(router_name)
|
||||
if enabled_only and not config_entry.enabled:
|
||||
break
|
||||
|
||||
router_entry = RouterEntry(router_name)
|
||||
router_entry.dhcp_entry = RouterEntriesHandler.router_entry(config_entry.remote_dhcp_entry)
|
||||
break
|
||||
|
||||
return router_entry
|
||||
|
||||
@@ -27,7 +27,10 @@ class RouterEntry:
|
||||
MKTXPConfigKeys.ROUTERBOARD_NAME: self.router_name,
|
||||
MKTXPConfigKeys.ROUTERBOARD_ADDRESS: self.config_entry.hostname
|
||||
}
|
||||
|
||||
self.wifi_package = None
|
||||
self.dhcp_entry = None
|
||||
|
||||
self.time_spent = { 'IdentityCollector': 0,
|
||||
'SystemResourceCollector': 0,
|
||||
'HealthCollector': 0,
|
||||
@@ -49,4 +52,18 @@ class RouterEntry:
|
||||
'QueueSimpleCollector': 0,
|
||||
'UserCollector': 0,
|
||||
'MKTXPCollector': 0
|
||||
}
|
||||
}
|
||||
|
||||
def is_connected(self):
|
||||
connected = True
|
||||
if not self.api_connection.is_connected():
|
||||
connected = False
|
||||
# let's get connected now
|
||||
self.api_connection.connect()
|
||||
if self.dhcp_entry:
|
||||
self.dhcp_entry.api_connection.connect()
|
||||
|
||||
return connected
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user