haussli / rancid

RANCiD
Other
114 stars 42 forks source link

Mikrotik 'export terse' Preferred #25

Open danpalamo opened 3 years ago

danpalamo commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

Can one mix the options? such as:

export terse show-sensitive

haussli commented 2 years ago

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

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

mjducharme commented 2 years ago

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 commented 2 years ago

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

miken32 commented 1 year ago

@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?)