2 |
# File: sap.monitor |
# File: sap.monitor |
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 [-[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; |
13 |
|
|
14 |
|
# change paths here if you want to |
15 |
|
my $CONFIG = "/usr/local/etc/sap-mon.conf"; |
16 |
|
my $SAPINFO = "/usr/local/bin/sapinfo"; |
17 |
|
|
18 |
|
my %opts; |
19 |
|
getopt('h:s:H:S:', \%opts); |
20 |
|
|
21 |
my @config; |
my @config; |
22 |
open(C,"/usr/local/etc/sap-mon.conf") || die "sap-mon.conf: $!"; |
open(C, $CONFIG) || die "sap-mon.conf: $!"; |
23 |
@config = <C>; |
@config = <C>; |
24 |
close(C); |
close(C); |
25 |
|
|
37 |
s/#.+$//g; # nuke comments |
s/#.+$//g; # nuke comments |
38 |
s/^\s+$//g; # remove empty lines |
s/^\s+$//g; # remove empty lines |
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 |
my $output = `/usr/local/bin/sapinfo trace=0 ashost=$ashost sysnr=$sysnr`; |
(($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) && |
42 |
|
(($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`; |
46 |
$output =~ m/System ID\s+(\w+)/; |
$output =~ m/System ID\s+(\w+)/; |
47 |
my $sys_id = $1 || ""; |
my $sys_id = $1 || ""; |
48 |
if ($? != 0) { |
if ($? != 0) { |