script/mpd-check.pl untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 142 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 # read pidlist avery N seconds and (kill -9|STOP) a random pid
4 # usage mpd-kill.pl --time=5 --hostname=node-0.phenyxtest --username=evaleto --loop
5  
6 use Data::Dumper;
7 use Parallel::Mpich::MPD;
8 use File::Temp;
9 use IO::All;
10  
11 use Getopt::Long;
12 my($verbose, $machinesfile, $repair, $mpdhome, $help, $debug, $mailto);
13  
14 if (!GetOptions(
15 "verbose" =>\$verbose,
16 "machinesfile=s" =>\$machinesfile,
17 "repair" =>\$repair,
18 "mailto=s" =>\$mailto,
19 "mpdhome=s" =>\$mpdhome,
20 "help" =>\$help,
21 "debug" =>\$debug,
22 )|defined($help)){
23 printf STDERR "Usage:\n";
24 printf STDERR "$0 --verbose --repair --machinesfile=/path/to/machinesfile --mpdhome=/path/to/mpdhome\n\n";
25 exit 0;
26 }
27  
28 my $mailfile=new File::Temp(UNLINK=>0, TEMPLATE => File::Spec->tmpdir."/mpd-check-XXXX");
29  
30 if (defined $mailto){
31 use Mail::Sendmail;
32 open(STDOUT, "> ".$mailfile->filename) or die "Can't redirect stdout: $!";
33 open(STDERR, ">&STDOUT") or die "Can't dup stdout: $!";
34 }
35  
36  
37  
38 $Parallel::Mpich::MPD::Common::WARN=1;
39 $Parallel::Mpich::MPD::Common::DEBUG=1 if defined $debug;
40  
41 #
42 # Check current user
43 #
44 my $id=`id -u`;
45 chop $id;
46 if ($id == 0){
47 print STDERR "ERROR: You could not run script as user root, exit now!\n";
48 exit 1;
49 }
50  
51  
52 #
53 # Check configuration
54 #
55 print "Checking MPD environnement ...\n";
56 Parallel::Mpich::MPD::Common::env_Hostsfile($machinesfile) if defined $machinesfile;
57 Parallel::Mpich::MPD::Common::env_MpichHome($mpdhome) if defined $mpdhome;
58 Parallel::Mpich::MPD::Common::env_Check();
59 Parallel::Mpich::MPD::Common::env_Print()if defined $debug;
60  
61 #
62 #Print machinesfile
63 #
64  
65 print "machinesfile: ".Parallel::Mpich::MPD::Common::env_Hostsfile()."\n\n";
66 #
67 #Check mpd info
68 #
69 print "1) Checking MPD master informations ...\n";
70 my %info=Parallel::Mpich::MPD::info();
71 my $mpd_is_down;
72 my $machine_is_down;
73 my $mpdnode_is_down;
74 my $sendemail;
75 if ((my $c=%info) eq "0"){
76 print STDERR "ERROR:MPD seems down, could not read master informations\n";
77 $mpd_is_down=1;
78 $sendemail=1;
79 }
80 my %hostsdown;
81 print "2) Checking machines for ping and ssh...\n";
82 Parallel::Mpich::MPD::Common::checkHosts(hostsdown => \%hostsdown );
83  
84 if (($c = %hostsdown) ne "0" ){
85 print STDERR "ERROR: machine(s) doesn't respond, please check why?\n";
86 $machine_is_down=1;
87 $sendemail=1;
88 }
89 $repair=(defined($repair))?" (and try to repair) ":"";
90 print "3) Checking $repair MDP nodes state ...\n\n";
91 my %hostsdown;
92 my %hostsup=Parallel::Mpich::MPD::check(reboot =>(defined $repair)?1:0, hostsdown=>\%hostsdown);
93  
94 if (($c = %hostsdown) eq "0" ){
95 undef $machine_is_down;
96 undef $mpd_is_down;
97 }
98  
99 print "\n";
100 print "REPORT:\n";
101 printf "%-60s %s\n", " - all machines are up (ping/ssh)" , (defined($machine_is_down))?"[no]":"[yes]";
102  
103 printf "%-60s %s\n", " - MDP master is up and working" , (defined($mpd_is_down))?"[no]":"[yes]";
104  
105 printf "%-60s %s\n", " - MPD nodes are up", (($c=%hostsdown) ne "0" || defined($mpd_is_down))?"[no]":"[yes]" ;
106  
107  
108 unless (($c=%hostsdown) eq "0" ){
109 foreach (keys %hostsdown){print "\t$_ is not available\n";};
110 }
111  
112 if (defined ($mailto) && defined($sendemail)){
113 my $mail=IO::All::io($mailfile->filename)->slurp;
114 %send=(To => $mailto, From => $mailto, Subject => "MPD check report", Message => $mail);
115 sendmail(%send) or die $Mail::Sendmail::error;
116 }
117  
118 print "\n";
119  
120  
121