Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing after upgrading RouterOS to 7.18 #229

Open
emx0r opened this issue Feb 25, 2025 · 4 comments
Open

Failing after upgrading RouterOS to 7.18 #229

emx0r opened this issue Feb 25, 2025 · 4 comments

Comments

@emx0r
Copy link

emx0r commented Feb 25, 2025

2025-02-25 17:28:44 Connection to router [email protected] has been established
Error getting IPv4 pool used info from router [email protected]: ('Malformed sentence %s', [b'!empty', b'.tag=10'])
Traceback (most recent call last):
File "/usr/local/bin/mktxp", line 8, in
sys.exit(main())
^^^^^^
File "/usr/local/lib/python3.12/site-packages/mktxp/cli/dispatch.py", line 108, in main
MKTXPDispatcher().dispatch()
File "/usr/local/lib/python3.12/site-packages/mktxp/cli/dispatch.py", line 39, in dispatch
self.start_export(args)
File "/usr/local/lib/python3.12/site-packages/mktxp/cli/dispatch.py", line 89, in start_export
ExportProcessor.start()
File "/usr/local/lib/python3.12/site-packages/mktxp/flow/processor/base_proc.py", line 37, in start
REGISTRY.register(CollectorHandler(RouterEntriesHandler(), CollectorRegistry()))
File "/usr/local/lib/python3.12/site-packages/prometheus_client/registry.py", line 40, in register
names = self._get_names(collector)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prometheus_client/registry.py", line 80, in _get_names
for metric in desc_func():

@dannwoodcock
Copy link

I am also having failures on a Hex and CCR1009-7G-1C-1S+

Exception happened during processing of request from ('172.19.0.1', 46336)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/socketserver.py", line 316, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/local/lib/python3.8/socketserver.py", line 347, in process_request
self.finish_request(request, client_address)
File "/usr/local/lib/python3.8/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python3.8/socketserver.py", line 747, in init
self.handle()
File "/usr/local/lib/python3.8/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/local/lib/python3.8/http/server.py", line 415, in handle_one_request
method()
File "/usr/local/lib/python3.8/site-packages/prometheus_client/exposition.py", line 278, in do_GET
status, headers, output = _bake_output(registry, accept_header, accept_encoding_header, params, False)
File "/usr/local/lib/python3.8/site-packages/prometheus_client/exposition.py", line 104, in _bake_output
output = encoder(registry)
File "/usr/local/lib/python3.8/site-packages/prometheus_client/openmetrics/exposition.py", line 21, in generate_latest
for metric in registry.collect():
File "/usr/local/lib/python3.8/site-packages/prometheus_client/registry.py", line 97, in collect
yield from collector.collect()
File "/usr/local/lib/python3.8/site-packages/mktxp/flow/collector_handler.py", line 36, in collect
yield from collect_func(router_entry)
File "/usr/local/lib/python3.8/site-packages/mktxp/collector/pool_collector.py", line 36, in collect
for pool_used_record in pool_used_records:
TypeError: 'NoneType' object is not iterable

@baubukas
Copy link

There are different "checks" which are failing with ROS 7.18:

Error getting system health info from router xxxx: ('Malformed sentence %s', [b'!empty', b'.tag=4'])
Error getting dhcp info from router xxxx: ('Malformed sentence %s', [b'!empty', b'.tag=9'])
Error getting Neighbors info from router xxxxx: ('Malformed sentence %s', [b'!empty', b'.tag=6'])
Error getting IPv4 firewall filters info from router xxxx: ('Malformed sentence %s', [b'!empty', b'.tag=13'])

@akpw
Copy link
Owner

akpw commented Feb 28, 2025

Upon a quick look, looks like the exception is from the RouterOS-api and it seems to happen whenever an API call returns an empty response from a RouterOS device.

Probably due to a change in the format in one of the latest RouterOS versions, not yet reflected in the library.

Here is a quick way to see what happening:

import routeros_api
if __name__ == '__main__':
    host = 'xx.xx.xx.xx'
    
    port = 8728
    use_ssl = False
    connection = routeros_api.RouterOsApiPool(
            host = host,
            username = '.....',
            password='.....',
            port=port,
            plaintext_login = True,
            use_ssl = use_ssl,
            ssl_verify=False
            )   
    api = connection.get_api()

    users = api.get_resource('/user/active/').get() # works
    print(f'active users: {users}\n')

    pools = api.get_resource('/ip/pool').get() # Works if some record exists, breaks if it does not
    for pool in pools:
        print(pool)    

    dhcp = api.get_resource('/ip/dhcp-server/lease').get(status='bound') # Works if some record exists, breaks if it does not
    print(f'dhcp: {dhcp}\n')

    bgp_sessions = api.get_resource('/routing/bgp/session').get() # ...
    print(bgp_sessions)

A quick workaround for now could be disabling the mktxp.conf features that do not return any records.

dhcp = False                     # DHCP general metrics
pool = False                     # IPv4 Pool metrics
...

@dginhoux
Copy link

https://forum.mikrotik.com/viewtopic.php?t=215048#p1129769

This come from this change : "*) console - put !empty sentence when API query returns nothing;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants