Array returnd from Function

Started by gkaudewitz, April 17, 2022, 12:03:49 PM

Previous topic - Next topic

gkaudewitz

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);




Filipp Sudanov

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


gkaudewitz

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

Filipp Sudanov

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.