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 'export terse' Preferred #25

Open
danpalamo opened this issue Jun 15, 2021 · 7 comments
Open

Mikrotik 'export terse' Preferred #25

danpalamo opened this issue Jun 15, 2021 · 7 comments

Comments

@danpalamo
Copy link

In bin/mtrancid, line 279, the command 'export terse' produces output that makes for cleaner diffs.

'export' produces multi-line commands where as 'export terse' produces every complete command as a single line.

It would be great if 'export terse' could be the default.

@haussli
Copy link
Owner

haussli commented Nov 11, 2021

How about another device type?

mikrotik-terse;alias;routeros-terse
routeros-terse;script;rancid -t routeros-terse
routeros-terse;login;mtlogin
routeros-terse;module;routeros
routeros-terse;inloop;routeros::inloop
routeros-terse;command;routeros::SystemPackagePrintDetail;system package print detail without-paging
routeros-terse;command;routeros::SystemRouterboardPrint;system routerboard print
routeros-terse;command;routeros::SystemLicensePrint;system license print
routeros-terse;command;routeros::Export;export terse

@mjducharme
Copy link

@haussli Another device type will be necessary with RouterOS v7 actually, as in RouterOS v7 you need to export show-sensitive so that it doesn't hide the sensitive parts of the config. Unfortunately in RouterOS v6, running export show-sensitive will error out as it isn't a valid option. I just mention that here because if you did add export-terse in this way you might need four different device types - one for routeros6, one for routeros6-terse, one for routeros7 and one for routeros7-terse.

@haussli
Copy link
Owner

haussli commented Nov 12, 2021

Can one mix the options? such as:

export terse show-sensitive

@haussli
Copy link
Owner

haussli commented Nov 12, 2021

I expect this would work for both v6 and v7 in one device type:

https://github.com/haussli/rancid/tree/routeros67

@mjducharme
Copy link

Can one mix the options? such as:

export terse show-sensitive

Yes, export terse show-sensitive is possible of course.

If your v6 and v7 in one device type tries export show-sensitive first and then runs export only if the export show-sensitive fails, yes it should work for both v6 and v7 in one device type.

@haussli
Copy link
Owner

haussli commented Nov 12, 2021

Yes. If someone could confirm for me that it works, i'll commit that and add the terse type. TiA

@miken32
Copy link

miken32 commented Jan 12, 2023

@haussli we're running a mixed 6/7 environment so I tried the code in the routeros67 branch and it did not work for me. I ended up with 2 copies of the config for my 7.0 routers. In addition to adding a new device type, I just changed the module like so:

--- /usr/share/perl5/vendor_perl/rancid/routeros.pm.org	2022-12-02 09:28:27.000000000 -0500
+++ /usr/share/perl5/vendor_perl/rancid/routeros.pm	2023-01-12 18:25:29.434461051 -0500
@@ -59,6 +59,8 @@
 
 use rancid 3.13;
 
+our $Export;
+
 @ISA = qw(Exporter rancid main);
 #XXX @Exporter::EXPORT = qw($VERSION @commandtable %commands @commands);
 
@@ -207,9 +209,12 @@
 	if (/$prompt/) { $found_end=1; $clean_run=1; return 0};
 	next if(/^(\s*|\s*$cmd\s*)$/);
 	next if(/^#/);
+	return(1) if /(expected end of command )/;
 	return(1) if /(bad command name )/;
 	s/^\s+//g;
 
+	return(0) if ($routeros::Export);
+
 	# RouterOS splits long lines with backslashes - this re-joins them
 	if (/\\\n$/) {
 	    s/\s*\\\n$//;
@@ -232,6 +237,7 @@
 	    $buffer = "";
 	}
     }
+	$routeros::Export = 1;
 }
 
 1;

Happy to help troubleshoot further as we're trying to move config backups to rancid instead of scripted FTP dumps. (See also #53 – is the same problem possibly causing the code to bail out before setting the $Export variable?)

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

4 participants