mirror of
				https://github.com/KevinMidboe/mktxp-no-cli.git
				synced 2025-10-29 17:50:23 +00:00 
			
		
		
		
	initial WifiWave2 support+installed packages collector
This commit is contained in:
		| @@ -36,6 +36,7 @@ class MKTXPConfigKeys: | ||||
|     NO_SSL_CERTIFICATE = 'no_ssl_certificate' | ||||
|     SSL_CERTIFICATE_VERIFY = 'ssl_certificate_verify' | ||||
|  | ||||
|     FE_PACKAGE_KEY = 'installed_packages' | ||||
|     FE_DHCP_KEY = 'dhcp' | ||||
|     FE_DHCP_LEASE_KEY = 'dhcp_lease'     | ||||
|     FE_DHCP_POOL_KEY = 'pool'     | ||||
| @@ -87,7 +88,7 @@ class MKTXPConfigKeys: | ||||
|     BOOLEAN_KEYS_NO = {ENABLED_KEY, SSL_KEY, NO_SSL_CERTIFICATE, SSL_CERTIFICATE_VERIFY, FE_IPV6_FIREWALL_KEY, FE_IPV6_NEIGHBOR_KEY} | ||||
|      | ||||
|     # Feature keys enabled by default | ||||
|     BOOLEAN_KEYS_YES = {FE_DHCP_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_IP_CONNECTIONS_KEY, FE_INTERFACE_KEY, FE_FIREWALL_KEY, | ||||
|     BOOLEAN_KEYS_YES = {FE_DHCP_KEY, FE_PACKAGE_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_IP_CONNECTIONS_KEY, FE_INTERFACE_KEY, FE_FIREWALL_KEY, | ||||
|                       FE_MONITOR_KEY, FE_ROUTE_KEY, MKTXP_USE_COMMENTS_OVER_NAMES,  | ||||
|                       FE_WIRELESS_KEY, FE_WIRELESS_CLIENTS_KEY, FE_CAPSMAN_KEY, FE_CAPSMAN_CLIENTS_KEY, FE_POE_KEY, | ||||
|                       FE_NETWATCH_KEY, FE_PUBLIC_IP_KEY}  | ||||
| @@ -106,11 +107,10 @@ class ConfigEntry: | ||||
|     MKTXPConfigEntry = namedtuple('MKTXPConfigEntry', [MKTXPConfigKeys.ENABLED_KEY, MKTXPConfigKeys.HOST_KEY, MKTXPConfigKeys.PORT_KEY, | ||||
|                                                  MKTXPConfigKeys.USER_KEY, MKTXPConfigKeys.PASSWD_KEY, | ||||
|                                                  MKTXPConfigKeys.SSL_KEY, MKTXPConfigKeys.NO_SSL_CERTIFICATE, MKTXPConfigKeys.SSL_CERTIFICATE_VERIFY, | ||||
|  | ||||
|                                                  MKTXPConfigKeys.FE_DHCP_KEY, MKTXPConfigKeys.FE_DHCP_LEASE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_INTERFACE_KEY, MKTXPConfigKeys.FE_FIREWALL_KEY, | ||||
|                                                  MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY, MKTXPConfigKeys.FE_IP_CONNECTIONS_KEY, | ||||
|                                                  MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY, MKTXPConfigKeys.FE_POE_KEY, MKTXPConfigKeys.FE_NETWATCH_KEY, MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, | ||||
|                                                  MKTXPConfigKeys.FE_PUBLIC_IP_KEY, MKTXPConfigKeys.FE_IPV6_FIREWALL_KEY, MKTXPConfigKeys.FE_IPV6_NEIGHBOR_KEY | ||||
|                                                  MKTXPConfigKeys.FE_DHCP_KEY, MKTXPConfigKeys.FE_PACKAGE_KEY, MKTXPConfigKeys.FE_DHCP_LEASE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_INTERFACE_KEY,  | ||||
|                                                  MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY,  | ||||
|                                                  MKTXPConfigKeys.FE_IP_CONNECTIONS_KEY, MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY, MKTXPConfigKeys.FE_POE_KEY, MKTXPConfigKeys.FE_NETWATCH_KEY,  | ||||
|                                                  MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, MKTXPConfigKeys.FE_PUBLIC_IP_KEY, MKTXPConfigKeys.FE_IPV6_FIREWALL_KEY, MKTXPConfigKeys.FE_IPV6_NEIGHBOR_KEY | ||||
|                                                  ]) | ||||
|     MKTXPSystemEntry = namedtuple('MKTXPSystemEntry', [MKTXPConfigKeys.PORT_KEY, MKTXPConfigKeys.MKTXP_SOCKET_TIMEOUT, | ||||
|                                                   MKTXPConfigKeys.MKTXP_INITIAL_DELAY, MKTXPConfigKeys.MKTXP_MAX_DELAY, | ||||
|   | ||||
| @@ -24,6 +24,7 @@ | ||||
|     no_ssl_certificate = False      # enables API_SSL connect without router SSL certificate | ||||
|     ssl_certificate_verify = False  # turns SSL certificate verification on / off    | ||||
|  | ||||
|     installed_packages = True       # Installed packages | ||||
|     dhcp = True                     # DHCP general metrics | ||||
|     dhcp_lease = True               # DHCP lease metrics | ||||
|     connections = True              # IP connections metrics | ||||
|   | ||||
							
								
								
									
										31
									
								
								mktxp/collector/package_collector.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								mktxp/collector/package_collector.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| # coding=utf8 | ||||
| ## Copyright (c) 2020 Arseniy Kuznetsov | ||||
| ## | ||||
| ## This program is free software; you can redistribute it and/or | ||||
| ## modify it under the terms of the GNU General Public License | ||||
| ## as published by the Free Software Foundation; either version 2 | ||||
| ## of the License, or (at your option) any later version. | ||||
| ## | ||||
| ## This program is distributed in the hope that it will be useful, | ||||
| ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| ## GNU General Public License for more details. | ||||
|  | ||||
|  | ||||
| from mktxp.collector.base_collector import BaseCollector | ||||
| from mktxp.datasource.package_ds import PackageMetricsDataSource | ||||
|  | ||||
|  | ||||
| class PackageCollector(BaseCollector): | ||||
|     '''Installed Packages collector''' | ||||
|     @staticmethod | ||||
|     def collect(router_entry): | ||||
|         if not router_entry.config_entry.installed_packages: | ||||
|             return | ||||
|  | ||||
|         package_labels = ['name', 'version', 'build_time', 'disabled'] | ||||
|         package_records = PackageMetricsDataSource.metric_records(router_entry, metric_labels=package_labels) | ||||
|         if package_records: | ||||
|             package_metrics = BaseCollector.info_collector('installed_packages', 'Installed Packages', package_records, package_labels) | ||||
|             yield package_metrics | ||||
|  | ||||
| @@ -13,7 +13,6 @@ | ||||
|  | ||||
|  | ||||
| from mktxp.collector.base_collector import BaseCollector | ||||
| from mktxp.flow.processor.output import BaseOutputProcessor | ||||
| from mktxp.datasource.poe_ds import POEMetricsDataSource | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -28,7 +28,7 @@ class WLANCollector(BaseCollector): | ||||
|             return | ||||
|  | ||||
|         monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq', 'registered_clients'] | ||||
|         monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, kind = 'wireless')    | ||||
|         monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, kind = WirelessMetricsDataSource.wireless_package(router_entry))    | ||||
|         if monitor_records: | ||||
|             # sanitize records for relevant labels | ||||
|             noise_floor_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('noise_floor')] | ||||
| @@ -78,4 +78,3 @@ class WLANCollector(BaseCollector): | ||||
|                 yield registration_metrics | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
							
								
								
									
										43
									
								
								mktxp/datasource/package_ds.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								mktxp/datasource/package_ds.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| # coding=utf8 | ||||
