--- sap.monitor 2002/07/10 08:31:21 1.2 +++ sap.monitor 2002/07/10 12:10:21 1.3 @@ -2,11 +2,22 @@ # File: sap.monitor # Author: Dobrica Pavlinusic, dpavlin@rot13.org # Description: monitor sap servers using sapinfo from RFCSDK +# +# Usage: sap.monitor [-h ashost filter] [-s sysnr filter] +# use strict; +use Getopt::Std; + +# change paths here if you want to +my $CONFIG = "/usr/local/etc/sap-mon.conf"; +my $SAPINFO = "/usr/local/bin/sapinfo"; + +my %opts; +getopt('h:s:', \%opts); my @config; -open(C,"/usr/local/etc/sap-mon.conf") || die "sap-mon.conf: $!"; +open(C, $CONFIG) || die "sap-mon.conf: $!"; @config = ; close(C); @@ -24,8 +35,10 @@ s/#.+$//g; # nuke comments s/^\s+$//g; # remove empty lines my ($ashost,$sysnr) = split(/\t+/,$_,2); - if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "") { - my $output = `/usr/local/bin/sapinfo trace=0 ashost=$ashost sysnr=$sysnr`; + if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" && + (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) && + (($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) ) { + my $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`; $output =~ m/System ID\s+(\w+)/; my $sys_id = $1 || ""; if ($? != 0) {