<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hello,</p>
    <p>I am playing with virtual parameters for the first time and am
      trying to get the IP address for the interface named 'loopback'.
      Unfortunately, different devices will have a different 'index
      number', if that is the correct term, for this interface. I have
      found the IP addresses table contains this address in
      Device.IP.Interface.5.IPv4Address.1.IPAddress, however it does not
      contain the name of the interface, which is 'loopback'. Instead,
      it contains a reference in Device.IP.Interface.5.LowerLayers,
      which has the value Device.X_MIKROTIK_Interface.Generic.3, and
      Device.X_MIKROTIK_Interface.Generic.3.Name is 'loopback'.</p>
    <p>Based on this I have worked out a specific algorithm that would
      determine the IP address:</p>
    <ol>
      <li>Iterate through Device.X_MIKROTIK_Interface.Generic.*.Name
        until finding one where the name is the string 'loopback'</li>
      <li>Once found, get the 'index number', i.e. the asterisk above,
        so that if loopback is found in
        Device.X_MIKROTIK_Interface.Generic.5.Name, it would return 5.</li>
      <li>Iterate through Device.IP.Interface.*.LowerLayers to find one
        where its value is Device.X_MIKROTIK_Interface.Generic.5.Name</li>
      <li>Once found, get the 'index number' for the IP interface,
        example, '8'</li>
      <li>Use this index number to get the IP address for the interface,
        ex. Device.IP.Interface.8.IPv4Address.1.IPAddress</li>
    </ol>
    <p>The algorithm I believe will work, but the thing I cannot figure
      out is how to get this index number as it iterates through. The
      script in progress is shown below. Initially I am just trying to
      fetch this 'index number' for the first part and return it
      instead, just to make sure I have part of the script working. Once
      I have that figured out I think the rest will fall into place.<br>
    </p>
    <p>// Example: Fetch index for loopback interface<br>
      let m = 'Unknown'<br>
      let intnames = declare(<br>
        "Device.X_MIKROTIK_Interface.Generic.*.Name",<br>
        {value: Date.now()});<br>
      if (intnames.size) {<br>
        for (let myitem of intnames) {<br>
          if (myitem.value[0]=='loopback') {<br>
            m = myitem;  // NOTE: This is the part I don't know, I want
      m to be the index number where value was found<br>
            break;<br>
          }<br>
        }  <br>
      }<br>
    </p>
    <p>return {writable: false, value: [m, "xsd:string"]};</p>
    <p><br>
    </p>
    <p>Any ideas? I have done programming in quite a few languages
      before but have done very little JavaScript.<br>
    </p>
    <p>Thanks!<br>
    </p>
    <p></p>
  </body>
</html>