Hello Perl type people

 i am shore i had this working, but its all gone wrong for some resion the
options do not seem to be getting filled.

 can some one please help

the program is for searching through a large datafile (poller.cfg)
and outputting the found data in a more usefull format.

BTW i am not getting payed to dev this script it just make my job eayeser
and i get to try and lern perl too.
i guess this should all be structured better so if you have any
constructive comments =)

thank you.
RichT


/scanPoller.cfg.pl==================================================
 more scanPoller.cfg.pl
#!/usr/local/bin/perl
#

use strict;
use warnings;
use Getopt::Long;

my
($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);
my ($opt_inFile, $opt_listAllFields, $opt_help ) = (0,0,0);
my $opt_findField = "agentAddress";
my $opt_showFields = "segment,agentAddress,community";

$USAGE = <<USAGETEXT;
usage: $0 ipaddress
          the following options are also availble
          [-inFile filename ] input filename
          [-findField fieldName ] this is the search key (default is
agentAddress)
          [-showFields field names ] feilds to output (default is
segment,agentAddress,community)
          [-listAllFields ] list avalible fields
          [-help] this help text
USAGETEXT

&GetOptions(    "inFile=s",
                "findField=s",
                "showFields=s",
                "listAllFields",
                "help|h|H|?|HELP",
        );

print " listAllFields =$opt_listAllFields\n";  #testing
print " help =$opt_help\n";  #testing


if ($opt_help == 1) {print $USAGE; exit; } # check to see if this is a
request for help, if so print USAGE
# start finding results
if ($opt_inFile != 0){  # find  results if we have in -inFile
        open DFILE, "$opt_inFile"  # open $inFile and read in  or die
                or die " could not open $opt_inFile";
        @dataFile = <DFILE>;
        close DFILE;

        foreach $value (@dataFile) {  # loop  for each line/site in dataFile
                chomp $value ;
                @foundSegments=findVars($opt_findField,$value);
        }
} elsif ($ARGV[0]) { # read in value from comandline

        foreach $value ($ARGV[0]) {  # loop  for each line/site in dataFile
                @foundSegments=findVars($opt_findField,$value);
        }
} else {print $USAGE; exit; }

print " listAllFields =$opt_listAllFields\n";  #testing

# start printing results
if ($opt_listAllFields == 1) {
 for $found ( @foundSegments ) {
        print "\n" ;
        for $foundKeys (keys %$found) {
                print "$foundKeys,";
        }
 }
} else {

 for $found ( @foundSegments ) {
        foreach $showKey (split /,/, $opt_showFields) {
                print "$found->{$showKey},";
        }
        print "\n";
 }
}

sub findVars {
############################################################
# Function Check Discover Results
# Parameters :
#
# Returns :
#
#
############################################################


my($findKey, $findValue, $segmentFieldKey, $segmentFieldValue,
%segmentFields, $nullVar, @foundSegments);

# read in Search Key and Value  from parent NOTE make a check for this
$findKey=$_[0] || die "Missing Args $findKey $!" ;
$findValue=$_[1] || die "Missing Args $findValue $!" ;
chomp $findValue;
chomp $findKey;
#my $NH_HOME= $ENV[NH_HOME];  # point to the poller CFG file
my $NH_HOME= ".";  # point to the poller CFG file NOTE this is temp for
testing use above line in live


local $/ = "}\n";                       # set delimiter


open(POLLER, "$NH_HOME/poller.cfg") || die "can not open : $!";

#s/universalPollList \{//g;

while(<POLLER>) {
        next unless /^\s+segment/;
        s/\n\s+\}\n//g;
        s/["{]//g;
        foreach (split(/\n/)) {
                ($nullVar,$segmentFieldKey,$segmentFieldValue) =
split(/\s+/,$_,3);
                $segmentFields{ $segmentFieldKey } = $segmentFieldValue ;
        }
        if ( $segmentFields{$findKey} eq $findValue ) {

                push @foundSegments, {%segmentFields } ;
        }
        undef %segmentFields;
        my %segmentFields;
}
close POLLER;

return (@foundSegments);      # return the IP and comunity string to main
ruteen
};

/scanPoller.cfg.pl==================================================


exampleExtract form poller.cfg==================================

   segment "customer-site-Bend" {
       agentAddress     "x.x.x.x"
       uniqueDeviceId   "dfofdkskhjkldsf"
       mibTranslationFile "cisco-frameRelay-cir.mtf"
       index            "2"
       index2           "400"
       deviceSpeed      "64000.0"
       deviceSpeed2     "64000.0"
       discoverMtf      "cisco-frameRelay-cir.mtf"
       index3           "7"
       community        "public"
       sysDescr         "Cisco Internetwork Operating System Software
IOS (tm) C1700 Software (C1700-Y-M), Version 12.1 blar blar..."
       sysName          "routerName"
       sysLoc           "siteLocation"
       ifDescr          "Serial0"
       ifType           "frame-relay"
       aliasName        "PVCreffNumber"
       nmsKey           "routerName Serial0 400"
       enterpriseId     "9"
       possibleLatencySources "concord, ciscoPing"
       fullDuplex       "1"
       mediaSpeed       "64000.0"
       mediaSpeed1      "64000.0"
       statistics       "1"
   }

/exampleExtract form poller.cfg==================================

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to