crackdonalds

help to linking array data

10 posts in this topic

#1 ·  Posted (edited)

Hi,

 

I've got 3 arrays, each with 2 columns. This after requesting snmp from a switch.

What i need (in the end) is 1 array with 2 columns.
mac in decimal (preferably in hex seperated by ":" (i'll work on that obviously)) 2.0.0.36.208.3.178
interface: Gi2/0/2

Basically I need to link them like this:

mac > interface
interface > interface index
interface index > interface name

-array output example of the arrays mentioned above-
array1: [1]|1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178  | 98
array2: [31]|1.3.6.1.2.1.17.1.4.1.2.98  | 74
array3: [74]|1.3.6.1.2.1.31.1.1.1.1.74  | Gi2/0/2

The 98 value from the first array should be linked to the 1.3.6.1.2.1.17.1.4.1.2.98 (trimed to 98) value which returns 74 and then link to the third array.

 

The first array that i have contains mac and intarface value's, the second contains the interface  and interface index and the third contains the interface index and the interface name.

In each array, the first column contains a whole snmp OID which looks like: 1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178
Each of them can be Trimmed from the left by 23 characters.

 

I hope anyone understand what i'm talking about (lol) and can point me into the right direction cuz I don't really know how to approach this.

Thanks for thinking with me...

 

 

Edited by crackdonalds

Share this post


Link to post
Share on other sites



Are this arrays 0 or 1 based? Means: Does the first row contain a row/column count or does the array only hold data?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

They contain a row count for now but I don't need the count at all so....

btw: the first number u see in the array is the row count....

Edited by crackdonalds

Share this post


Link to post
Share on other sites

Something like this?

#include <Array.au3>
; All arrays are 1-based
Global $aArrayIn1[2][2] = [[1, 2], ["1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178", "98"]]
Global $aArrayIn2[33][2] = [[32, 2]]
$aArrayIn2[32][0] = "1.3.6.1.2.1.17.1.4.1.2.98"
$aArrayIn2[32][1] = 74
Global $aArrayIn3[75][2] = [[174, 2]]
$aArrayIn3[74][0] = "1.3.6.1.2.1.31.1.1.1.1.74"
$aArrayIn3[74][1] = "Gi2/0/2"
Global $aArrayOut[$aArrayIn1[0][0]][3]
For $i = 1 To $aArrayIn1[0][0]
    For $j = 1 To $aArrayIn2[0][0]
        If StringTrimLeft($aArrayIn2[$j][0], 23) = $aArrayIn1[$i][1] Then
            ConsoleWrite($aArrayIn1[$i][1] & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF)
            ExitLoop
        EndIf
    Next
Next

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

it results in 98 | Gi2/0/2

the expected result would be 0.0.36.208.3.178 | Gi2/0/2

i'll be looking into this concept though.

Edited by crackdonalds

Share this post


Link to post
Share on other sites

Replace this line:

ConsoleWrite(StringTrimLeft($aArrayIn1[$i][0], 23) & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF)

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Great, i've implemented it and it works. Thanks!

Now what if i would want that first column to appear in Hex?

For a single decimal mac i made this earlier to test:

$input = InputBox("Decimal mac-addr to hex", "Enter decimal mac")
Local $bla[6]
$asd = StringSplit($input, ".", 2)

For $i = 0 To UBound($asd) - 1
$bla[$i] = Hex($asd[$i], 2)
Next


$string = _ArrayToString($bla, ":")

it works fine for one but how would it fit into the code you just made (to have all rows into hex)?

 

Hope i'm not asking too much now...

Share this post


Link to post
Share on other sites

This?

#include <Array.au3>
; All arrays are 1-based
Global $aArrayIn1[2][2] = [[1, 2], ["1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178", "98"]]
Global $aArrayIn2[33][2] = [[32, 2]]
$aArrayIn2[32][0] = "1.3.6.1.2.1.17.1.4.1.2.98"
$aArrayIn2[32][1] = 74
Global $aArrayIn3[75][2] = [[174, 2]]
$aArrayIn3[74][0] = "1.3.6.1.2.1.31.1.1.1.1.74"
$aArrayIn3[74][1] = "Gi2/0/2"
Global $aArrayOut[$aArrayIn1[0][0]][3]
For $i = 1 To $aArrayIn1[0][0]
    For $j = 1 To $aArrayIn2[0][0]
        If StringTrimLeft($aArrayIn2[$j][0], 23) = $aArrayIn1[$i][1] Then
            $aIP = StringSplit(StringTrimLeft($aArrayIn1[$i][0], 23), ".", 2)
            For $k = 0 To UBound($aIP) - 1
                $aIP[$k] = Hex($aIP[$k], 2)
            Next
            ConsoleWrite(StringTrimLeft($aArrayIn1[$i][0], 23) & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF) ; decimal
            ConsoleWrite(_ArrayToString($aIP, ":") & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF) ; hex
            ExitLoop
        EndIf
    Next
Next

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Perfect! Thanks again.

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now