#!/usr/bin/perl -w #Status Legend : 1=psNotInstalled,2=psAvailable,3=psBlocked,4=psUnavailable, #5=psLinkFailure,6=psLinkFailLOL,7=psIntDiags, 8=psExtLoop,9=psPortFail, #10=psSR,11=psLR,12=psInaccessible,13=psInactive ### This script developed by Bill Ruehl, July 2007 ### Version 1.0 This is version 1 of the time check script use strict; #modules used use XML::Simple; use Net::SNMP; use XML::Parser; use XML::Parser::Expat; our ($data, $xml, $e, $value, $IPAddressA, $OID, $session, $error, $statA,$resmsg); #create object # Hard Code OID for port status info $OID ="1.3.6.1.4.1.289.2.1.1.2.1.11" ; #Hard Code OID for metrics info #instantiate a parser $xml = new XML::Simple; open LOG, ">>/home/pbkhk/test/log.txt"; # read the XML file $data = $xml->XMLin("/home/pbkhk/test/timetest.xml"); print LOG "This iteration run at: " . localtime() . "\n" ; 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 LOG "Pairname is: ". $e->{PairName} . "\n "; $IPAddressA = $e->{DeviceA}->{IPAddress} ; #print "IpAddressA is " . $IPAddressA . "\n"; #print "IpAddressB is " . $IPAddressB . "\n"; if ($e->{ExclusionIndicator} ne "y") #Check to see if host should be ignored { #print "SNMP test for DeviceA \n"; ($session,$error) = Net::SNMP->session(Hostname => $IPAddressA, Community => "public"); } $value = $session->get_request($OID); print LOG "request error " . $session->error unless (defined $value); $session->close; $statA = $value->{$OID}; print "value is $value \n" ; print "StatA is $statA \n"; #print "Date and Time for : $e->{PairName} was $statA \n"; #print LOG "Date and Time for : $e->{PairName} was $statA \n"; } close LOG;