1 |
dpavlin |
1.1 |
#!/usr/bin/perl -w |
2 |
dpavlin |
1.2 |
# File: sap.monitor |
3 |
|
|
# Author: Dobrica Pavlinusic, dpavlin@rot13.org |
4 |
|
|
# Description: monitor sap servers using sapinfo from RFCSDK |
5 |
dpavlin |
1.1 |
|
6 |
|
|
use strict; |
7 |
|
|
|
8 |
|
|
my @config; |
9 |
|
|
open(C,"/usr/local/etc/sap-mon.conf") || die "sap-mon.conf: $!"; |
10 |
|
|
@config = <C>; |
11 |
|
|
close(C); |
12 |
|
|
|
13 |
|
|
my @failed; |
14 |
|
|
my @ok; |
15 |
|
|
my $fail_msg = ""; |
16 |
|
|
|
17 |
|
|
# sap info leaves trace files, so create dir without write permission |
18 |
|
|
# and chdir to it! |
19 |
|
|
mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!"; |
20 |
|
|
chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!"; |
21 |
|
|
|
22 |
|
|
foreach (@config) { |
23 |
|
|
chomp; |
24 |
|
|
s/#.+$//g; # nuke comments |
25 |
|
|
s/^\s+$//g; # remove empty lines |
26 |
|
|
my ($ashost,$sysnr) = split(/\t+/,$_,2); |
27 |
|
|
if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "") { |
28 |
|
|
my $output = `/usr/local/bin/sapinfo trace=0 ashost=$ashost sysnr=$sysnr`; |
29 |
|
|
$output =~ m/System ID\s+(\w+)/; |
30 |
|
|
my $sys_id = $1 || ""; |
31 |
|
|
if ($? != 0) { |
32 |
|
|
push @failed, "$ashost ($sysnr)"; |
33 |
|
|
$fail_msg .= $output; |
34 |
|
|
} else { |
35 |
|
|
push @ok, "$ashost ($sys_id)"; |
36 |
|
|
} |
37 |
|
|
} |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
my $exit = 0; |
41 |
|
|
|
42 |
|
|
if (@failed) { |
43 |
|
|
print "FAILED HOSTS: ",join(", ",@failed),"\n\n"; |
44 |
|
|
print "$fail_msg\n"; |
45 |
|
|
$exit = 1; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
print "CHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n"; |
49 |
|
|
|
50 |
|
|
rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!"; |
51 |
|
|
|
52 |
|
|
exit $exit; |