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

Diff of /sap.monitor

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by dpavlin, Wed Jul 10 08:31:21 2002 UTC revision 1.11 by dpavlin, Mon Oct 28 08:36:48 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  # File:         sap.monitor  # File:         sap.monitor
3  # Author:       Dobrica Pavlinusic, dpavlin@rot13.org  # Author:       Dobrica Pavlinusic, dpavlin@rot13.org
4    #               http://www.rot13.org/~dpavlin/sysadm.html
5  # Description:  monitor sap servers using sapinfo from RFCSDK  # 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;  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    # seconds to wait between retries
31    my $repeat_wait = 5;
32    
33    my %opts;
34    getopt('h:s:H:S:', \%opts);
35    
36  my @config;  my @config;
37  open(C,"/usr/local/etc/sap-mon.conf") || die "sap-mon.conf: $!";  open(C, $CONFIG) || die "sap-mon.conf: $!";
38  @config = <C>;  @config = <C>;
39  close(C);  close(C);
40    
# Line 23  foreach (@config) { Line 51  foreach (@config) {
51          chomp;          chomp;
52          s/#.+$//g;      # nuke comments          s/#.+$//g;      # nuke comments
53          s/^\s+$//g;     # remove empty lines          s/^\s+$//g;     # remove empty lines
54          my ($ashost,$sysnr) = split(/\t+/,$_,2);          my ($ashost,$sysnr,undef) = split(/\s+/,$_,3);
55          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "") {          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
56                  my $output = `/usr/local/bin/sapinfo trace=0 ashost=$ashost sysnr=$sysnr`;                  (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
57                  $output =~ m/System ID\s+(\w+)/;                  (($opts{s} && $sysnr  =~ m/$opts{s}/) || not $opts{s}) &&
58                  my $sys_id = $1 || "";                  (($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) &&
59                  if ($? != 0) {                  (($opts{S} && $sysnr  !~ m/$opts{S}/) || not $opts{S}) ) {
60                    my $ret = 1;
61                    my $loop = 0;
62                    my $output;
63                    my $sys_id;
64                    for(my $i=0; $i<$repeat; $i++) {
65                            eval {
66                                    local $SIG{ALRM} = sub { die "timeout\n"; };
67                                    alarm 30; # wait for sapinfo to finish
68                                    $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
69                            };
70                            alarm 0; # turn alarm off
71                            undef $sys_id;
72                            if ($output =~ m/System\s+ID\s+(\w+)/i) {
73                                    $sys_id = $1;
74                                    last;
75                            }
76    #                       print "$loop: $ashost $sysnr $ret\n";
77                            $loop++;
78                            sleep $repeat_wait;
79                    }
80                    if (! $sys_id) {
81                          push @failed, "$ashost ($sysnr)";                          push @failed, "$ashost ($sysnr)";
82                          $fail_msg .= $output;                          $fail_msg .= $output;
83                  } else {                  } else {
# Line 40  foreach (@config) { Line 89  foreach (@config) {
89  my $exit = 0;  my $exit = 0;
90    
91  if (@failed) {  if (@failed) {
92          print "FAILED HOSTS: ",join(", ",@failed),"\n\n";          print join(", ",@failed)," FAILED\n\n";
93          print "$fail_msg\n";          print "$fail_msg\n";
94          $exit = 1;          $exit = 1;
95  }  }
96    
97  print "CHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";  print "ALL OK\nCHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
98    
99  rmdir "/tmp/sap$$"              || die "can't rmdir in /tmp/sap$$: $!";  rmdir "/tmp/sap$$"              || die "can't rmdir in /tmp/sap$$: $!";
100    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.26