/[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.3 - (hide annotations)
Wed Jul 10 12:10:21 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +16 -3 lines
added filtering by host and sysid

1 dpavlin 1.1 #!/usr/bin/perl -w
2 dpavlin 1.2 # File: sap.monitor
3     # Author: Dobrica Pavlinusic, dpavlin@rot13.org
4     # Description: monitor sap servers using sapinfo from RFCSDK
5 dpavlin 1.3 #
6     # Usage: sap.monitor [-h ashost filter] [-s sysnr filter]
7     #
8 dpavlin 1.1
9     use strict;
10 dpavlin 1.3 use Getopt::Std;
11    
12     # change paths here if you want to
13     my $CONFIG = "/usr/local/etc/sap-mon.conf";
14     my $SAPINFO = "/usr/local/bin/sapinfo";
15    
16     my %opts;
17     getopt('h:s:', \%opts);
18 dpavlin 1.1
19     my @config;
20 dpavlin 1.3 open(C, $CONFIG) || die "sap-mon.conf: $!";
21 dpavlin 1.1 @config = <C>;
22     close(C);
23    
24     my @failed;
25     my @ok;
26     my $fail_msg = "";
27    
28     # sap info leaves trace files, so create dir without write permission
29     # and chdir to it!
30     mkdir "/tmp/sap$$",0555 || die "can't make /tmp/sap$$: $!";
31     chdir "/tmp/sap$$" || die "can't chdir in /tmp/sap$$: $!";
32    
33     foreach (@config) {
34     chomp;
35     s/#.+$//g; # nuke comments
36     s/^\s+$//g; # remove empty lines
37     my ($ashost,$sysnr) = split(/\t+/,$_,2);
38 dpavlin 1.3 if ($ashost && $ashost ne "" && $sysnr && $sysnr ne "" &&
39     (($opts{h} && $ashost =~ m/$opts{h}/) || not $opts{h}) &&
40     (($opts{s} && $sysnr =~ m/$opts{s}/) || not $opts{s}) ) {
41     my $output = `$SAPINFO trace=0 ashost=$ashost sysnr=$sysnr`;
42 dpavlin 1.1 $output =~ m/System ID\s+(\w+)/;
43     my $sys_id = $1 || "";
44     if ($? != 0) {
45     push @failed, "$ashost ($sysnr)";
46     $fail_msg .= $output;
47     } else {
48     push @ok, "$ashost ($sys_id)";
49     }
50     }
51     }
52    
53     my $exit = 0;
54    
55     if (@failed) {
56     print "FAILED HOSTS: ",join(", ",@failed),"\n\n";
57     print "$fail_msg\n";
58     $exit = 1;
59     }
60    
61     print "CHECKED HOSTS (which are OK): ",join(", ",@ok),"\n\n";
62    
63     rmdir "/tmp/sap$$" || die "can't rmdir in /tmp/sap$$: $!";
64    
65     exit $exit;

  ViewVC Help
Powered by ViewVC 1.1.26