/[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.6 by dpavlin, Wed Jul 17 10:18:14 2002 UTC revision 1.13 by dpavlin, Thu Oct 2 08:18:32 2003 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]  # Usage: sap.monitor [-[hH] ashost only/ignore] [-[sS] sysnr only/ignore]
# Line 8  Line 9 
9  # e.g.  sap.monitor -s 20       will scan only hosts with sysnr == 20  # 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  #       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;  use Getopt::Std;
24    
# Line 16  my $CONFIG = "/usr/local/etc/sap-mon.con Line 27  my $CONFIG = "/usr/local/etc/sap-mon.con
27  my $SAPINFO = "/usr/local/bin/sapinfo";  my $SAPINFO = "/usr/local/bin/sapinfo";
28  # number of tries to repeat sapinfo if it fails first time  # number of tries to repeat sapinfo if it fails first time
29  my $repeat = 3;  my $repeat = 3;
30    # seconds to wait between retries
31    my $repeat_wait = 5;
32    # sapinfo timeout
33    my $sapinfo_timeout = 10;
34    
35  my %opts;  my %opts;
36  getopt('h:s:H:S:', \%opts);  getopt('h:s:H:S:', \%opts);
# Line 38  foreach (@config) { Line 53  foreach (@config) {
53          chomp;          chomp;
54          s/#.+$//g;      # nuke comments          s/#.+$//g;      # nuke comments
55          s/^\s+$//g;     # remove empty lines          s/^\s+$//g;     # remove empty lines
56          my ($ashost,$sysnr) = split(/\t+/,$_,2);          my ($ashost,$sysnr,undef) = split(/\s+/,$_,3);
57          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
58                  (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&                  (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
59                  (($opts{s} && $sysnr  =~ m/$opts{s}/) || not $opts{s}) &&                  (($opts{s} && $sysnr  =~ m/$opts{s}/) || not $opts{s}) &&
# Line 47  foreach (@config) { Line 62  foreach (@config) {
62                  my $ret = 1;                  my $ret = 1;
63                  my $loop = 0;                  my $loop = 0;
64                  my $output;                  my $output;
65                    my $sys_id;
66                  for(my $i=0; $i<$repeat; $i++) {                  for(my $i=0; $i<$repeat; $i++) {
67                          $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;                          eval {
68                          $ret &= $?;                                  local $SIG{ALRM} = sub { die "timeout\n"; };
69                                    alarm $sapinfo_timeout; # wait for sapinfo to finish
70                                    $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
71                            };
72                            alarm 0; # turn alarm off
73                            undef $sys_id;
74                            $output = "" if (! defined $output);
75                            if ($output =~ m/System\s+ID\s+(\w+)/i) {
76                                    $sys_id = $1;
77                                    last;
78                            }
79  #                       print "$loop: $ashost $sysnr $ret\n";  #                       print "$loop: $ashost $sysnr $ret\n";
                         last if ($ret == 0);  
80                          $loop++;                          $loop++;
81                          sleep 5;                          sleep $repeat_wait;
82                  }                  }
83                  $output =~ m/System ID\s+(\w+)/;                  if (! $sys_id) {
                 my $sys_id = $1 || "";  
                 if ($ret != 0) {  
84                          push @failed, "$ashost ($sysnr)";                          push @failed, "$ashost ($sysnr)";
85                          $fail_msg .= $output;                          $fail_msg .= $output;
86                  } else {                  } else {

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.26