All pastes #229479 Raw Edit

Someone

public text v1 · immutable
#229479 ·published 2006-10-30 18:55 UTC
rendered paste body
netscaler_get_vips.pl

#!/usr/bin/perl
#*****************************************
# Script to dynamically find all the VIPS
# on the netscaler via SNMP
#
# Steve Finkelstein
# sfinkelstein@communityconnect.com
# Community Connect, Inc.
#*****************************************

use warnings;
use strict;
use Data::Dumper;
use Getopt::Long;

#****************************************
# MAIN
#****************************************

my $vservername_oid = 'enterprises.5951.4.1.3.1.1.1';
my $vserverclient_oid = 'enterprises.5951.4.1.3.2.1.8';

my $community = 'cci-ro';
my $netscaler_ip = '10.50.0.1';
use vars qw($oid $vserver $verbose @clients);
my %vips;

my ($show) = '';
my @match = ();

GetOptions(
                'm=s'           => \@match,
                'match=s'       => \@match,
                "s"             => \$show,
                "show-all"      => \$show,
          );

my $usage_error = undef;

unless ( (@match) || ($show) ) {
    $usage_error .= "You must specify show-all or match!\n";
}

if ($usage_error) {
    print "$usage_error\n";
    die "Usage: $0 -m [client1[,client2,client3]] -s.\nLong options available:\n -m --match, -s --show-all\n";
}

if ($show) { populate_vservers(1); }

if (@match) {
     @match = split(/,/,join(',',@match));
     populate_vservers();
     for my $match (@match) {
        next if $match =~ /^$/;
        push(@clients,map  { $vips{$_}{name} }
                      grep { join( "\x00",@{ $vips{$_}{clients} } ) =~ /\Q$match/i }
                      keys %vips);
     }
    for (@clients) {
        print "The node @{match} is currently part of the following Virtual Server: @clients\n";
        #print "$_\n";
    }
}

#****************************************
# Get all of the vserver names and their
# respective services. Populate data
# into %vips
#****************************************
sub populate_vservers {
    $verbose = @_;
    my @vserverNames = `/usr/bin/snmpwalk -c $community -v 1 $netscaler_ip $vservername_oid`;
    for my $output_line ( @vserverNames ) {
        ($oid,$vserver) = ($output_line =~ /(enterprises[\.\d]+)\s+=\s+STRING:\s(.*)/);
        $vserver =~ s/\"//g;
        $oid =~ s/$vservername_oid//;
        $vips{$oid} = { name => $vserver, clients => [ `/usr/bin/snmpwalk -c $community -v 1 $netscaler_ip ${vserverclient_oid}${oid}` ] };
    }

    for my $oid ( sort sort_vip(keys %vips) ) {
        if ($verbose) {
        #    print "vserver: " . $vips{$oid}{name} . "\n"; 
             print "\n$vips{$oid}{name}: ";        }
        for my $i ( 0 .. $#{$vips{$oid}{clients}} ) {
            @{$vips{$oid}{clients}}[$i] =~ s/SNMPv2-SMI::enterprises[\.\d]+\s+=\s+STRING:\s(.*)/$1/g;
            @{$vips{$oid}{clients}}[$i] =~ s/\"//g;
            @{$vips{$oid}{clients}}[$i] =~ s/\s+$//g;
            if ($verbose) {
                #print "client " . ($i+1) . ": @{$vips{$oid}{clients}}[$i]"; 
                print "@{$vips{$oid}{clients}}[$i] ";
            }
        }
  }
}


#****************************************
# Sort VIPS 
#****************************************
sub sort_vip {
    $vips{$a} cmp $vips{$b};
}


---------- phplogsplit.pl --------------

#!/usr/bin/perl
###############################################################################
# DESCRIPTION
# This script will parse /var/log/batch/php.log using logtail and simply split
# the log into a BP, AA and MG logs for sanity purposes. 
# 
# OPERATION
# The script runs from a global crontab every minute. 
#
# AUTHOR
# Steve Finkelstein <sfinkelstein@communityconnect.com>
###############################################################################

use warnings;
use strict;
use FileHandle;
use vars qw($node @vserver_output);


#############################################
# define miscellaneous variables
my $logtail = '/usr/local/bin/logtail';
my $logfile = '/var/log/batch/php.log';
my $bplog = '/var/log/batch/php-bp.log';
my $aalog = '/var/log/batch/php-aa.log';
my $mglog = '/var/log/batch/php-mg.log';
my $gllog = '/var/log/batch/php-gl.log';
#############################################


##############################################
# Open filehandles to log destinations
##############################################
my $log = new FileHandle "$logtail $logfile |";
my $bpfh = new FileHandle ">> $bplog";
my $aafh = new FileHandle ">> $aalog";
my $mgfh = new FileHandle ">> $mglog";
my $glfh = new FileHandle ">> $gllog";

# call netscaler_get_vips.pl to populate all vservers and their nodes
@vserver_output = `perl /usr/local/bin/netscaler_get_vips.pl --show-all`;

if (defined($log) ) {
    while(<$log>) {
        chomp;
        $node = (split / /, $_)[3];
        for my $vserver (@vserver_output) {
            if ($vserver =~ /$node/i) {
                print $bpfh "$_\n" if $vserver =~ /bp/i;
                print $mgfh "$_\n" if $vserver =~ /mg/i;
                print $aafh "$_\n" if $vserver =~ /aa/i;
                print $glfh "$_\n" if $vserver =~ /gl/i;
            }
        }
    }
}

$bpfh->close();
$aafh->close();
$mgfh->close();
$glfh->close();
$log->close();

__END__
"netscaler_get_vips.pl" 104L, 3113C                                                        1,1           Top