/[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

Annotation of /sap.monitor

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Thu Oct 2 08:18:32 2003 UTC (15 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +3 -1 lines
added configurable timeout for sapinfo

1 dpavlin 1.1 #!/usr/bin/perl -w
2 dpavlin 1.2 # File: sap.monitor
3     # Author: Dobrica Pavlinusic, dpavlin@rot13.org
4 dpavlin 1.9 # http://www.rot13.org/~dpavlin/sysadm.html
5 dpavlin 1.2 # Description: monitor sap servers using sapinfo from RFCSDK
6 dpavlin 1.3 #
7 dpavlin 1.4 # Usage: sap.monitor [-[hH] ashost only/ignore] [-[sS] sysnr only/ignore]
8 dpavlin 1.3 #
9 dpavlin 1.4 # 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 dpavlin 1.1
12 dpavlin 1.8 # 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 dpavlin 1.1 use strict;
23 dpavlin 1.3 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 dpavlin 1.6 # number of tries to repeat sapinfo if it fails first time
29     my $repeat = 3;
30 dpavlin 1.10 # seconds to wait between retries
31     my $repeat_wait = 5;
32 dpavlin 1.13 # sapinfo timeout
33     my $sapinfo_timeout = 10;
34 dpavlin 1.3
35     my %opts;
36 dpavlin 1.5 getopt('h:s:H:S:', \%opts);
37 dpavlin 1.1
38     my @config;
39 dpavlin 1.3 open(C, $CONFIG) || die "sap-mon.conf: $!";
40 dpavlin 1.1 @config = <C>;
41     close(C);
42    
43     my @failed;
44     my @ok;
45     my $fail_msg = "";
46    
47     # sap info leaves trace files, so create dir without write permission
48     # and chdir to it!
49     mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!";
50     chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!";
51    
52     foreach (@config) {
53     chomp;
54     s/#.+$//g; # nuke comments
55     s/^\s+$//g; # remove empty lines
56 dpavlin 1.7 my ($ashost,$sysnr,undef) = split(/\s+/,$_,3);
57 dpavlin 1.3 if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
58     (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
59 dpavlin 1.4 (($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) &&
60     (($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) &&
61     (($opts{S} && $sysnr !~ m/$opts{S}/) || not $opts{S}) ) {
62 dpavlin 1.6 my $ret = 1;
63     my $loop = 0;
64     my $output;
65 dpavlin 1.7 my $sys_id;
66 dpavlin 1.6 for(my $i=0; $i<$repeat; $i++) {
67 dpavlin 1.11 eval {
68     local $SIG{ALRM} = sub { die "timeout\n"; };
69 dpavlin 1.13 alarm $sapinfo_timeout; # wait for sapinfo to finish
70 dpavlin 1.11 $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
71     };
72     alarm 0; # turn alarm off
73 dpavlin 1.7 undef $sys_id;
74 dpavlin 1.12 $output = "" if (! defined $output);
75 dpavlin 1.7 if ($output =~ m/System\s+ID\s+(\w+)/i) {
76     $sys_id = $1;
77     last;
78     }
79 dpavlin 1.6 # print "$loop: $ashost $sysnr $ret\n";
80     $loop++;
81 dpavlin 1.10 sleep $repeat_wait;
82 dpavlin 1.6 }
83 dpavlin 1.7 if (! $sys_id) {
84 dpavlin 1.1 push @failed, "$ashost ($sysnr)";
85     $fail_msg .= $output;
86     } else {
87     push @ok, "$ashost ($sys_id)";
88     }
89     }
90     }
91    
92     my $exit = 0;
93    
94     if (@failed) {
95 dpavlin 1.6 print join(", ",@failed)," FAILED\n\n";
96 dpavlin 1.1 print "$fail_msg\n";
97     $exit = 1;
98     }
99    
100 dpavlin 1.6 print "ALL OK\nCHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
101 dpavlin 1.1
102     rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!";
103    
104     exit $exit;

  ViewVC Help
Powered by ViewVC 1.1.26