+ Responder ao Tópico



  1. #1

    Post MikroTik Scripting - Filtros de consulta (find - where)

    Prezados,

    Pelos testes que fiz, detectei uma falha em filtros de consulta, aplicados à propriedade de modo de proteção, em interfaces bridge, no MikroTik RouterOS.

    O problema pode ser reproduzido em qualquer versão do MikroTik RouterOS, entre 5.14 e 5.21. Não testei em versões anteriores, pois são muito ultrapassadas, de uso não recomendado.

    O código abaixo demonstra, de forma básica, o problema existente.
    Código :
    #Add 3 bridges, with protocol mode none, stp and rstp, respectively.
    /interface bridge add name=MYBRIDGE-A protocol-mode=none comment="Temp"
    /interface bridge add name=MYBRIDGE-B protocol-mode=stp  comment="Temp"
    /interface bridge add name=MYBRIDGE-C protocol-mode=rstp comment="Temp"

    Código :
    #Enumerate each interface. Teorically work, but not work :(
    foreach X in=[ /interface bridge find where protocol-mode=none ]  do={:put ([/interface bridge get $X name ] ) }
    foreach X in=[ /interface bridge find where protocol-mode=stp  ]  do={:put ([/interface bridge get $X name ] ) }
    foreach X in=[ /interface bridge find where protocol-mode=rstp ]  do={:put ([/interface bridge get $X name ] ) }

    Código :
    #Print each interface found, filtered by protocol-mode. Teorically work, but not work :(
    /interface bridge print where protocol-mode=none
    /interface bridge print where protocol-mode=stp 
    /interface bridge print where protocol-mode=rstp

    Como demonstrado acima, o resultado de cada consulta não condiz com o filtro aplicado, seja "find", seja "where", em versões anteriores ao MikroTik RouterOS 5.21, inclusive.

    Já abri um chamado de suporte na MikroTik, entretanto, não tive resposta até o momento.

    Desejo saber se em seus ativos que rodam MikroTik RouterOS, entre 5.14 e 5.21, esse problema também acontece.

    Grato,

    Trober

  2. #2

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Obrigado Trober por compartilhar!

    Abs.

  3. #3
    Analista de Suporte em TI Avatar de demattos
    Ingresso
    Jul 2011
    Localização
    Criciuma/SC
    Posts
    1.923
    Posts de Blog
    3

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Copio, anotado e ligado no descrito

    Obrigado por sua contribuicao

  4. #4
    Moderador Avatar de gamineiro
    Ingresso
    Jan 2008
    Localização
    RS
    Posts
    423
    Posts de Blog
    2

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Bom dia amigo.

    Tente esse código.

    Código PHP:
    #Enumerate each interface. Teorically work, but not work :( 
    foreach X in=[ /interface bridge find where protocol-mode="none" ]  do={:put ([/interface bridge get $X name ] ) } 
    foreach 
    X in=[ /interface bridge find where protocol-mode="stp"  ]  do={:put ([/interface bridge get $X name ] ) } 
    foreach 
    X in=[ /interface bridge find where protocol-mode="rstp" ]  do={:put ([/interface bridge get $X name ] ) } 
    Acredito que o problema seja apenas referenciar o valor de protocol-mode entre aspas.

    Abraço

  5. #5

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Citação Postado originalmente por gamineiro Ver Post
    Bom dia amigo.
    Bom dia Gabriel

    Citação Postado originalmente por gamineiro Ver Post
    Tente esse código.
    Código :
    #Enumerate each interface. Teorically work, but not work :( 
    foreach X in=[ /interface bridge find where protocol-mode="none" ]  do={:put ([/interface bridge get $X name ] ) } 
    foreach X in=[ /interface bridge find where protocol-mode="stp"  ]  do={:put ([/interface bridge get $X name ] ) } 
    foreach X in=[ /interface bridge find where protocol-mode="rstp" ]  do={:put ([/interface bridge get $X name ] ) }

    Acredito que o problema seja apenas referenciar o valor de protocol-mode entre aspas.
    Deu certo!!!

    Mas convenhamos, que porquice a MikroTik fez. Fugiu ao padrão de usar aspas somente em strings com espaços. Prova disso é que o autocompletar aceita dessa forma, sem as aspas. Outra prova, são os exemplos abaixo:

    Código :
    #Double quotes no required (example 1).
    /ip address add address=9.9.9.1/32 interface=MYBRIDGE-A
    /ip address add address=9.9.9.2/32 interface=MYBRIDGE-B 
    /ip address add address=9.9.9.3/32 interface=MYBRIDGE-C  
    /ip address print where interface=MYBRIDGE-A
    /ip address print where interface=MYBRIDGE-B
    /ip address print where interface=MYBRIDGE-C
    Aspas duplas não são requeridas. De igual forma no exemplo abaixo.
    Código :
    #Double quotes no required (example 2).
    /interface bridge print where comment=Temp
    Enfim, faltou homogeneidade nos filtros.

    Farei um complemento ao chamado aberto, informando a sua análise. Dessa forma, talvez corrijam isso para o MikroTik RouterOS 5.22

    Citação Postado originalmente por gamineiro Ver Post
    Abraço
    Abraço!

    Trober

  6. #6

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Citação Postado originalmente por trober Ver Post
    Fugiu ao padrão de usar aspas somente em strings com espaços. Prova disso é que o autocompletar aceita dessa forma, sem as aspas.
    Citação Postado originalmente por trober Ver Post
    Enfim, faltou homogeneidade nos filtros.
    Complementando com a informação oficial do MikroTik Wiki[1], no que tange aos scripts.

    Valid characters in variable names are letters and digits. If variable name contains any other character, then variable name should be put in double quotes.
    [1] http://wiki.mikrotik.com/wiki/Manual:Scripting

    Saudações,

    Trober

  7. #7
    Moderador Avatar de gamineiro
    Ingresso
    Jan 2008
    Localização
    RS
    Posts
    423
    Posts de Blog
    2

    Padrão Re: MikroTik Scripting - Filtros de consulta (find - where)

    Eu creio que eles não "se apegam" aos detalhes, que muitas vezes nos fazem perder muito tempo.

    Tive um problema parecido com filtros BGP. Quando que criava um filtro que não precisa de prefix, ou seja, para todos os prefixos, não conseguia faze-lo funcionar. Depois de abrir um chamado me disseram que eu precisava setar o prefix com 0.0.0.0/0, hahahahaUm abraço.