| ## Copyright (c) 2020 Arseniy Kuznetsov | ||||
| ## | ||||
| ## This program is free software; you can redistribute it and/or | ||||
| ## modify it under the terms of the GNU General Public License | ||||
| ## as published by the Free Software Foundation; either version 2 | ||||
| ## of the License, or (at your option) any later version. | ||||
| ## | ||||
| ## This program is distributed in the hope that it will be useful, | ||||
| ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| ## GNU General Public License for more details. | ||||
|  | ||||
|  | ||||
| from mktxp.datasource.base_ds import BaseDSProcessor | ||||
|  | ||||
|  | ||||
| class PackageMetricsDataSource: | ||||
|     ''' Wireless Metrics data provider | ||||
|     '''              | ||||
|     @staticmethod | ||||
|     def metric_records(router_entry, *, metric_labels = None, add_router_id = True): | ||||
|         if metric_labels is None: | ||||
|             metric_labels = []                 | ||||
|         try: | ||||
|             package_records = router_entry.api_connection.router_api().get_resource('/system/package').get() | ||||
|             return BaseDSProcessor.trimmed_records(router_entry, router_records = package_records, metric_labels = metric_labels, add_router_id = add_router_id) | ||||
|         except Exception as exc: | ||||
|             print(f'Error getting installed packages info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') | ||||
|             return None | ||||
|  | ||||
|  | ||||
|     @staticmethod | ||||
|     def is_package_installed (router_entry, package_name = ''): | ||||
|         if package_name: | ||||
|             try: | ||||
|                 package_records = router_entry.api_connection.router_api().get_resource('/system/package').get() | ||||
|                 for package_record in package_records: | ||||
|                     if package_record['name'] == package_name: | ||||
|                         return True | ||||
|             except Exception as exc: | ||||
|                 print(f'Error getting installed packages info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')         | ||||
|         return False | ||||
| @@ -13,6 +13,7 @@ | ||||
|  | ||||
|  | ||||
| from mktxp.datasource.base_ds import BaseDSProcessor | ||||
| from mktxp.datasource.package_ds import PackageMetricsDataSource | ||||
|  | ||||
|  | ||||
| class WirelessMetricsDataSource: | ||||
| @@ -23,10 +24,14 @@ class WirelessMetricsDataSource: | ||||
|         if metric_labels is None: | ||||
|             metric_labels = []                 | ||||
|         try: | ||||
|             registration_table_records = router_entry.api_connection.router_api().get_resource('/interface/wireless/registration-table').get() | ||||
|             wireless_package = WirelessMetricsDataSource.wireless_package(router_entry) | ||||
|             registration_table_records = router_entry.api_connection.router_api().get_resource(f'/interface/{wireless_package}/registration-table').get() | ||||
|             return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id) | ||||
|         except Exception as exc: | ||||
|             print(f'Error getting wireless registration table info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') | ||||
|             return None | ||||
|  | ||||
|  | ||||
|     @staticmethod | ||||
|     def wireless_package(router_entry): | ||||
|         return 'wifiwave2' if PackageMetricsDataSource.is_package_installed(router_entry, package_name = 'wifiwave2') else 'wireless' | ||||
|   | ||||
| @@ -14,6 +14,7 @@ | ||||
|  | ||||
| from collections import OrderedDict | ||||
| from mktxp.collector.dhcp_collector import DHCPCollector | ||||
| from mktxp.collector.package_collector import PackageCollector | ||||
| from mktxp.collector.connection_collector import IPConnectionCollector | ||||
| from mktxp.collector.interface_collector import InterfaceCollector | ||||
| from mktxp.collector.health_collector import HealthCollector | ||||
| @@ -49,6 +50,7 @@ class CollectorRegistry: | ||||
|  | ||||
|         self.register('IPv6NeighborCollector', IPv6NeighborCollector.collect) | ||||
|  | ||||
|         self.register('PackageCollector', PackageCollector.collect) | ||||
|         self.register('DHCPCollector', DHCPCollector.collect) | ||||
|         self.register('IPConnectionCollector', IPConnectionCollector.collect) | ||||
|         self.register('PoolCollector', PoolCollector.collect) | ||||
|   | ||||
| @@ -32,6 +32,7 @@ class RouterEntry: | ||||
|                             'HealthCollector': 0, | ||||
|                             'PublicIPAddressCollector': 0, | ||||
|                             'IPv6NeighborCollector': 0, | ||||
|                             'PackageCollector': 0, | ||||
|                             'DHCPCollector': 0, | ||||
|                             'PoolCollector': 0, | ||||
|                             'IPConnectionCollector': 0, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user