3 |
# Author: Dobrica Pavlinusic, dpavlin@rot13.org |
# Author: Dobrica Pavlinusic, dpavlin@rot13.org |
4 |
# Description: monitor sap servers using sapinfo from RFCSDK |
# Description: monitor sap servers using sapinfo from RFCSDK |
5 |
# |
# |
6 |
# Usage: sap.monitor [-h ashost filter] [-s sysnr filter] |
# Usage: sap.monitor [-[hH] ashost only/ignore] [-[sS] sysnr only/ignore] |
7 |
# |
# |
8 |
|
# e.g. sap.monitor -s 20 will scan only hosts with sysnr == 20 |
9 |
|
# sap.monitor -S 20 will scan only hosts with sysnr != 20 |
10 |
|
|
11 |
use strict; |
use strict; |
12 |
use Getopt::Std; |
use Getopt::Std; |
16 |
my $SAPINFO = "/usr/local/bin/sapinfo"; |
my $SAPINFO = "/usr/local/bin/sapinfo"; |
17 |
|
|
18 |
my %opts; |
my %opts; |
19 |
getopt('h:s:', \%opts); |
getopt('h:s:H:S:', \%opts); |
20 |
|
|
21 |
my @config; |
my @config; |
22 |
open(C, $CONFIG) || die "sap-mon.conf: $!"; |
open(C, $CONFIG) || die "sap-mon.conf: $!"; |
39 |
my ($ashost,$sysnr) = split(/\t+/,$_,2); |
my ($ashost,$sysnr) = split(/\t+/,$_,2); |
40 |
if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" && |
if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" && |
41 |
(($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) && |
(($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) && |
42 |
(($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) ) { |
(($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) && |
43 |
|
(($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) && |
44 |
|
(($opts{S} && $sysnr !~ m/$opts{S}/) || not $opts{S}) ) { |
45 |
my $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`; |
my $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`; |
46 |
$output =~ m/System ID\s+(\w+)/; |
$output =~ m/System ID\s+(\w+)/; |
47 |
my $sys_id = $1 || ""; |
my $sys_id = $1 || ""; |