For my first Perl project(IE I've never used Perl before) I'm using XML Simple to process the data in a program that will need to store the xml data as variables. I can access the first level code, but don't really know the snyax to access the second level hash. Below is the code followed by the results of a data dump, this should show more closely what I'm trying to do. What I need to be able to do is pull the data from all the tags, and as of right now I can't pull the data from the sub tags of DeviceA and DeviceB. I'm also having issues with getting the SNMP syntax correct, which is why that code is commented out. That code was a result of trying an example that I found online, but like most of the examples of NET::SNMP get that I found, it was not easy to understand, so I just tried to alter it for my purposes, and wasn't successful.

Ideally what I'd like to be able to do is Run the SNMPget command within the foreach loop and report the findings to a seperate file. Eventually this code will be used by NetIQ to run a port monitoring script and will have calls to the their libraries for the reporting.

Also if anyone could give me tips on the proper input to the Net::SNMP snmpget function that would be appreciated, all of the examples I've seen have used some form of variable to extract the target. What I'd like to do is be able to use the IP address and port from the foreach statement in my request, and store the results in variables to either be logged or reported in some way. I already have the OID that I'll need to be accessing, so if possible I'd like to know the syntax for that sort of request.

#!/usr/bin/perl -w #use strict; #modules used use XML::Simple; use Data::Dumper; use Net::SNMP; our ($data, $xml, $e, $Host, $OID, $port, $CMD, $value, $SNMP_TARGET , + $SNMP_GET_CMD); #create object $xml = new XML::Simple; # MIB Hard value taken from parameters of the DC1 fab port pairs scrip +t appended a 1 to test port #1 $OID = ".1.3.6.1.4.1.289.2.1.1.2.3.1.1.152.1"; #checking against PD110 as a test run will probably be read from an XM +L input file in the future $Host = "10.2.125.110"; # read the XML file #$CMD = "snmpget -v1 -c public -Ovq -m "; #chomp($value = '${CMD} ${Host} .1.3.6.1.4.1.289.2.1.1.2.3.1.1.152.1') +; #print $value; $data = $xml->XMLin("FabPortPairs.xml"); #print Dumper($data); foreach $e (@{$data->{PairedDevices}}) #Do actions that require use of XML data in this loop possibly #call SNMP data gathering and reporting { print "Pairname is: " . $e->{PairName} . "\n "; print "Hosted Apps are: " . $e->{HostedApplication} . "\n" ; print "HostOS is: " . $e->{HostOS} . "\n"; }
Data dump output of one iteration of the file:
$VAR1 = { 'PairedDevices' => [ { 'DeviceB' => { 'SNMPCommunity' => 'public +', 'DeviceNickName' => 'SD131 +', 'SNMPPortIndex' => '19', 'IPAddress' => '10.2.125.1 +31', 'PathName' => '01', 'RealPort' => '18' }, 'ExclusionIndicator' => {}, 'PairName' => 'Chestnut', 'MetricSeverity' => '34', 'MinPercent' => '20', 'HostOwningGroup' => 'AIX Team', 'StatusAlertThisPair' => 'Y', 'DeviceA' => { 'SNMPCommunity' => 'public +', 'DeviceNickName' => 'SD130 +', 'SNMPPortIndex' => '19', 'IPAddress' => '10.2.125.1 +30', 'PathName' => '00', 'RealPort' => '18' }, 'StatusSeverity' => '31', 'HostedEnvironment' => 'Test', 'MetricAlertThisPair' => 'Y', 'MaxPercent' => '80', 'HostedApplication' => 'IEOR', 'HostOS' => 'AIX' },
Thanks, Bill

In reply to Accessing 2nd level elements in XML::Simple and using the data in an SNMP call by wruehl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.