Add value to the end of an array?

So, I’m having an interesting time trying to find how to add a value to the end of an array. I’d like to use an array to ethernet errors detected in a for loop but I’m not finding a way to add to an array easily?

I’ve got the logic down for finding the count of interfaces, polling the interfaces for each specific type I want then passing that value to a global array errorlist, but the syntax I’m using currently produces an array where the previous entire array is a single variable.

Any ideas?

(and yes, I know the last :log is currently just logging the array variable output to info, will work on setting up an e-mail tool call once I get this array figured out, and that tx-packet are not errors)


local ethstattype [:toarray value=“rx-too-short,rx-pause,rx-fcs-error,rx-align-error,rx-drop,rx-jabber,tx-pause,tx-deferred,tx-late-collision,tx-drop,tx-fcs-error,tx-packet”];
foreach iface in=[/interface ethernet find] do={
local ifacename [/interface ethernet get value-name=name number=$iface];
foreach i in=[/interface ethernet find default-name=“$ifacename”] do={
foreach ethstat in=$ethstattype do={
local ethstatvalue [:tonum [/interface ethernet get $i value-name=$ethstat]];
if ( $ethstatvalue > -1 ) do={
local alert “$ifacename has $ethstatvalue $ethstat errors”;
global errorlist [:toarray value=“$alert”];
}
}
}
/interface ethernet reset-counters $ifacename
}
foreach etherror in=$errorlist do={
:put $etherror;
:log info $etherror;
global thishassomething $etherror;
}

This creates empty array and adds a value:

:local array [ :toarray "" ];
:set array ( $array, $newvalue );

Just repeat for more values.

For a KV array, you can do:

{
:local array [ :toarray "producer=ford;color=blue" ]
:set ("$array"->"type") "mustang"
:put $array
}
producer=ford;color=blue;type=mustang