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 RouterOS Parser #244

Conversation

h4ndzdatm0ld
Copy link
Contributor

  • Added mikrotik_routeros parser
  • Compliance Tests
  • Parser Tests

@@ -0,0 +1,6 @@
features = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always like to have an example of a banner being parsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Ken! The comments at the top of the config files, is that considered a banner here, not just comments? There is a system note command, but it just outputs like a normal str config line.

# mar/22/2023 17:44:57 by RouterOS 6.48.5
# software id =
#
#
#
/interface wireless security-profiles set [ find default=yes ] supplicant-identity=MikroTik
/ip address add address=172.31.255.30/30 interface=ether1 network=172.31.255.28
/ip dhcp-client add disabled=no interface=ether1
/system identity set name=R2
/system note set note="SOME CRAZY NOTE!"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, perhaps simpleton of me to presume there is a banner :)

I do think it would be great to have a few options for "note", like how does it handle multi-line (is that supported), special characters, can you have a double quote in there, etc.. Think of ways to break it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itdependsnetworks I added to the parsing tests to capture the lines that are children of the /system note set note=.. line. This is the exact input that went into the device is below. If a user inputs a string without adding \n the config export will handle it and add it for you, same with special chars. Device will just escape them when exporting config.

This is a \"System Note\" for a Mikrotik router.\n\
It includes double quotes (\") and special characters such as:\n\
@, #, $, %, ^, &, *, (, ), _, +, [, ], {, }, |, ;, ',', ., /, <, >, and ?.\n\
\n\
Remember to escape any special characters with a backslash (\\) when necessary.\n\
\n\
This is a multiline note with several lines of text.

and when doing a terse config export, the following output appears ->

[admin@ag1.123site.nwk.nj] /system note> export terse
# apr/01/2023 17:16:02 by RouterOS 6.48.5
# software id =
#
#
#
/system note set note="This is a \\\"System Note\\\" for a Mikrotik router.\\n\\\
    \nIt includes double quotes (\\\") and special characters such as:\\n\\\
    \n@, #, \$, %, ^, &, *, (, ), _, +, [, ], {, }, |, ;, ',', ., /, <, >, and \?.\\n\\\
    \n\\n\\\
    \nRemember to escape any special characters with a backslash (\\\\) when necessary.\\n\\\
    \n\\n\\\
    \nThis is a multiline note with several lines of text.\\n\\\
    \nWow, what a great example of a note to ensure proper parsing by NetUtils!"
[admin@ag1.123site.nwk.nj] /system note>

hope this helps and captures what you asked for, LMK.

parents=(),
),
ConfigLine(
config_line=' \\nIt includes double quotes (\\\\\\") and special characters such as:\\\\n\\\\\\',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my mind, this line and the below should all be a single line without a parent. As an example I would not see the other lines as children of this parent.

look at:

and https://github.com/networktocode/netutils/blob/1312c08d58a74ebb63f36ea35d03bec7747628d0/tests/unit/mock/config/parser/base/cisco_ios/ios_full_received.py#LL360C34-L360C86

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'd expect this to be one single line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right on, the more I looked at this, it makes sense to treat this like a banner since it does allow to display upon logging into the device. Made some changes, lmk what ya'll think. Single line.

@itdependsnetworks itdependsnetworks merged commit ed4af96 into networktocode:develop May 11, 2023
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

Successfully merging this pull request may close these issues.

3 participants