Community discussions

MikroTik App
 
mdaitc
newbie
Topic Author
Posts: 34
Joined: Mon Mar 22, 2010 5:18 am

feature request: group by in firewall interface

Wed Mar 24, 2010 4:26 am

Hi,

a feature request:

/ip firewall print "group-by=interface"

to allow printing out rules grouped by the interface.

this would help to emulate some of hte behavior seen by other venders, such as Cisco Pix, where large rulesets might be accross multiple interfaces, and it would be nice to list all of the rules for particular interfaces (either direction in or out) together.

thanks,
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7188
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: feature request: group by in firewall interface

Wed Mar 24, 2010 9:08 am

It is already possible.
/ip firewall filter print where in-interface="ether1"
 
mdaitc
newbie
Topic Author
Posts: 34
Joined: Mon Mar 22, 2010 5:18 am

Re: feature request: group by in firewall interface

Wed Mar 24, 2010 1:59 pm

my thought was slightly different.

to print out all of the firewall rules, but to group the output by interface, rather than to only print out by interface

thanks,
 
eflanery
Member
Member
Posts: 376
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Re: feature request: group by in firewall interface

Wed Mar 24, 2010 11:48 pm

how about:
:foreach INT in=[/int find] do={/ip fir fil pr where in-interface=[/int get $INT name]}
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: feature request: group by in firewall interface

Thu Mar 25, 2010 12:00 am

Nice.

To filter out interfaces that don't have rule associated:
:foreach INT in=[/int find] do={:local rules [/ip fir fil find in-interface=[/int get $INT name]]; :if ([:len $rules] > 0) do={/ip fir fil print where in-interface=[/int get $INT name]}}
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: feature request: group by in firewall interface

Thu Mar 25, 2010 12:52 am

I haven't found a clean way of sorting firewall rules by a specific property, so I made a script to show me the output I want. Also, this works great if executed remotely as you can retrieve specific information for input into other systems.

Try this:
# Displays a sorted firewall list

/interface {
   :local ifacename
   :local property
   :local value
   :local findindex
   :local curline

   :foreach i in=[find] do={
      :set ifacename [get $i name]
      /ip firewall filter {
         :local ruledisabled
         :foreach f in=[print as-value where in-interface=[:tostr $ifacename]] do={
            :set curline ""
            :set ruledisabled ""
            :foreach item in=[:toarray $f] do={
               :set findindex [:find [:tostr $item] "="]
               :set property [:pick [:tostr $item] 0 $findindex]
               :set value [:pick [:tostr $item] ($findindex + 1) [:len [:tostr $item]]]

#            don't show IDs or comments (provides a cleaner output)
               :if ($property != ".id" && $property != "comment") do={
                  :set curline ($curline . " " . $property . "=" . $value)
               }

#            print as-value doesn't show disabled status; get rule's disabled status
               :if ($property = ".id") do={
                  :if ([get [:toid $value] disabled] = true) do={
                     :set ruledisabled "disabled=true" } else={
                        :set ruledisabled "disabled=false" }
               }
            }
            :put ($curline . " " . $ruledisabled)
         }
      }
   }
}

Who is online

Users browsing this forum: DanMos79, johnson73, Laxity, sindy and 21 guests