Community discussions

MikroTik App
 
User avatar
Splash
Member Candidate
Member Candidate
Topic Author
Posts: 206
Joined: Fri Oct 16, 2015 10:09 am
Location: Johannesburg, South Africa

Feature: /export with a term match

Thu Mar 10, 2016 11:47 am

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
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: Feature: /export with a term match

Thu Mar 10, 2016 10:54 pm

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
 
User avatar
Splash
Member Candidate
Member Candidate
Topic Author
Posts: 206
Joined: Fri Oct 16, 2015 10:09 am
Location: Johannesburg, South Africa

Re: Feature: /export with a term match

Sat Mar 12, 2016 9:05 am

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.

:)
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: Feature: /export with a term match

Sat Mar 12, 2016 1:08 pm

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.
 
User avatar
Splash
Member Candidate
Member Candidate
Topic Author
Posts: 206
Joined: Fri Oct 16, 2015 10:09 am
Location: Johannesburg, South Africa

Re: Feature: /export with a term match

Sun Mar 13, 2016 8:26 pm

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.

Who is online

Users browsing this forum: korg and 105 guests