/[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.3 by dpavlin, Wed Jul 10 12:10:21 2002 UTC revision 1.7 by dpavlin, Mon Jul 22 12:26:06 2002 UTC
# Line 3  Line 3 
3  # Author:       Dobrica Pavlinusic, dpavlin@rot13.org  # Author:       Dobrica Pavlinusic, dpavlin@rot13.org
4  # Description:  monitor sap servers using sapinfo from RFCSDK  # Description:  monitor sap servers using sapinfo from RFCSDK
5  #  #
6  # Usage: sap.monitor [-h ashost filter] [-s sysnr filter]  # 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;  use strict;
12  use Getopt::Std;  use Getopt::Std;
# Line 12  use Getopt::Std; Line 14  use Getopt::Std;
14  # change paths here if you want to  # change paths here if you want to
15  my $CONFIG = "/usr/local/etc/sap-mon.conf";  my $CONFIG = "/usr/local/etc/sap-mon.conf";
16  my $SAPINFO = "/usr/local/bin/sapinfo";  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;  my %opts;
21  getopt('h:s:', \%opts);  getopt('h:s:H:S:', \%opts);
22    
23  my @config;  my @config;
24  open(C, $CONFIG) || die "sap-mon.conf: $!";  open(C, $CONFIG) || die "sap-mon.conf: $!";
# Line 34  foreach (@config) { Line 38  foreach (@config) {
38          chomp;          chomp;
39          s/#.+$//g;      # nuke comments          s/#.+$//g;      # nuke comments
40          s/^\s+$//g;     # remove empty lines          s/^\s+$//g;     # remove empty lines
41          my ($ashost,$sysnr) = split(/\t+/,$_,2);          my ($ashost,$sysnr,undef) = split(/\s+/,$_,3);
42          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&          if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
43                  (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&                  (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
44                  (($opts{s} && $sysnr  =~ m/$opts{s}/) || not $opts{s}) ) {                  (($opts{s} && $sysnr  =~ m/$opts{s}/) || not $opts{s}) &&
45                  my $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;                  (($opts{H} && $ashost !~ m/$opts{H}/) || not $opts{H}) &&
46                  $output =~ m/System ID\s+(\w+)/;                  (($opts{S} && $sysnr  !~ m/$opts{S}/) || not $opts{S}) ) {
47                  my $sys_id = $1 || "";                  my $ret = 1;
48                  if ($? != 0) {                  my $loop = 0;
49                    my $output;
50                    my $sys_id;
51                    for(my $i=0; $i<$repeat; $i++) {
52                            $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
53                            undef $sys_id;
54                            if ($output =~ m/System\s+ID\s+(\w+)/i) {
55                                    $sys_id = $1;
56                                    last;
57                            }
58    #                       print "$loop: $ashost $sysnr $ret\n";
59                            $loop++;
60                            sleep 5;
61                    }
62                    if (! $sys_id) {
63                          push @failed, "$ashost ($sysnr)";                          push @failed, "$ashost ($sysnr)";
64                          $fail_msg .= $output;                          $fail_msg .= $output;
65                  } else {                  } else {
# Line 53  foreach (@config) { Line 71  foreach (@config) {
71  my $exit = 0;  my $exit = 0;
72    
73  if (@failed) {  if (@failed) {
74          print "FAILED HOSTS: ",join(", ",@failed),"\n\n";          print join(", ",@failed)," FAILED\n\n";
75          print "$fail_msg\n";          print "$fail_msg\n";
76          $exit = 1;          $exit = 1;
77  }  }
78    
79  print "CHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";  print "ALL OK\nCHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
80    
81  rmdir "/tmp/sap$$"              || die "can't rmdir in /tmp/sap$$: $!";  rmdir "/tmp/sap$$"              || die "can't rmdir in /tmp/sap$$: $!";
82    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26