Page 1 of 1

invalid internal item number

Posted: Wed Oct 05, 2022 10:35 am
by quotengrote
Hi,

when i set a variable like:
:global xx "pppoe-out-fb"
i cant use it in this where question:
/ip/address/get [find where interface "$xx" ]
invalid internal item number
Where is the problem?

Device:
/system/resource> print 
                   uptime: 3w1d18h4m48s
                  version: 7.6beta6 (development)
               build-time: Sep/07/2022 09:06:03
         factory-software: 7.0.4
              free-memory: 799.4MiB
             total-memory: 1024.0MiB
                      cpu: ARM64
                cpu-count: 4
            cpu-frequency: 350MHz
                 cpu-load: 18%
           free-hdd-space: 481.9MiB
          total-hdd-space: 513.0MiB
  write-sect-since-reboot: 74548
         write-sect-total: 995885
               bad-blocks: 0%
        architecture-name: arm64
               board-name: RB5009UG+S+
                 platform: MikroTik
Wishes
mg

Re: invalid internal item number

Posted: Wed Oct 05, 2022 7:20 pm
by eworm
Two (possible) issues:
  • You are missing an equal sign...
  • Your interface may have no or more than one address...

Re: invalid internal item number

Posted: Wed Oct 05, 2022 9:11 pm
by quotengrote
With ROS6 this Syntax works as expected.

Re: invalid internal item number

Posted: Wed Oct 05, 2022 9:53 pm
by msatter
I use a regualar expression to match. That is the ~ sign instead of a = .

The searched interface name has to be also unique or there will no match. If you have two PPPoE (pppoe-in pppoe-out) then matching on pppoe does not cut. You have to match on the difference and the shortest one is "in" or "out" . pppoe alone will not match and so no result.
:local xx "pppoe"; :put [typeof $xx]; :put [/ip/address/get [find interface~$xx]]
I use :local and it display the type of the variable. That is in this case a string (str), so no need to put the variable $xx in quotes.

Re: invalid internal item number

Posted: Wed Oct 05, 2022 10:08 pm
by quotengrote
Same error on ROS7; with ROS6 it works as expected.

Re: invalid internal item number

Posted: Wed Oct 05, 2022 11:32 pm
by mrz
Returned type is an array of a single element, get command does not accept an array, either use pick command to pick the 0 element of an array or if you are sure that there is only one element then convert array to string with :tostr command

Re: invalid internal item number  [SOLVED]

Posted: Fri Oct 07, 2022 2:45 am
by rextended
@quotengrote, choose your method...

All tested on v6, but I do not know any reason for wat must do not work on v7, let me know, please.

:global iface "pppoe-out-fb"
:put ([/interface pppoe-client monitor $iface once as-value]->"local-address")
# do error if interface not exist
# do not contain /xx

:global iface "pppoe-out-fb"
:put [/ip address get [:tostr [find where interface=$iface]] address]
# do error if interface not exist or if interface have multiple IPs
# contain /xx and must be removed if needed

:global iface "pppoe-out-fb"
:put [/ip address get ([find where interface=$iface]->0) address]
# do error if interface not exist or if interface have no IP
# contain /xx and must be removed if needed

# on ppp profile used, on on-up script:
:global fbIP $"local-address"
# do not contain /xx

Re: invalid internal item number

Posted: Fri Oct 07, 2022 9:58 pm
by quotengrote
@rextended and all

Thank you very much, all of these worked for me.

Wishes
mg

Re: invalid internal item number

Posted: Mon May 08, 2023 8:36 pm
by 611
A follow-up as I've ran into similar issue, but the cause was not apparent from this thread.
:local interface "some-interface"
:put [/ip dhcp-client get [find interface=$interface] primary-dns]
 
Results in "invalid internal item number".
:put [/ip dhcp-client get [find interface="some-interface"] primary-dns]
 
Works well.
:local dhcpinterface "some-interface"
:put [/ip dhcp-client get [find interface=$dhcpinterface] primary-dns]
 
Works well.

Tested on ROS 7.9.

The cause of error in the particular case is name clash in between parameter name "interface" and variable name "interface", use of a variable with different name solves the issue.

Re: invalid internal item number

Posted: Mon May 08, 2023 8:59 pm
by rextended
The cause of error ...
You broke a simple law of almost all programming languages: don't use reserved words as a variable name...
If the context has "interface" as the element name, obviously you must NOT use the same name.
That's why I wrote "iface".

Re: invalid internal item number

Posted: Mon May 08, 2023 11:33 pm
by 611
You broke a simple law of almost all programming languages: don't use reserved words as a variable name...
Sure. The problem is DHCP client supplies interface name to the script as variable named "interface" (unlike DHCP server that uses "bindingVariableName" variables). Had to use a proxy variable instead.

I know it's in the docs (now, when I searched them for reserved variable names), but, honestly, the clash was NOT obvious - from implementation POV I've expected variables to be substituted first, in the shell or script interpreter, before the commands are executed (thus no clash is possible - the command sees no variable names), but the commands just inherit script environment and substute variables internally (thus causing clash and this, rather cryptic, error message).

An interesting feature of this internal variable substitution is ability to use values of other properties for inline filtering:
/ip firewall address-list print where address=$comment
Will print all IPv4 firewall address list entries in which the address is the same as the comment.

This, however, seems to work for find and where only.

Re: invalid internal item number

Posted: Mon May 08, 2023 11:37 pm
by rextended
"find" and "print"...

the correct syntax is

"find where" and "print where"...

Some complex example for what can be doed with that...
/system script job print where [:typeof $script]!="nil"
(just one example from viewtopic.php?t=195953#p1000381 )

Re: invalid internal item number

Posted: Tue May 09, 2023 12:47 am
by 611
the correct syntax is
"find where"
While it looks more in line with "print where" this way, both docs page on scripting and /export command use "[find property=value]" without "where". Terminal autocomplete suggests that "where" is optional for "find" too.

Re: invalid internal item number

Posted: Wed Oct 11, 2023 1:43 am
by diamuxin
With this script I have the same error: "invalid internal item number". It works on a hAP ac^2 and does not work on a RB4011. Both with v7.11.2.

:local output
:local filename
:local sysname  [/system identity get name]

:set filename  ($"sysname"."-"."Leases.txt")

/ip dhcp-server lease
:foreach i in=[find] do={
    :local hname      [get $i host-name]
    :local activeMAC  [get $i active-mac-address]
    :local Address    [get $i address]
    :local macAddress [get $i mac-address]
    :local Status     [get $i status]
    :local Comment    [get $i comment]
    :local iface      "undefined"
    
    /interface bridge host
    :local searchresult [find where mac-address=$activeMAC]
    :if ([:len $searchresult] > 0) do={
        :set iface [get $searchresult on-interface]
    
        :if (([:typeof $hname] = "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $Comment) . "\n")
        } 
        :if (([:typeof $hname] != "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $hname) . "\n")
        }
    }
}

/file print file=$filename
:delay 2s
/file set $filename contents=$output


EDIT: I don't understand anything, but there was a host in the DHCP Lease list that made it give that error, after disabling it it is working again. I am sorry for this.