Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
title2statusparsePL.rtf
collapsetrue
#!/usr/bin/perl
use vars;
$file = "/home/gds/navcsStatus";
if (!open (FILE, $file)) {
        print "ERROR: Status file not found : $file";
        exit(0);
    }
#$new_file = "./vcsstatus.php";
#if (-e $new_file) {
#       unlink($new_file);
#}
$stat_line = '';
$Name = '';
$Value = '';
$val_name = '';
$val_status = '';
$val_zone_num = '';
while(<FILE>) {
        my($line) = $_;
        chomp($line);          # Get rid of the traillingtrailing \n
        $line =~ s/^\s*//;     # Remove spaces at the start of the line
        $line =~ s/\s*$//;     # Remove spaces at the end of the line
        if ( ($line !~ /^#/) && ($line ne "") ){    # Ignore lines starting with # and blank lines
                ($Name, $Value) = split (/:/, $line);          # Split each line into name value pairs
                if( ($Name eq "Name") or ($Name eq "Status") or ($Name =~ m/^Zone*/)){          # Checks to see if $Name is Name or Status
                        $Value =~ s/^\s*//; # Removes spaces from the start of the value
                        $Value =~ s/\s*$//; # Removes spaces from the end of the value
                        if($Name =~ m/^Zone\s*/){ # Searches for the line that starts with "Zone X"
                                my($z_zone, $z_number); # Defines local variables for parsing and seperatingseparating Zone and X
                                $Name =~ s/^\s*//; # Removes extra space from beginning
                                $Name =~ s/\s*$//; # Removes extra space from the end
                                $Name =~ s/[:]*$//; # Removes the : fronfrom the end of "Zone X:"
                                ($z_zone, $z_number) = split (/\s/,$Name); # Splits "Zone X" into "Zone" and "X"
                                $val_zone_num = $z_number; # Assigns "X" to variable $val_zone_num
                        }
                        if($Name eq "Name"){ #Checks for what the name of the line is, if it is "Name", it continutescontinues
                                $Value =~ s/^["]*//; # Removes quotes from beginning of Name
                                $Value =~ s/["]*$//; # Removes quotes from end of Name
                                $val_name = $Value;  # Assigned the name of the zone to $val_name
                        }
                        if($Name eq "Status"){ #Checks for what the name of the line is.  It is "Status", it contintuescontinues
                                $val_status = $Value; #Assigned the value of "Status" otof $val_status
                        }
                        if( ($val_name ne '') && ($val_status ne '') ){ #Since it cycles through the lines a few times before it gets to the next variable, it checks to see if both Name and Status have values applies (IE not empty), If both values have values assigned, it continues in.  If not, it goes to the next line retraining any value that has been assiendassigned to either $val_name or $val_status.
                                $stat_line .= "$val_zone_num:$val_name:$val_status\r\n"; # write the line giving the name and status of the zone.  Output will look like: XXX: Zone_name: Status.  IE:  1: Some_Zone: Active
                                $val_name = ''; # Clears out the variblevariable for next loop through.
                                $val_status = ''; # Clears out the variable for the next loop through
                        }
                }
        }
        if($line eq "*s/end"){
                last;
        }
    }
        close FILE; # Closes the input file it read from.
        open FILE2, ">/home/gds/vcs_scripts/vcsstatus.cfg" or die $!; #Opens the file 'vcsstatus.php' for writing to.
        print FILE2 $stat_line; # writes the value of $stat_line to the file
        close FILE2; # Closes the file.

...

Code Block
title3check_neighbor_status-PLUGIN.rtf
collapsetrue
#!/usr/bin/perl
use vars;
$file = "/home/gds/vcs_scripts/vcsstatus.cfg";
if (!open (FILE, $file)) {
        print "ERROR: Status file not found : $file\r\n";
        exit(0);
    }
#$new_file = "./vcsstatus.php";
#if (-e $new_file) {
#       unlink($new_file);
#}
$val_name = '';
$val_status = '';
$val_zone_num = '';
$ex_status = '';
$ne_id = $ARGV[0];
while(<FILE>) {
        my($line) = $_;
        chomp($line);          # Get rid of the traillingtrailing \n
        $line =~ s/^\s*//;     # Remove spaces at the start of the line
        $line =~ s/\s*$//;     # Remove spaces at the end of the line
        if($line =~ m/^($ne_id)/){
                ($val_zone_num, $val_name, $val_status) = split (/:/, $line);          # Split each line into name value pairs
                if( $val_zone_num = $ne_id ){
                        if( $val_status eq "Active"){
                                print "OK\n";
                                $ex_status = 0;
                                last;
                        }
                        elsif( $val_status eq "Warning"){
                                print "Warning!\n";
                                $ex_status = 1;
                                last;
                        }
                        elsif( $val_status eq "Failed"){
                                print "Critical!\n";
                                $ex_status = 2;
                                last;
                        }
                }
        }
        }
close FILE;
exit $ex_status;

...

Comments and feedback to the above can be sent to NickNicholas Thompson nick (at) internet2.edu