mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
bug fixes
This commit is contained in:
@@ -24,7 +24,7 @@ class IPConnectionCollector(BaseCollector):
|
|||||||
if not router_entry.config_entry.connections:
|
if not router_entry.config_entry.connections:
|
||||||
return
|
return
|
||||||
|
|
||||||
connection_records = IPConnectionDatasource.metric_records(router_entry, metric_labels = [])
|
connection_records = IPConnectionDatasource.metric_records(router_entry)
|
||||||
if connection_records:
|
if connection_records:
|
||||||
|
|
||||||
connection_metrics = BaseCollector.gauge_collector('ip_connections_total', 'Number of IP connections', connection_records, 'count',)
|
connection_metrics = BaseCollector.gauge_collector('ip_connections_total', 'Number of IP connections', connection_records, 'count',)
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ class BaseDSProcessor:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def trimmed_records(router_entry, *, router_records = [], metric_labels = [], add_router_id = True, translation_table = {}):
|
def trimmed_records(router_entry, *, router_records = None, metric_labels = None, add_router_id = True, translation_table = None):
|
||||||
|
if router_records is None:
|
||||||
|
router_records = []
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
|
if translation_table is None:
|
||||||
|
translation_table = {}
|
||||||
dash2_ = lambda x : x.replace('-', '_')
|
dash2_ = lambda x : x.replace('-', '_')
|
||||||
if len(metric_labels) == 0 and len(router_records) > 0:
|
if len(metric_labels) == 0 and len(router_records) > 0:
|
||||||
metric_labels = [dash2_(key) for key in router_records[0].keys()]
|
metric_labels = [dash2_(key) for key in router_records[0].keys()]
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class CapsmanCapsMetricsDataSource:
|
|||||||
''' Caps Metrics data provider
|
''' Caps Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
remote_caps_records = router_entry.api_connection.router_api().get_resource('/caps-man/remote-cap').get()
|
remote_caps_records = router_entry.api_connection.router_api().get_resource('/caps-man/remote-cap').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = remote_caps_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = remote_caps_records, metric_labels = metric_labels)
|
||||||
@@ -32,7 +34,9 @@ class CapsmanRegistrationsMetricsDataSource:
|
|||||||
''' Capsman Registrations Metrics data provider
|
''' Capsman Registrations Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = [], add_router_id = True):
|
def metric_records(router_entry, *, metric_labels = None, add_router_id = True):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
registration_table_records = router_entry.api_connection.router_api().get_resource('/caps-man/registration-table').get()
|
registration_table_records = router_entry.api_connection.router_api().get_resource('/caps-man/registration-table').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class IPConnectionDatasource:
|
|||||||
''' IP connections data provider
|
''' IP connections data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
answer = router_entry.api_connection.router_api().get_binary_resource('/ip/firewall/connection/').call('print', {'count-only': b''})
|
answer = router_entry.api_connection.router_api().get_binary_resource('/ip/firewall/connection/').call('print', {'count-only': b''})
|
||||||
# answer looks and feels like an empty list: [], but it has a special attribute `done_message`
|
# answer looks and feels like an empty list: [], but it has a special attribute `done_message`
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ class DHCPMetricsDataSource:
|
|||||||
''' DHCP Metrics data provider
|
''' DHCP Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = [], add_router_id = True):
|
def metric_records(router_entry, *, metric_labels = None, add_router_id = True):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
#dhcp_lease_records = router_entry.api_connection.router_api().get_resource('/ip/dhcp-server/lease').get(status='bound')
|
#dhcp_lease_records = router_entry.api_connection.router_api().get_resource('/ip/dhcp-server/lease').get(status='bound')
|
||||||
dhcp_lease_records = router_entry.api_connection.router_api().get_resource('/ip/dhcp-server/lease').call('print', {'active':''})
|
dhcp_lease_records = router_entry.api_connection.router_api().get_resource('/ip/dhcp-server/lease').call('print', {'active':''})
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class FirewallMetricsDataSource:
|
|||||||
''' Firewall Metrics data provider
|
''' Firewall Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = [], raw = False, matching_only = True):
|
def metric_records(router_entry, *, metric_labels = None, raw = False, matching_only = True):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
filter_path = '/ip/firewall/filter' if not raw else '/ip/firewall/raw'
|
filter_path = '/ip/firewall/filter' if not raw else '/ip/firewall/raw'
|
||||||
firewall_records = router_entry.api_connection.router_api().get_resource(filter_path).call('print', {'stats':'', 'all':''})
|
firewall_records = router_entry.api_connection.router_api().get_resource(filter_path).call('print', {'stats':'', 'all':''})
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class HealthMetricsDataSource:
|
|||||||
''' Health Metrics data provider
|
''' Health Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
health_records = router_entry.api_connection.router_api().get_resource('/system/health').get()
|
health_records = router_entry.api_connection.router_api().get_resource('/system/health').get()
|
||||||
for record in health_records:
|
for record in health_records:
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class IdentityMetricsDataSource:
|
|||||||
''' Identity Metrics data provider
|
''' Identity Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
identity_records = router_entry.api_connection.router_api().get_resource('/system/identity').get()
|
identity_records = router_entry.api_connection.router_api().get_resource('/system/identity').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = identity_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = identity_records, metric_labels = metric_labels)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class InterfaceTrafficMetricsDataSource:
|
|||||||
''' Interface Traffic Metrics data provider
|
''' Interface Traffic Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
traffic_records = router_entry.api_connection.router_api().get_resource('/interface').get(running='yes', disabled='no')
|
traffic_records = router_entry.api_connection.router_api().get_resource('/interface').get(running='yes', disabled='no')
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = traffic_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = traffic_records, metric_labels = metric_labels)
|
||||||
@@ -32,7 +34,9 @@ class InterfaceMonitorMetricsDataSource:
|
|||||||
''' Interface Monitor Metrics data provider
|
''' Interface Monitor Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = [], kind = 'ethernet', include_comments = False, running_only = True):
|
def metric_records(router_entry, *, metric_labels = None, kind = 'ethernet', include_comments = False, running_only = True):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
interfaces = router_entry.api_connection.router_api().get_resource(f'/interface/{kind}').get()
|
interfaces = router_entry.api_connection.router_api().get_resource(f'/interface/{kind}').get()
|
||||||
interface_names = [(interface['name'], interface.get('comment'), interface.get('running')) for interface in interfaces]
|
interface_names = [(interface['name'], interface.get('comment'), interface.get('running')) for interface in interfaces]
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class NetwatchMetricsDataSource:
|
|||||||
''' Netwatch Metrics data provider
|
''' Netwatch Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
netwatch_records = router_entry.api_connection.router_api().get_resource('/tool/netwatch').get(disabled='false')
|
netwatch_records = router_entry.api_connection.router_api().get_resource('/tool/netwatch').get(disabled='false')
|
||||||
if 'name' in metric_labels:
|
if 'name' in metric_labels:
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class POEMetricsDataSource:
|
|||||||
''' POE Metrics data provider
|
''' POE Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, include_comments = False, metric_labels = []):
|
def metric_records(router_entry, *, include_comments = False, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
poe_records = router_entry.api_connection.router_api().get_resource('/interface/ethernet/poe').get()
|
poe_records = router_entry.api_connection.router_api().get_resource('/interface/ethernet/poe').get()
|
||||||
for int_num, poe_record in enumerate(poe_records):
|
for int_num, poe_record in enumerate(poe_records):
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class PoolMetricsDataSource:
|
|||||||
''' Pool Metrics data provider
|
''' Pool Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
pool_records = router_entry.api_connection.router_api().get_resource('/ip/pool').get()
|
pool_records = router_entry.api_connection.router_api().get_resource('/ip/pool').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = pool_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = pool_records, metric_labels = metric_labels)
|
||||||
@@ -32,7 +34,9 @@ class PoolUsedMetricsDataSource:
|
|||||||
''' Pool/Used Metrics data provider
|
''' Pool/Used Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
pool_used_records = router_entry.api_connection.router_api().get_resource('/ip/pool/used').get()
|
pool_used_records = router_entry.api_connection.router_api().get_resource('/ip/pool/used').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = pool_used_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = pool_used_records, metric_labels = metric_labels)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class RouteMetricsDataSource:
|
|||||||
''' Routes Metrics data provider
|
''' Routes Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
route_records = router_entry.api_connection.router_api().get_resource('/ip/route').get(active='yes')
|
route_records = router_entry.api_connection.router_api().get_resource('/ip/route').get(active='yes')
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = route_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = route_records, metric_labels = metric_labels)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class RouterboardMetricsDataSource:
|
|||||||
''' Routerboard Metrics data provider
|
''' Routerboard Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
routerboard_records = router_entry.api_connection.router_api().get_resource('/system/routerboard').get()
|
routerboard_records = router_entry.api_connection.router_api().get_resource('/system/routerboard').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = routerboard_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = routerboard_records, metric_labels = metric_labels)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class SystemResourceMetricsDataSource:
|
|||||||
''' System Resource Metrics data provider
|
''' System Resource Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = None):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
system_resource_records = router_entry.api_connection.router_api().get_resource('/system/resource').get()
|
system_resource_records = router_entry.api_connection.router_api().get_resource('/system/resource').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = system_resource_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = system_resource_records, metric_labels = metric_labels)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class WirelessMetricsDataSource:
|
|||||||
''' Wireless Metrics data provider
|
''' Wireless Metrics data provider
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = [], add_router_id = True):
|
def metric_records(router_entry, *, metric_labels = None, add_router_id = True):
|
||||||
|
if metric_labels is None:
|
||||||
|
metric_labels = []
|
||||||
try:
|
try:
|
||||||
registration_table_records = router_entry.api_connection.router_api().get_resource('/interface/wireless/registration-table').get()
|
registration_table_records = router_entry.api_connection.router_api().get_resource('/interface/wireless/registration-table').get()
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user