Page 1 of 1

Feature: /export with a term match

Posted: Thu Mar 10, 2016 11:47 am
by Splash
I would like to ask that some more power be added to the export facility on the Mikrotik to include the ability to match particular configuration only and with their respective grouping. This would allow one to filter all configuration that matches a particular term which could be an ip, comment, interface etc.

For example,

You have applied a comment to each configuration attribute related to a customers configuration. You would like to only export the configuration where this comment is matched but in the same way also include the group configuration headers.
/export where comment="CUSTOMER"
-------OUTPUT----------
/interface ethernet
set [ find default-name=ether1 ] comment="CUSTOMER" name=ether2
/ip address
add address=192.168.1.1/24 comment=CUSTOMER interface=ether2 network=192.168.1.0

Re: Feature: /export with a term match

Posted: Thu Mar 10, 2016 10:54 pm
by pe1chl
Of course until such a feature is included you can simply do a full export and take out only the lines you want
using a tool like egrep:

egrep '^/|comment="*CUSTOMER' exportfile.rsc >customer.rsc

Re: Feature: /export with a term match

Posted: Sat Mar 12, 2016 9:05 am
by Splash
Agreed, the only problem is that when you do this it wont include the configuration "sub-sections" which you would need to manually include.

Since the OS is based on Linux, I don't think it would be too hard to include cmd line tools like grep for example. Juniper uses the 'match' function, Cisco uses the 'include' function and Mikrotik uses the 'where' function however you can only use this 'where' function within a configuration "sub-section" and not against the whole configuration.

:)

Re: Feature: /export with a term match

Posted: Sat Mar 12, 2016 1:08 pm
by pe1chl
The main problem is that export files use line splitting with \ at the end of the line for continuation.
This often makes things more complicated than they need to be, and there appears to be no option to turn this off.
My suggested solution would need an extra command (sed, awk) to glue lines together at the \ mark.
By then it is probably better to write a small Perl script to do the job.

Re: Feature: /export with a term match

Posted: Sun Mar 13, 2016 8:26 pm
by Splash
Line splitting normally happens when your terminal window isnt long enough for the full line. You can try doing it with a bigger window on a bigger screen :).

I don't think it would require much work to implement some sort of filtering on the export command. I'll look at seeing if I can get sometime to write an export like script which you can run with the term you are searching for and see if I can output the export in a way that makes it work with a filter.