/[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.6 - (show annotations)
Wed Jul 17 10:18:14 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +16 -4 lines
selectable number of retries if fist one fails (default: 3)

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 # number of tries to repeat sapinfo if it fails first time
18 my $repeat = 3;
19
20 my %opts;
21 getopt('h:s:H:S:', \%opts);
22
23 my @config;
24 open(C, $CONFIG) || die "sap-mon.conf: $!";
25 @config = <C>;
26 close(C);
27
28 my @failed;
29 my @ok;
30 my $fail_msg = "";
31
32 # sap info leaves trace files, so create dir without write permission
33 # and chdir to it!
34 mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!";
35 chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!";
36
37 foreach (@config) {
38 chomp;
39 s/#.+$//g; # nuke comments
40 s/^\s+$//g; # remove empty lines
41 my ($ashost,$sysnr) = split(/\t+/,$_,2);
42 if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
43 (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
44 (($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) &&
45 (($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) &&
46 (($opts{S} && $sysnr !~ m/$opts{S}/) || not $opts{S}) ) {
47 my $ret = 1;
48 my $loop = 0;
49 my $output;
50 for(my $i=0; $i<$repeat; $i++) {
51 $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
52 $ret &= $?;
53 # print "$loop: $ashost $sysnr $ret\n";
54 last if ($ret == 0);
55 $loop++;
56 sleep 5;
57 }
58 $output =~ m/System ID\s+(\w+)/;
59 my $sys_id = $1 || "";
60 if ($ret != 0) {
61 push @failed, "$ashost ($sysnr)";
62 $fail_msg .= $output;
63 } else {
64 push @ok, "$ashost ($sys_id)";
65 }
66 }
67 }
68
69 my $exit = 0;
70
71 if (@failed) {
72 print join(", ",@failed)," FAILED\n\n";
73 print "$fail_msg\n";
74 $exit = 1;
75 }
76
77 print "ALL OK\nCHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
78
79 rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!";
80
81 exit $exit;

  ViewVC Help
Powered by ViewVC 1.1.26