/[mon-modules]/sap.monitor
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sap.monitor

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Wed Jul 10 12:36:57 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +1 -1 lines
added missing options

1 #!/usr/bin/perl -w
2 # File: sap.monitor
3 # Author: Dobrica Pavlinusic, dpavlin@rot13.org
4 # 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;
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;
22 open(C, $CONFIG) || die "sap-mon.conf: $!";
23 @config = <C>;
24 close(C);
25
26 my @failed;
27 my @ok;
28 my $fail_msg = "";
29
30 # sap info leaves trace files, so create dir without write permission
31 # and chdir to it!
32 mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!";
33 chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!";
34
35 foreach (@config) {
36 chomp;
37 s/#.+$//g; # nuke comments
38 s/^\s+$//g; # remove empty lines
39 my ($ashost,$sysnr) = split(/\t+/,$_,2);
40 if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
41 (($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+)/;
47 my $sys_id = $1 || "";
48 if ($? != 0) {
49 push @failed, "$ashost ($sysnr)";
50 $fail_msg .= $output;
51 } else {
52 push @ok, "$ashost ($sys_id)";
53 }
54 }
55 }
56
57 my $exit = 0;
58
59 if (@failed) {
60 print "FAILED HOSTS: ",join(", ",@failed),"\n\n";
61 print "$fail_msg\n";
62 $exit = 1;
63 }
64
65 print "CHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
66
67 rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!";
68
69 exit $exit;

  ViewVC Help
Powered by ViewVC 1.1.26