Skip to content

Commit

Permalink
BGP RouterOS 6.x support (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Aug 11, 2024
1 parent ef471d9 commit 6e3ea42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mktxp/datasource/bgp_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


from mktxp.datasource.base_ds import BaseDSProcessor

from mktxp.datasource.system_resource_ds import SystemResourceMetricsDataSource
from mktxp.utils.utils import routerOS7_version

class BGPMetricsDataSource:
''' Wireless Metrics data provider
Expand All @@ -23,7 +24,14 @@ def metric_records(router_entry, *, metric_labels = None, translation_table = No
if metric_labels is None:
metric_labels = []
try:
bgp_records = router_entry.api_connection.router_api().get_resource('/routing/bgp/session').get()
bgp_routing_path = '/routing/bgp/session'

# legacy 6.x versions use a different path
ver = SystemResourceMetricsDataSource.os_version(router_entry)
if not routerOS7_version(ver):
bgp_routing_path = '/routing/bgp/peer'

bgp_records = router_entry.api_connection.router_api().get_resource(bgp_routing_path).get()
return BaseDSProcessor.trimmed_records(router_entry, router_records = bgp_records, metric_labels = metric_labels, translation_table = translation_table)
except Exception as exc:
print(f'Error getting BGP sessions info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
Expand Down
9 changes: 9 additions & 0 deletions mktxp/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def builtin_wifi_capsman_version(version):
print(f'could not get current RouterOS version, because: {err}')
return False

def routerOS7_version(version):
try:
cur_version, _ = parse_ros_version(version)
if cur_version >= parse('7.0'):
return True
except Exception as err:
print(f'could not get current RouterOS version, because: {err}')
return False

def check_for_updates(cur_version):
"""Try to check if there is a newer version available.
If anything goes wrong, it returns the same version.
Expand Down

0 comments on commit 6e3ea42

Please sign in to comment.