/[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.9 - (show annotations)
Fri Jul 26 10:43:47 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.8: +1 -0 lines
better instructions

1 #!/usr/bin/perl -w
2 # File: sap.monitor
3 # Author: Dobrica Pavlinusic, dpavlin@rot13.org
4 # http://www.rot13.org/~dpavlin/sysadm.html
5 # Description: monitor sap servers using sapinfo from RFCSDK
6 #
7 # Usage: sap.monitor [-[hH] ashost only/ignore] [-[sS] sysnr only/ignore]
8 #
9 # e.g. sap.monitor -s 20 will scan only hosts with sysnr == 20
10 # sap.monitor -S 20 will scan only hosts with sysnr != 20
11
12 # configuration file in /usr/local/etc/sap-mon.conf describes which
13 # hosts (ashost) and systems (sysnr) you want to check.
14 #
15 # format of line is:
16 #
17 # ashost [tab|space] sysnr # optional comment
18 #
19 # you can spacify host as hostname (sap01) or with sap routers in-between
20 # to test routers too (/H/saprtr/H/sap01)
21
22 use strict;
23 use Getopt::Std;
24
25 # change paths here if you want to
26 my $CONFIG = "/usr/local/etc/sap-mon.conf";
27 my $SAPINFO = "/usr/local/bin/sapinfo";
28 # number of tries to repeat sapinfo if it fails first time
29 my $repeat = 3;
30
31 my %opts;
32 getopt('h:s:H:S:', \%opts);
33
34 my @config;
35 open(C, $CONFIG) || die "sap-mon.conf: $!";
36 @config = <C>;
37 close(C);
38
39 my @failed;
40 my @ok;
41 my $fail_msg = "";
42
43 # sap info leaves trace files, so create dir without write permission
44 # and chdir to it!
45 mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!";
46 chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!";
47
48 foreach (@config) {
49 chomp;
50 s/#.+$//g; # nuke comments
51 s/^\s+$//g; # remove empty lines
52 my ($ashost,$sysnr,undef) = split(/\s+/,$_,3);
53 if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
54 (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
55 (($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) &&
56 (($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) &&
57 (($opts{S} && $sysnr !~ m/$opts{S}/) || not $opts{S}) ) {
58 my $ret = 1;
59 my $loop = 0;
60 my $output;
61 my $sys_id;
62 for(my $i=0; $i<$repeat; $i++) {
63 $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
64 undef $sys_id;
65 if ($output =~ m/System\s+ID\s+(\w+)/i) {
66 $sys_id = $1;
67 last;
68 }
69 # print "$loop: $ashost $sysnr $ret\n";
70 $loop++;
71 sleep 5;
72 }
73 if (! $sys_id) {
74 push @failed, "$ashost ($sysnr)";
75 $fail_msg .= $output;
76 } else {
77 push @ok, "$ashost ($sys_id)";
78 }
79 }
80 }
81
82 my $exit = 0;
83
84 if (@failed) {
85 print join(", ",@failed)," FAILED\n\n";
86 print "$fail_msg\n";
87 $exit = 1;
88 }
89
90 print "ALL OK\nCHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
91
92 rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!";
93
94 exit $exit;

  ViewVC Help
Powered by ViewVC 1.1.26