Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Array returnd from Function

Array returnd from Function

Scheduled Pinned Locked Moved Support
4 Posts 2 Posters 26.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G
    G
    gkaudewitz
    wrote on last edited by
    #1

    I'm not genius in script writing. As of this I do not know what I'm doing wrong.
    Using Netxms 4.0-2227 calling a script from scriptlibrary out of Instance discovery filter I'm doing some analyzing of alias-string.
    >>> 2022.04.15 22:38:50.538 *I* [nxsl.trace        ] NT_lib_InstDisc::int_InstDisc_01 called with: ##---#hjipeffebguo Fa0/4 (##---#hjipeffebguo)
    Within the sub int_InstDisc_01 an other sub is called that should return an array consisting of three values and a string with three characters.
    >>> 2022.04.15 22:38:50.538 *I* [nxsl.trace        ] NT_lib_Parsers::Parse_Interface_Alias_Prefix called with: ##---#hjipeffebguo
    Using trace function I can figure out that the array will be constructed the right way within called sub Parse_Interface_Alias_Prefix.
    >>> 2022.04.15 22:38:50.538 *I* [nxsl.trace        ] NT_lib_Parsers::Parse_Interface_Alias_Prefix returns Values (hashash has2hash hasparams param ):1;1;1;---;
    But printing the resulting array within int_InstDisc_01 I only can identify the three values but there is no string to find
    >>> 2022.04.15 22:38:50.538 *I* [nxsl.trace        ] In int_InstDisc_01 Return Values from Parse_Interface_Alias_Prefix: 1;1;1;;
    Moving the three character-string from the last place in the array a little bit forward within sub Parse_Interface_Alias_Prefix just gave me analogous result without the string in returned array.

    Is there a restriction concerning mixing of different types for the return array of a sub?

    For production environment I have the two scripts in different libs. But I build up a test system where I put them in one library to reduce complexity.

    Script snipplets:
    sub int_InstDisc_01(ifalias,ifname)
    { trace(0,"NT_lib_InstDisc::int_InstDisc_01 called with: ".ifalias." ".ifname);
    
      inst_disc = false;
      array res1;
    
      res1 = Parse_Interface_Alias_Prefix(ifalias);
      trace(0,"In int_InstDisc_01 Return Values from Parse_Interface_Alias_Prefix: ".ArrayToString(res1,";").";");
    .....
    }
    
    sub Parse_Interface_Alias_Prefix(ialias)
    { trace(0,"NT_lib_Parsers::Parse_Interface_Alias_Prefix called with: ".ialias);
    
      array retval;
    ....
      retval = %(hashash,has2hash,hasparams,param);
      trace(0,"NT_lib_Parsers::Parse_Interface_Alias_Prefix returns Values (hashash has2hash hasparams param ):".ArrayToString(retval,";").";");
      return(retval);
    }
    
    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      This looks strange. I suggest you to minimize the code to get it as short as possible with this bug replicating.

      Does it acts the same if you do "Execute server script" on any node and put the code there?

      For debugging you can also trace the number of elements of array, it's size attribute, e.g. retval->size

      1 Reply Last reply
      0
      • G
        G
        gkaudewitz
        wrote on last edited by
        #3

        Hello Filipp,
        I followed Your advice and looked at the length of the array in called function and in calling function. Value was the same both times e.g. 4.
        Reducing and testing code via calling the script as serverscript from a device. This scriptlib has the subs and a "main"-function that calls the subs. With reduced code resulting string appears in the calling-function. After introducing some more calculation in called function the problem appears once more with the following results:
        NT_lib_InstDisc::int_InstDisc_01 called with: ##---#nsnsnsn bhohofewho
        NT_lib_Parsers::Parse_Interface_Alias_Prefix called with: ##---#nsnsnsn
        Parse_Interface_Alias_Prefix IN default:13 ##---#nsnsnsn
        NT_lib_Parsers::Parse_Interface_Alias_Prefix returns Values (hashash;has2hash;hasparams;param;;arraylength):1;1;1;---;;4;
        Error 15 in line 37: Unknown object's attribute

        Some times automatic server-restart followed.

        Putting a trace command directly in front of building  retval changed situation and function worked as expected.

        WITH LINE 135 NOT COMMENTED OUT:
        NT_lib_InstDisc::int_InstDisc_01 called with: ##---#nsnsnsn bhohofewho
        NT_lib_Parsers::Parse_Interface_Alias_Prefix called with: ##---#nsnsnsn
        Parse_Interface_Alias_Prefix IN default:13 ##---#nsnsnsn
        NT_lib_Parsers::Parse_Interface_Alias_Prefix param:---
        NT_lib_Parsers::Parse_Interface_Alias_Prefix returns Values (hashash;has2hash;hasparams;param;;arraylength):1;1;1;---;;4;
        In int_InstDisc_01 Return Values from Parse_Interface_Alias_Prefix: 1;1;1;---;;4;

        As of this You will find complete code I wrote as attachment, because I don't know where my error is.

        Best regards

        Georg


        parseprefix.nxsl

        1 Reply Last reply
        0
        • F
          F
          Filipp Sudanov
          wrote on last edited by
          #4

          There was a bug related to use of case operator. It's now fixed, will be included in next release which is planned next week.

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups