Hello Roboticus
Sorry i don't understand your code answer and it doesn't seem to work either? Was going to test it so that i could make sense out of it..But it fails.
were you going for something like?
$varbindhash{"OID_$i"} = $OIDs[$i];
Also the soft reference solution didn't work either since it required turning of use strict;
I can't put everything inside one hash and post it to elastic since i want each line containing 3 values of an unknown number of lines to be viewed by itself with only the values belonging to that line..If that makes any sense=). If i put and post everything in a hash it will look like one variable with all the values in it.
Anyway sorry for the late reply just didn't have time to try to elaborate the reference problem..Will try now..
One of the ARGVs that comes with NetSNMP::TrapReceiver::register is for SNMP VARBINDs which have references to a multi dimensional array.
And i just can-t manage to de-reference that multiarray reference when put into a new hash or get them approved as JSON format. I don't really understand how perl references works but single arrays has no de reference problem as seen below must be something special with multi but i can't figure it out.
Here is a simulation of what it looks like (see last line), the fun thing is that together with JSON function to_json() it gets de-referenced:
#!/usr/bin/perl
use strict;
#use JSON;
my $alex = "alex";
my $alexAge = "35";
my $tristan = "tristan";
my $tristanAge = "5";
my $krista_bell = "kristabell";
my $krista_bellAge = "2";
my %newHash = ("$alex" => "$alexAge", "$tristan" => "$tristanAge", "$k
+rista_bell" => "$krista_bellAge");
my @array = ('test_0_0', 'test_0_1', 'test_0_2');
my $arrayRef = \@array;
printf("\narray = @array, ArrayRef = $arrayRef, de-referenced arrayRef
+: @{$arrayRef}, de-referenced arrayRef2: @$arrayRef\n\n");
my @multiArray = (
['value_on_0_0', 'value_on_0_1', 'value_on_0_2'],
['value_on_1_0', 'value_on_1_1', 'value_on_1_2'],
['value_on_2_0', 'value_on_2_1', 'value_on_2_2']
);
my $multiArrayRef = \@multiArray;
printf("\nmultiArray = @multiArray, MultiArrayRef = $multiArrayRef, de
+-referenced multiArrayRef: @{$multiArrayRef}, de-referenced multiArra
+yRef2: @$multiArrayRef\n\n");
printf("\n\n");
my $i = 0;
my $c0 = 0;
my $c1 = 1;
my $c2 = 2;
foreach my $x (@multiArray)
{
printf("\n\nX Ref: $x,\nX De-Ref: @$x,\nRow[$i] Column[$c0]: $
+x->[0], Row[$i] Column[$c1]: $x->[1], Row[$i] Column[$c2]: $x->[2]");
printf("\nVariations on first value on row[$i]: x[0] = $x->[0]
+ OR x[0] = @$x[0] OR x[0] = ${$x}[0]");
my %varbind = (
("row" . "$i" . "c" . "$c0") => @$x[0],
("row" . "$i" . "c" . "$c1") => @$x[1],
("row" . "$i" . "c" . "$c2") => @$x[2]
#("row" . "$i" . "c" . "$c0") => $x->[0],
#("row" . "$i" . "c" . "$c1") => $x->[1],
#("row" . "$i" . "c" . "$c2") => $x->[2]
);
printf("\n\n Value of current varbind: ");
print %varbind;
push(@{$newHash{"varbinds"}}, {%varbind});
$i++;
}
printf("\n\nNext line will be printout of newhash\n");
print %newHash;
printf("\n\n\n");
#printf("\nto_json(%newHash)");
And here is the output.
array = test_0_0 test_0_1 test_0_2, ArrayRef = ARRAY(0x17dc7b8), de-re
+ferenced arrayRef: test_0_0 test_0_1 test_0_2, de-referenced arrayRef
+2: test_0_0 test_0_1 test_0_2
multiArray = ARRAY(0x153b088) ARRAY(0x153b688) ARRAY(0x17dce18), Multi
+ArrayRef = ARRAY(0x17dca40), de-referenced multiArrayRef: ARRAY(0x153
+b088) ARRAY(0x153b688) ARRAY(0x17dce18), de-referenced multiArrayRef2
+: ARRAY(0x153b088) ARRAY(0x153b688) ARRAY(0x17dce18)
X Ref: ARRAY(0x153b088),
X De-Ref: value_on_0_0 value_on_0_1 value_on_0_2,
Row[0] Column[0]: value_on_0_0, Row[0] Column[1]: value_on_0_1, Row[0]
+ Column[2]: value_on_0_2
Variations on first value on row[0]: x[0] = value_on_0_0 OR x[0] = val
+ue_on_0_0 OR x[0] = value_on_0_0
Value of current varbind: row0c2value_on_0_2row0c1value_on_0_1row0c0v
+alue_on_0_0
X Ref: ARRAY(0x153b688),
X De-Ref: value_on_1_0 value_on_1_1 value_on_1_2,
Row[1] Column[0]: value_on_1_0, Row[1] Column[1]: value_on_1_1, Row[1]
+ Column[2]: value_on_1_2
Variations on first value on row[1]: x[0] = value_on_1_0 OR x[0] = val
+ue_on_1_0 OR x[0] = value_on_1_0
Value of current varbind: row1c2value_on_1_2row1c1value_on_1_1row1c0v
+alue_on_1_0
X Ref: ARRAY(0x17dce18),
X De-Ref: value_on_2_0 value_on_2_1 value_on_2_2,
Row[2] Column[0]: value_on_2_0, Row[2] Column[1]: value_on_2_1, Row[2]
+ Column[2]: value_on_2_2
Variations on first value on row[2]: x[0] = value_on_2_0 OR x[0] = val
+ue_on_2_0 OR x[0] = value_on_2_0
Value of current varbind: row2c0value_on_2_0row2c2value_on_2_2row2c1v
+alue_on_2_1
Next line will be printout of newhash
varbindsARRAY(0x15562a8)alex35tristan5kristabell2
|