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

Mikrotik version > 6.48 = 'export' command incomplete #3405

Open
prtomasi opened this issue Mar 19, 2024 · 3 comments
Open

Mikrotik version > 6.48 = 'export' command incomplete #3405

prtomasi opened this issue Mar 19, 2024 · 3 comments

Comments

@prtomasi
Copy link

prtomasi commented Mar 19, 2024

Description of Issue/Question

Note: Please check https://guides.github.com/features/mastering-markdown/
to see how to properly format your request.

Setup

Netmiko version

(Paste verbatim output from pip freeze | grep netmiko between quotes below)

netmiko==4.2.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

    'device_type': 'mikrotik_routeros',

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

no error, just incomplete output from 'export' command

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue)
(Paste the code between the quotes below)

from netmiko import ConnectHandler

mikrotik = {
    'device_type': 'mikrotik_routeros',
    'host':   '10.1.1.68',
    'port':     2222,
    'username': 'dude',
    'password': 'not_real_password'
}

mikrotik_connection = ConnectHandler(**mikrotik)
print(mikrotik_connection.send_command(f'export', cmd_verify=False))

Test

I noticed netmiko is breaking the output of 'export' command when the Mikrotik RouterOS version is > 6.48

The following was tested with 6.49.8 version
# mar/19/2024 11:25:34 by RouterOS 6.49.8

With the python code above, only 27 lines (from a total of 275 lines) were captured by netmiko, no errors were generated

line 22 --> /interface vlan
line 23 --> add disabled=yes interface=sfp-sfpplus1 name=v450 vlan-id=450
line 24 --> add interface=sfp-sfpplus1 name=v495 vlan-id=495
line 25 --> add interface=sfp-sfpplus1 name=v1904 vlan-id=1904
line 26 --> add interface=sfp-sfpplus1 name=v1906 vlan-id=1906
line 27 --> add interface=sfp-sfpplus1 name=v2056 vlan-id=2056

When I use PuTTY to run 'export' command in the same device, the output is complete and has 275 lines

...
line 28 --> /interface ethernet switch port
...
line 275 --> set default-group=deny use-radius=yes

line 278 --> prompt:

[user@RTR-FW-NNN-NNN-01] >

I asked for help at Mikrotik Forum, but I was ignored:

https://forum.mikrotik.com/viewtopic.php?t=205175

@prtomasi prtomasi changed the title Mikrotik version > 6.47 = 'export' command incomplete Mikrotik version > 6.48 = 'export' command incomplete Mar 19, 2024
@ktbyers
Copy link
Owner

ktbyers commented Mar 19, 2024

I would probably try on your send_command() statement to make it.

import re

# rest of your code
output = mikrotik_connection.send_command(
    f'export', 
    cmd_verify=False, 
    expect_string=re.escape("[user@RTR-FW-NNN-NNN-01] >")
)

Does that help?

@prtomasi
Copy link
Author

prtomasi commented Mar 20, 2024

Hi,

It still didn't work.
Every time I run the script the output has ~20 and ~30 lines (it's not breaking at any specific character or specific amount of lines)

I can't use a fixed expect_string, it must be a regex because the user and hostname will be variable in another complete script, that has a loop (for) to catch the running-config (export) from a list of devices.

@prtomasi
Copy link
Author

Hi,

Additional information:

from netmiko import ConnectHandler
import re

mikrotik = {
    'device_type': 'mikrotik_routeros',
    'host':   '10.1.1.68',
    'port':     2222,
    'username': 'dude',
    'password': 'not_real_password'
}

mikrotik_connection = ConnectHandler(**mikrotik)

output = mikrotik_connection.send_command(
    f'export',
    cmd_verify=False,
    expect_string=re.escape("[user@RTR-FW-NNN-NNN-01] >")
)

print(output)
print(f"Command 'export' executed")

the amount of lines captured is not fixed, this time only 5 lines were captured before the command print(f"Command 'export' executed") was applied:

root@ubuntu:/# python3 run.py


# mar/20/2024 17:04:53 by RouterOS 6.49.8
# software id = 74TS-LPJG
#
# model = RB4011iGS+
# serial number = MC927J062DR <<< only 5 lines captured

Command 'export' executed <<< print(f"Command 'export' executed") applied
root@ubuntu:/#

no visible errors generated

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

2 participants